diff options
author | Stefan Haller <stefan@haller-berlin.de> | 2023-02-26 11:51:02 +0100 |
---|---|---|
committer | Stefan Haller <stefan@haller-berlin.de> | 2023-06-22 18:57:58 +0200 |
commit | 3928d0ebda6952975059405544183bb1e63c0e1f (patch) | |
tree | e9369348db9401c683142cad2b5a293e780260da /pkg/commands/git_commands/commit_loader_test.go | |
parent | d66ca7751c22a888497d53830a4d94db02506def (diff) |
Insert fake todo entry for a conflicting commit that is being applied
When stopping in a rebase because of a conflict, it is nice to see the commit
that git is trying to apply. Create a fake todo entry labelled "conflict" for
this, and show the "<-- YOU ARE HERE ---" string for that one (in red) instead
of for the real current head.
Diffstat (limited to 'pkg/commands/git_commands/commit_loader_test.go')
-rw-r--r-- | pkg/commands/git_commands/commit_loader_test.go | 177 |
1 files changed, 177 insertions, 0 deletions
diff --git a/pkg/commands/git_commands/commit_loader_test.go b/pkg/commands/git_commands/commit_loader_test.go index a1a2c7e41..5c0102964 100644 --- a/pkg/commands/git_commands/commit_loader_test.go +++ b/pkg/commands/git_commands/commit_loader_test.go @@ -6,6 +6,7 @@ import ( "strings" "testing" + "github.com/fsmiamoto/git-todo-parser/todo" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/commands/oscommands" "github.com/jesseduffield/lazygit/pkg/commands/types/enums" @@ -319,3 +320,179 @@ func TestGetCommits(t *testing.T) { }) } } + +func TestCommitLoader_getConflictedCommitImpl(t *testing.T) { + scenarios := []struct { + testName string + todos []todo.Todo + doneTodos []todo.Todo + amendFileExists bool + expectedSha string + }{ + { + testName: "no done todos", + todos: []todo.Todo{}, + doneTodos: []todo.Todo{}, + amendFileExists: false, + expectedSha: "", + }, + { + testName: "common case (conflict)", + todos: []todo.Todo{}, + doneTodos: []todo.Todo{ + { + Command: todo.Pick, + Commit: "deadbeef", + }, + { + Command: todo.Pick, + Commit: "fa1afe1", + }, + }, + amendFileExists: false, + expectedSha: "fa1afe1", + }, + { + testName: "last command was 'break'", + todos: []todo.Todo{}, + doneTodos: []todo.Todo{ + {Command: todo.Break}, + }, + amendFileExists: false, + expectedSha: "", + }, + { + testName: "last command was 'exec'", + todos: []todo.Todo{}, + doneTodos: []todo.Todo{ + { + Command: todo.Exec, + ExecCommand: "make test", + }, + }, + amendFileExists: false, + expectedSha: "", + }, + { + testName: "last command was 'reword'", + todos: []todo.Todo{}, + doneTodos: []todo.Todo{ + {Command: todo.Reword}, + }, + amendFileExists: false, + expectedSha: "", + }, + { + testName: "'pick' was rescheduled", + todos: []todo.Todo{ + { + Command: todo.Pick, + Commit: "fa1afe1", + }, + }, + doneTodos: []todo.Todo{ + { + Command: todo.Pick, + Commit: "fa1afe1", + }, + }, + amendFileExists: false, + expectedSha: "", + }, + { + testName: "'pick' was rescheduled, buggy git version", + todos: []todo.Todo{ + { + Command: todo.Pick, + Commit: "fa1afe1", + }, + }, + doneTodos: []todo.Todo{ + { + Command: todo.Pick, + Commit: "deadbeaf", + }, + { + Command: todo.Pick, + Commit: "fa1afe1", + }, + { + Command: todo.Pick, + Commit: "deadbeaf", + }, + }, + amendFileExists: false, + expectedSha: "", + }, + { + testName: "conflicting 'pick' after 'exec'", + todos: []todo.Todo{ + { + Command: todo.Exec, + ExecCommand: "make test", + }, + }, + doneTodos: []todo.Todo{ + { + Command: todo.Pick, + Commit: "deadbeaf", + }, + { + Command: todo.Exec, + ExecCommand: "make test", + }, + { + Command: todo.Pick, + Commit: "fa1afe1", + }, + }, + amendFileExists: false, + expectedSha: "fa1afe1", + }, + { + testName: "'edit' with amend file", + todos: []todo.Todo{}, + doneTodos: []todo.Todo{ + { + Command: todo.Edit, + Commit: "fa1afe1", + }, + }, + amendFileExists: true, + expectedSha: "", + }, + { + testName: "'edit' without amend file", + todos: []todo.Todo{}, + doneTodos: []todo.Todo{ + { + Command: todo.Edit, + Commit: "fa1afe1", + }, + }, + amendFileExists: false, + expectedSha: "fa1afe1", + }, + } + for _, scenario := range scenarios { + t.Run(scenario.testName, func(t *testing.T) { + common := utils.NewDummyCommon() + + builder := &CommitLoader{ + Common: common, + cmd: oscommands.NewDummyCmdObjBuilder(oscommands.NewFakeRunner(t)), + getRebaseMode: func() (enums.RebaseMode, error) { return enums.REBASE_MODE_INTERACTIVE, nil }, + dotGitDir: ".git", + readFile: func(filename string) ([]byte, error) { + return []byte(""), nil + }, + walkFiles: func(root string, fn filepath.WalkFunc) error { + return nil + }, + } + + sha := builder.getConflictedCommitImpl(scenario.todos, scenario.doneTodos, scenario.amendFileExists) + assert.Equal(t, scenario.expectedSha, sha) + }) + } +} |