mirror of
				https://github.com/jesseduffield/lazygit.git
				synced 2025-10-30 23:57:43 +02:00 
			
		
		
		
	fix specs
This commit is contained in:
		| @@ -47,7 +47,7 @@ func (b *BranchListBuilder) obtainCurrentBranch() *Branch { | |||||||
|  |  | ||||||
| func (b *BranchListBuilder) obtainReflogBranches() []*Branch { | func (b *BranchListBuilder) obtainReflogBranches() []*Branch { | ||||||
| 	branches := make([]*Branch, 0) | 	branches := make([]*Branch, 0) | ||||||
| 	rawString, err := b.GitCommand.OSCommand.RunCommandWithOutput(`git reflog -n100 --pretty='%cr|%gs' --grep-reflog='checkout: moving' HEAD`) | 	rawString, err := b.GitCommand.OSCommand.RunCommandWithOutput("git reflog -n100 --pretty='%cr|%gs' --grep-reflog='checkout: moving' HEAD") | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return branches | 		return branches | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -289,6 +289,10 @@ func TestCommitListBuilderGetCommits(t *testing.T) { | |||||||
| 					assert.EqualValues(t, []string{"symbolic-ref", "--short", "HEAD"}, args) | 					assert.EqualValues(t, []string{"symbolic-ref", "--short", "HEAD"}, args) | ||||||
| 					// here's where we are returning the error | 					// here's where we are returning the error | ||||||
| 					return exec.Command("test") | 					return exec.Command("test") | ||||||
|  | 				case "branch": | ||||||
|  | 					assert.EqualValues(t, []string{"branch", "--contains"}, args) | ||||||
|  | 					// here too | ||||||
|  | 					return exec.Command("test") | ||||||
| 				case "rev-parse": | 				case "rev-parse": | ||||||
| 					assert.EqualValues(t, []string{"rev-parse", "--short", "HEAD"}, args) | 					assert.EqualValues(t, []string{"rev-parse", "--short", "HEAD"}, args) | ||||||
| 					// here too | 					// here too | ||||||
|   | |||||||
| @@ -157,7 +157,7 @@ func findDotGitDir(stat func(string) (os.FileInfo, error), readFile func(filenam | |||||||
|  |  | ||||||
| // GetStashEntries stash entries | // GetStashEntries stash entries | ||||||
| func (c *GitCommand) GetStashEntries() []*StashEntry { | func (c *GitCommand) GetStashEntries() []*StashEntry { | ||||||
| 	rawString, _ := c.OSCommand.RunCommandWithOutput(`git stash list --pretty='%gs'`) | 	rawString, _ := c.OSCommand.RunCommandWithOutput("git stash list --pretty='%gs'") | ||||||
| 	stashEntries := []*StashEntry{} | 	stashEntries := []*StashEntry{} | ||||||
| 	for i, line := range utils.SplitLines(rawString) { | 	for i, line := range utils.SplitLines(rawString) { | ||||||
| 		stashEntries = append(stashEntries, stashEntryFromLine(line, i)) | 		stashEntries = append(stashEntries, stashEntryFromLine(line, i)) | ||||||
| @@ -333,12 +333,12 @@ func (c *GitCommand) CurrentBranchName() (string, error) { | |||||||
| 	branchName, err := c.OSCommand.RunCommandWithOutput("git symbolic-ref --short HEAD") | 	branchName, err := c.OSCommand.RunCommandWithOutput("git symbolic-ref --short HEAD") | ||||||
| 	if err != nil || branchName == "HEAD\n" { | 	if err != nil || branchName == "HEAD\n" { | ||||||
| 		output, err := c.OSCommand.RunCommandWithOutput("git branch --contains") | 		output, err := c.OSCommand.RunCommandWithOutput("git branch --contains") | ||||||
| 		re := regexp.MustCompile(CurrentBranchNameRegex) |  | ||||||
| 		match := re.FindStringSubmatch(output) |  | ||||||
| 		branchName = match[1] |  | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return "", err | 			return "", err | ||||||
| 		} | 		} | ||||||
|  | 		re := regexp.MustCompile(CurrentBranchNameRegex) | ||||||
|  | 		match := re.FindStringSubmatch(output) | ||||||
|  | 		branchName = match[1] | ||||||
| 	} | 	} | ||||||
| 	return utils.TrimTrailingNewline(branchName), nil | 	return utils.TrimTrailingNewline(branchName), nil | ||||||
| } | } | ||||||
|   | |||||||
| @@ -58,14 +58,14 @@ func (f fileInfoMock) Sys() interface{} { | |||||||
| func TestVerifyInGitRepo(t *testing.T) { | func TestVerifyInGitRepo(t *testing.T) { | ||||||
| 	type scenario struct { | 	type scenario struct { | ||||||
| 		testName string | 		testName string | ||||||
| 		runCmd   func(string) error | 		runCmd   func(string, ...interface{}) error | ||||||
| 		test     func(error) | 		test     func(error) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	scenarios := []scenario{ | 	scenarios := []scenario{ | ||||||
| 		{ | 		{ | ||||||
| 			"Valid git repository", | 			"Valid git repository", | ||||||
| 			func(string) error { | 			func(string, ...interface{}) error { | ||||||
| 				return nil | 				return nil | ||||||
| 			}, | 			}, | ||||||
| 			func(err error) { | 			func(err error) { | ||||||
| @@ -74,7 +74,7 @@ func TestVerifyInGitRepo(t *testing.T) { | |||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			"Not a valid git repository", | 			"Not a valid git repository", | ||||||
| 			func(string) error { | 			func(string, ...interface{}) error { | ||||||
| 				return fmt.Errorf("fatal: Not a git repository (or any of the parent directories): .git") | 				return fmt.Errorf("fatal: Not a git repository (or any of the parent directories): .git") | ||||||
| 			}, | 			}, | ||||||
| 			func(err error) { | 			func(err error) { | ||||||
| @@ -990,7 +990,7 @@ func TestGitCommandPush(t *testing.T) { | |||||||
| 			"Push with force disabled", | 			"Push with force disabled", | ||||||
| 			func(cmd string, args ...string) *exec.Cmd { | 			func(cmd string, args ...string) *exec.Cmd { | ||||||
| 				assert.EqualValues(t, "git", cmd) | 				assert.EqualValues(t, "git", cmd) | ||||||
| 				assert.EqualValues(t, []string{"push"}, args) | 				assert.EqualValues(t, []string{"push", "--follow-tags"}, args) | ||||||
|  |  | ||||||
| 				return exec.Command("echo") | 				return exec.Command("echo") | ||||||
| 			}, | 			}, | ||||||
| @@ -1003,7 +1003,7 @@ func TestGitCommandPush(t *testing.T) { | |||||||
| 			"Push with force enabled", | 			"Push with force enabled", | ||||||
| 			func(cmd string, args ...string) *exec.Cmd { | 			func(cmd string, args ...string) *exec.Cmd { | ||||||
| 				assert.EqualValues(t, "git", cmd) | 				assert.EqualValues(t, "git", cmd) | ||||||
| 				assert.EqualValues(t, []string{"push", "--force-with-lease"}, args) | 				assert.EqualValues(t, []string{"push", "--follow-tags", "--force-with-lease"}, args) | ||||||
|  |  | ||||||
| 				return exec.Command("echo") | 				return exec.Command("echo") | ||||||
| 			}, | 			}, | ||||||
| @@ -1016,7 +1016,7 @@ func TestGitCommandPush(t *testing.T) { | |||||||
| 			"Push with an error occurring", | 			"Push with an error occurring", | ||||||
| 			func(cmd string, args ...string) *exec.Cmd { | 			func(cmd string, args ...string) *exec.Cmd { | ||||||
| 				assert.EqualValues(t, "git", cmd) | 				assert.EqualValues(t, "git", cmd) | ||||||
| 				assert.EqualValues(t, []string{"push"}, args) | 				assert.EqualValues(t, []string{"push", "--follow-tags"}, args) | ||||||
| 				return exec.Command("test") | 				return exec.Command("test") | ||||||
| 			}, | 			}, | ||||||
| 			false, | 			false, | ||||||
| @@ -1639,7 +1639,7 @@ func TestGitCommandCurrentBranchName(t *testing.T) { | |||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			"falls back to git rev-parse if symbolic-ref fails", | 			"falls back to git `git branch --contains` if symbolic-ref fails", | ||||||
| 			func(cmd string, args ...string) *exec.Cmd { | 			func(cmd string, args ...string) *exec.Cmd { | ||||||
| 				assert.EqualValues(t, "git", cmd) | 				assert.EqualValues(t, "git", cmd) | ||||||
|  |  | ||||||
| @@ -1647,9 +1647,9 @@ func TestGitCommandCurrentBranchName(t *testing.T) { | |||||||
| 				case "symbolic-ref": | 				case "symbolic-ref": | ||||||
| 					assert.EqualValues(t, []string{"symbolic-ref", "--short", "HEAD"}, args) | 					assert.EqualValues(t, []string{"symbolic-ref", "--short", "HEAD"}, args) | ||||||
| 					return exec.Command("test") | 					return exec.Command("test") | ||||||
| 				case "rev-parse": | 				case "branch": | ||||||
| 					assert.EqualValues(t, []string{"rev-parse", "--short", "HEAD"}, args) | 					assert.EqualValues(t, []string{"branch", "--contains"}, args) | ||||||
| 					return exec.Command("echo", "master") | 					return exec.Command("echo", "* master") | ||||||
| 				} | 				} | ||||||
|  |  | ||||||
| 				return nil | 				return nil | ||||||
|   | |||||||
| @@ -9,7 +9,7 @@ import ( | |||||||
|  |  | ||||||
| func (c *GitCommand) GetRemotes() ([]*Remote, error) { | func (c *GitCommand) GetRemotes() ([]*Remote, error) { | ||||||
| 	// get remote branches | 	// get remote branches | ||||||
| 	remoteBranchesStr, err := c.OSCommand.RunCommandWithOutput(`git for-each-ref --format='%(refname:strip=2)' refs/remotes`) | 	remoteBranchesStr, err := c.OSCommand.RunCommandWithOutput("git for-each-ref --format='%%(refname:strip=2)' refs/remotes") | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -59,9 +59,11 @@ func (c *OSCommand) SetCommand(cmd func(string, ...string) *exec.Cmd) { | |||||||
| } | } | ||||||
|  |  | ||||||
| // RunCommandWithOutput wrapper around commands returning their output and error | // RunCommandWithOutput wrapper around commands returning their output and error | ||||||
|  | // NOTE: because this takes a format string followed by format args, you'll need | ||||||
|  | // to escape any percentage signs via '%%'. | ||||||
| func (c *OSCommand) RunCommandWithOutput(formatString string, formatArgs ...interface{}) (string, error) { | func (c *OSCommand) RunCommandWithOutput(formatString string, formatArgs ...interface{}) (string, error) { | ||||||
| 	command := formatString | 	command := formatString | ||||||
| 	if len(formatArgs) > 0 { | 	if formatArgs != nil { | ||||||
| 		command = fmt.Sprintf(formatString, formatArgs...) | 		command = fmt.Sprintf(formatString, formatArgs...) | ||||||
| 	} | 	} | ||||||
| 	c.Log.WithField("command", command).Info("RunCommand") | 	c.Log.WithField("command", command).Info("RunCommand") | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user