Skip to content

Commit

Permalink
Show diffs for unmerged files
Browse files Browse the repository at this point in the history
Also handle case where diff lines is empty
  • Loading branch information
rgburke committed Jan 7, 2019
1 parent f9c8df8 commit 66302c5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 14 deletions.
4 changes: 4 additions & 0 deletions cmd/grv/diff_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,10 @@ func selectDiffLine(diffView *DiffView, action Action) (err error) {
}

lineIndex := diffView.activeViewPos.ActiveRowIndex()
if lineIndex >= diffView.rows() {
return
}

diffLine := diffLines.lines[lineIndex]

if diffLine.lineType != dltDiffStatsFile {
Expand Down
56 changes: 42 additions & 14 deletions cmd/grv/repo_data_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -1177,12 +1177,16 @@ func (repoDataLoader *RepoDataLoader) DiffStage(statusType StatusType) (diff *Di
diff = &Diff{}

rawDiff, err := repoDataLoader.generateRawDiff(statusType)
if err != nil {
if diffErrorRegex.MatchString(err.Error()) {
log.Infof("Falling back to git cli after encountering error: %v", err)
repoDataLoader.diffErrorPresent = true
return repoDataLoader.generateStageDiffUsingCLI(statusType)
}

if err != nil && diffErrorRegex.MatchString(err.Error()) {
log.Infof("Falling back to git cli after encountering error: %v", err)
repoDataLoader.diffErrorPresent = true
return repoDataLoader.generateStageDiffUsingCLI(statusType)
} else if err != nil || rawDiff == nil {
return
} else if rawDiff == nil {
err = fmt.Errorf("Failed to generate diff for %v files", StatusTypeDisplayName(statusType))
return
}
defer rawDiff.Free()
Expand All @@ -1201,11 +1205,16 @@ func (repoDataLoader *RepoDataLoader) DiffFile(statusType StatusType, path strin
diff = &Diff{}

rawDiff, err := repoDataLoader.generateRawDiff(statusType)
if err != nil && diffErrorRegex.MatchString(err.Error()) {
log.Infof("Falling back to git cli after encountering error: %v", err)
repoDataLoader.diffErrorPresent = true
return repoDataLoader.generateFileDiffUsingCLI(statusType, path)
} else if err != nil || rawDiff == nil {
if err != nil {
if diffErrorRegex.MatchString(err.Error()) {
log.Infof("Falling back to git cli after encountering error: %v", err)
repoDataLoader.diffErrorPresent = true
return repoDataLoader.generateFileDiffUsingCLI(statusType, path)
}

return
} else if rawDiff == nil {
err = fmt.Errorf("Failed to generate diff for %v file %v", StatusTypeDisplayName(statusType), path)
return
}
defer rawDiff.Free()
Expand Down Expand Up @@ -1249,13 +1258,12 @@ func (repoDataLoader *RepoDataLoader) DiffFile(statusType StatusType, path strin
func (repoDataLoader *RepoDataLoader) generateRawDiff(statusType StatusType) (rawDiff *git.Diff, err error) {
var index *git.Index
var options git.DiffOptions
var head Ref
var commit *Commit
var tree *git.Tree

switch statusType {
case StStaged:
var head Ref
var commit *Commit
var tree *git.Tree

if head, err = repoDataLoader.Head(); err != nil {
return
}
Expand Down Expand Up @@ -1291,6 +1299,26 @@ func (repoDataLoader *RepoDataLoader) generateRawDiff(statusType StatusType) (ra
if rawDiff, err = repoDataLoader.repo.DiffIndexToWorkdir(index, &options); err != nil {
return
}
case StConflicted:
if head, err = repoDataLoader.Head(); err != nil {
return
}

if commit, err = repoDataLoader.Commit(head.Oid()); err != nil {
return
}

if tree, err = commit.commit.Tree(); err != nil {
return
}

if options, err = git.DefaultDiffOptions(); err != nil {
return
}

if rawDiff, err = repoDataLoader.repo.DiffTreeToWorkdir(tree, &options); err != nil {
return
}
}

return
Expand Down

0 comments on commit 66302c5

Please sign in to comment.