mirror of
				https://github.com/jesseduffield/lazygit.git
				synced 2025-10-30 23:57:43 +02:00 
			
		
		
		
	feat(log): allow to disable git.log.order
				
					
				
			This commit is contained in:
		| @@ -74,7 +74,7 @@ git: | |||||||
|     # extra args passed to `git merge`, e.g. --no-ff |     # extra args passed to `git merge`, e.g. --no-ff | ||||||
|     args: '' |     args: '' | ||||||
|   log: |   log: | ||||||
|     # one of date-order, author-date-order, topo-order. |     # one of date-order, author-date-order, topo-order or default. | ||||||
|     # topo-order makes it easier to read the git log graph, but commits may not |     # topo-order makes it easier to read the git log graph, but commits may not | ||||||
|     # appear chronologically. See https://git-scm.com/docs/git-log#_commit_ordering |     # appear chronologically. See https://git-scm.com/docs/git-log#_commit_ordering | ||||||
|     order: 'topo-order' |     order: 'topo-order' | ||||||
|   | |||||||
| @@ -426,7 +426,10 @@ func (self *CommitLoader) getLogCmd(opts GetCommitsOptions) oscommands.ICmdObj { | |||||||
|  |  | ||||||
| 	config := self.UserConfig.Git.Log | 	config := self.UserConfig.Git.Log | ||||||
|  |  | ||||||
| 	orderFlag := "--" + config.Order | 	orderFlag := "" | ||||||
|  | 	if config.Order != "default" { | ||||||
|  | 		orderFlag = " --" + config.Order | ||||||
|  | 	} | ||||||
| 	allFlag := "" | 	allFlag := "" | ||||||
| 	if opts.All { | 	if opts.All { | ||||||
| 		allFlag = " --all" | 		allFlag = " --all" | ||||||
| @@ -434,7 +437,7 @@ func (self *CommitLoader) getLogCmd(opts GetCommitsOptions) oscommands.ICmdObj { | |||||||
|  |  | ||||||
| 	return self.cmd.New( | 	return self.cmd.New( | ||||||
| 		fmt.Sprintf( | 		fmt.Sprintf( | ||||||
| 			"git -c log.showSignature=false log %s %s %s --oneline %s%s --abbrev=%d%s", | 			"git -c log.showSignature=false log %s%s%s --oneline %s%s --abbrev=%d%s", | ||||||
| 			self.cmd.Quote(opts.RefName), | 			self.cmd.Quote(opts.RefName), | ||||||
| 			orderFlag, | 			orderFlag, | ||||||
| 			allFlag, | 			allFlag, | ||||||
|   | |||||||
| @@ -27,6 +27,7 @@ func TestGetCommits(t *testing.T) { | |||||||
| 		runner            *oscommands.FakeCmdObjRunner | 		runner            *oscommands.FakeCmdObjRunner | ||||||
| 		expectedCommits   []*models.Commit | 		expectedCommits   []*models.Commit | ||||||
| 		expectedError     error | 		expectedError     error | ||||||
|  | 		logOrder          string | ||||||
| 		rebaseMode        enums.RebaseMode | 		rebaseMode        enums.RebaseMode | ||||||
| 		currentBranchName string | 		currentBranchName string | ||||||
| 		opts              GetCommitsOptions | 		opts              GetCommitsOptions | ||||||
| @@ -35,18 +36,20 @@ func TestGetCommits(t *testing.T) { | |||||||
| 	scenarios := []scenario{ | 	scenarios := []scenario{ | ||||||
| 		{ | 		{ | ||||||
| 			testName:          "should return no commits if there are none", | 			testName:          "should return no commits if there are none", | ||||||
|  | 			logOrder:          "topo-order", | ||||||
| 			rebaseMode:        enums.REBASE_MODE_NONE, | 			rebaseMode:        enums.REBASE_MODE_NONE, | ||||||
| 			currentBranchName: "master", | 			currentBranchName: "master", | ||||||
| 			opts:              GetCommitsOptions{RefName: "HEAD", IncludeRebaseCommits: false}, | 			opts:              GetCommitsOptions{RefName: "HEAD", IncludeRebaseCommits: false}, | ||||||
| 			runner: oscommands.NewFakeRunner(t). | 			runner: oscommands.NewFakeRunner(t). | ||||||
| 				Expect(`git merge-base "HEAD" "HEAD"@{u}`, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164", nil). | 				Expect(`git merge-base "HEAD" "HEAD"@{u}`, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164", nil). | ||||||
| 				Expect(`git -c log.showSignature=false log "HEAD" --topo-order  --oneline --pretty=format:"%H%x00%at%x00%aN%x00%ae%x00%d%x00%p%x00%s" --abbrev=40`, "", nil), | 				Expect(`git -c log.showSignature=false log "HEAD" --topo-order --oneline --pretty=format:"%H%x00%at%x00%aN%x00%ae%x00%d%x00%p%x00%s" --abbrev=40`, "", nil), | ||||||
|  |  | ||||||
| 			expectedCommits: []*models.Commit{}, | 			expectedCommits: []*models.Commit{}, | ||||||
| 			expectedError:   nil, | 			expectedError:   nil, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			testName:          "should return commits if they are present", | 			testName:          "should return commits if they are present", | ||||||
|  | 			logOrder:          "topo-order", | ||||||
| 			rebaseMode:        enums.REBASE_MODE_NONE, | 			rebaseMode:        enums.REBASE_MODE_NONE, | ||||||
| 			currentBranchName: "master", | 			currentBranchName: "master", | ||||||
| 			opts:              GetCommitsOptions{RefName: "HEAD", IncludeRebaseCommits: false}, | 			opts:              GetCommitsOptions{RefName: "HEAD", IncludeRebaseCommits: false}, | ||||||
| @@ -54,7 +57,7 @@ func TestGetCommits(t *testing.T) { | |||||||
| 				// here it's seeing which commits are yet to be pushed | 				// here it's seeing which commits are yet to be pushed | ||||||
| 				Expect(`git merge-base "HEAD" "HEAD"@{u}`, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164", nil). | 				Expect(`git merge-base "HEAD" "HEAD"@{u}`, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164", nil). | ||||||
| 				// here it's actually getting all the commits in a formatted form, one per line | 				// here it's actually getting all the commits in a formatted form, one per line | ||||||
| 				Expect(`git -c log.showSignature=false log "HEAD" --topo-order  --oneline --pretty=format:"%H%x00%at%x00%aN%x00%ae%x00%d%x00%p%x00%s" --abbrev=40`, commitsOutput, nil). | 				Expect(`git -c log.showSignature=false log "HEAD" --topo-order --oneline --pretty=format:"%H%x00%at%x00%aN%x00%ae%x00%d%x00%p%x00%s" --abbrev=40`, commitsOutput, nil). | ||||||
| 				// here it's seeing where our branch diverged from the master branch so that we can mark that commit and parent commits as 'merged' | 				// here it's seeing where our branch diverged from the master branch so that we can mark that commit and parent commits as 'merged' | ||||||
| 				Expect(`git merge-base "HEAD" "master"`, "26c07b1ab33860a1a7591a0638f9925ccf497ffa", nil), | 				Expect(`git merge-base "HEAD" "master"`, "26c07b1ab33860a1a7591a0638f9925ccf497ffa", nil), | ||||||
|  |  | ||||||
| @@ -174,13 +177,29 @@ func TestGetCommits(t *testing.T) { | |||||||
| 			}, | 			}, | ||||||
| 			expectedError: nil, | 			expectedError: nil, | ||||||
| 		}, | 		}, | ||||||
|  | 		{ | ||||||
|  | 			testName:          "should not specify order if `log.order` is `default`", | ||||||
|  | 			logOrder:          "default", | ||||||
|  | 			rebaseMode:        enums.REBASE_MODE_NONE, | ||||||
|  | 			currentBranchName: "master", | ||||||
|  | 			opts:              GetCommitsOptions{RefName: "HEAD", IncludeRebaseCommits: false}, | ||||||
|  | 			runner: oscommands.NewFakeRunner(t). | ||||||
|  | 				Expect(`git merge-base "HEAD" "HEAD"@{u}`, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164", nil). | ||||||
|  | 				Expect(`git -c log.showSignature=false log "HEAD" --oneline --pretty=format:"%H%x00%at%x00%aN%x00%ae%x00%d%x00%p%x00%s" --abbrev=40`, "", nil), | ||||||
|  |  | ||||||
|  | 			expectedCommits: []*models.Commit{}, | ||||||
|  | 			expectedError:   nil, | ||||||
|  | 		}, | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	for _, scenario := range scenarios { | 	for _, scenario := range scenarios { | ||||||
| 		scenario := scenario | 		scenario := scenario | ||||||
| 		t.Run(scenario.testName, func(t *testing.T) { | 		t.Run(scenario.testName, func(t *testing.T) { | ||||||
|  | 			common := utils.NewDummyCommon() | ||||||
|  | 			common.UserConfig.Git.Log.Order = scenario.logOrder | ||||||
|  |  | ||||||
| 			builder := &CommitLoader{ | 			builder := &CommitLoader{ | ||||||
| 				Common: utils.NewDummyCommon(), | 				Common: common, | ||||||
| 				cmd:    oscommands.NewDummyCmdObjBuilder(scenario.runner), | 				cmd:    oscommands.NewDummyCmdObjBuilder(scenario.runner), | ||||||
| 				getCurrentBranchInfo: func() (BranchInfo, error) { | 				getCurrentBranchInfo: func() (BranchInfo, error) { | ||||||
| 					return BranchInfo{RefName: scenario.currentBranchName, DisplayName: scenario.currentBranchName, DetachedHead: false}, nil | 					return BranchInfo{RefName: scenario.currentBranchName, DisplayName: scenario.currentBranchName, DetachedHead: false}, nil | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user