1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-15 00:15:32 +02:00

commands/git : add tests, refactor a bit

This commit is contained in:
Anthony HAMON
2018-09-13 21:27:35 +02:00
parent fa08c6c2a2
commit 91832f2c5e
2 changed files with 146 additions and 8 deletions

View File

@ -365,12 +365,12 @@ func (c *GitCommand) SquashFixupCommit(branchName string, shaValue string) error
// CatFile obtains the content of a file
func (c *GitCommand) CatFile(fileName string) (string, error) {
return c.OSCommand.RunCommandWithOutput("cat " + c.OSCommand.Quote(fileName))
return c.OSCommand.RunCommandWithOutput(fmt.Sprintf("cat %s", c.OSCommand.Quote(fileName)))
}
// StageFile stages a file
func (c *GitCommand) StageFile(fileName string) error {
return c.OSCommand.RunCommand("git add " + c.OSCommand.Quote(fileName))
return c.OSCommand.RunCommand(fmt.Sprintf("git add %s", c.OSCommand.Quote(fileName)))
}
// StageAll stages all files
@ -385,13 +385,11 @@ func (c *GitCommand) UnstageAll() error {
// UnStageFile unstages a file
func (c *GitCommand) UnStageFile(fileName string, tracked bool) error {
var command string
command := "git rm --cached %s"
if tracked {
command = "git reset HEAD "
} else {
command = "git rm --cached "
command = "git reset HEAD %s"
}
return c.OSCommand.RunCommand(command + c.OSCommand.Quote(fileName))
return c.OSCommand.RunCommand(fmt.Sprintf(command, c.OSCommand.Quote(fileName)))
}
// GitStatus returns the plaintext short status of the repo