MCPcopy
hub / github.com/jesseduffield/lazygit / TestGetCommits

Function TestGetCommits

pkg/commands/git_commands/commit_loader_test.go:30–334  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

28var singleCommitOutput = strings.ReplaceAll(`+0eea75e8c631fba6b58135697835d58ba4c18dbc|1640826609|Jesse Duffield|jessedduffield@gmail.com|b21997d6b4cbdf84b149|>|HEAD -> better-tests|better typing for rebase mode`, "|", "\x00")
29
30func TestGetCommits(t *testing.T) {
31 type scenario struct {
32 testName string
33 runner *oscommands.FakeCmdObjRunner
34 expectedCommitOpts []models.NewCommitOpts
35 expectedError error
36 logOrder string
37 opts GetCommitsOptions
38 mainBranches []string
39 }
40
41 scenarios := []scenario{
42 {
43 testName: "should return no commits if there are none",
44 logOrder: "topo-order",
45 opts: GetCommitsOptions{RefName: "HEAD", RefForPushedStatus: &models.Branch{Name: "mybranch"}, IncludeRebaseCommits: false},
46 runner: oscommands.NewFakeRunner(t).
47 ExpectGitArgs([]string{"rev-list", "refs/heads/mybranch", "^mybranch@{u}"}, "", nil).
48 ExpectGitArgs([]string{"log", "HEAD", "--topo-order", "--oneline", "--pretty=format:+%H%x00%at%x00%aN%x00%ae%x00%P%x00%m%x00%D%x00%s", "--abbrev=40", "--no-show-signature", "--"}, "", nil),
49
50 expectedCommitOpts: []models.NewCommitOpts{},
51 expectedError: nil,
52 },
53 {
54 testName: "should use proper upstream name for branch",
55 logOrder: "topo-order",
56 opts: GetCommitsOptions{RefName: "refs/heads/mybranch", RefForPushedStatus: &models.Branch{Name: "mybranch"}, IncludeRebaseCommits: false},
57 runner: oscommands.NewFakeRunner(t).
58 ExpectGitArgs([]string{"rev-list", "refs/heads/mybranch", "^mybranch@{u}"}, "", nil).
59 ExpectGitArgs([]string{"log", "refs/heads/mybranch", "--topo-order", "--oneline", "--pretty=format:+%H%x00%at%x00%aN%x00%ae%x00%P%x00%m%x00%D%x00%s", "--abbrev=40", "--no-show-signature", "--"}, "", nil),
60
61 expectedCommitOpts: []models.NewCommitOpts{},
62 expectedError: nil,
63 },
64 {
65 testName: "should return commits if they are present",
66 logOrder: "topo-order",
67 opts: GetCommitsOptions{RefName: "HEAD", RefForPushedStatus: &models.Branch{Name: "mybranch"}, IncludeRebaseCommits: false},
68 mainBranches: []string{"master", "main", "develop"},
69 runner: oscommands.NewFakeRunner(t).
70 // here it's seeing which commits are yet to be pushed
71 ExpectGitArgs([]string{"rev-list", "refs/heads/mybranch", "^mybranch@{u}", "^refs/remotes/origin/master", "^refs/remotes/origin/main"}, "0eea75e8c631fba6b58135697835d58ba4c18dbc\n", nil).
72 // here it's actually getting all the commits in a formatted form, one per line
73 ExpectGitArgs([]string{"log", "HEAD", "--topo-order", "--oneline", "--pretty=format:+%H%x00%at%x00%aN%x00%ae%x00%P%x00%m%x00%D%x00%s", "--abbrev=40", "--no-show-signature", "--"}, commitsOutput, nil).
74 // here it's testing which of the configured main branches have an upstream
75 ExpectGitArgs([]string{"rev-parse", "--symbolic-full-name", "master@{u}"}, "refs/remotes/origin/master", nil). // this one does
76 ExpectGitArgs([]string{"rev-parse", "--symbolic-full-name", "main@{u}"}, "", errors.New("error")). // this one doesn't, so it checks origin instead
77 ExpectGitArgs([]string{"rev-parse", "--verify", "--quiet", "refs/remotes/origin/main"}, "", nil). // yep, origin/main exists
78 ExpectGitArgs([]string{"rev-parse", "--symbolic-full-name", "develop@{u}"}, "", errors.New("error")). // this one doesn't, so it checks origin instead
79 ExpectGitArgs([]string{"rev-parse", "--verify", "--quiet", "refs/remotes/origin/develop"}, "", errors.New("error")). // doesn't exist there, either, so it checks for a local branch
80 ExpectGitArgs([]string{"rev-parse", "--verify", "--quiet", "refs/heads/develop"}, "", errors.New("error")). // no local branch either
81 // here it's seeing which of our commits are not on any of the main branches yet
82 ExpectGitArgs([]string{"rev-list", "HEAD", "^refs/remotes/origin/master", "^refs/remotes/origin/main"},
83 "0eea75e8c631fba6b58135697835d58ba4c18dbc\nb21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164\ne94e8fc5b6fab4cb755f29f1bdb3ee5e001df35c\nd8084cd558925eb7c9c38afeed5725c21653ab90\n65f910ebd85283b5cce9bf67d03d3f1a9ea3813a\n", nil),
84
85 expectedCommitOpts: []models.NewCommitOpts{
86 {
87 Hash: "0eea75e8c631fba6b58135697835d58ba4c18dbc",

Callers

nothing calls this directly

Calls 10

GetCommitsMethod · 0.95
NewFakeRunnerFunction · 0.92
NewDummyCmdObjBuilderFunction · 0.92
NewCommitFunction · 0.92
NewMainBranchesFunction · 0.85
ExpectGitArgsMethod · 0.80
UserConfigMethod · 0.80
CheckForMissingCallsMethod · 0.80
NewMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected