1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-05 13:24:54 +02:00

33 lines
922 B
Go
Raw Normal View History

2022-12-27 22:52:20 +11:00
package components
import (
"fmt"
"strings"
)
type Git struct {
*assertionHelper
shell *Shell
}
func (self *Git) CurrentBranchName(expectedName string) *Git {
return self.assert([]string{"git", "rev-parse", "--abbrev-ref", "HEAD"}, expectedName)
2022-12-27 22:52:20 +11:00
}
func (self *Git) TagNamesAt(ref string, expectedNames []string) *Git {
return self.assert([]string{"git", "tag", "--sort=v:refname", "--points-at", ref}, strings.Join(expectedNames, "\n"))
}
func (self *Git) assert(cmdArgs []string, expected string) *Git {
2022-12-27 22:52:20 +11:00
self.assertWithRetries(func() (bool, string) {
output, err := self.shell.runCommandWithOutput(cmdArgs)
2022-12-27 22:52:20 +11:00
if err != nil {
return false, fmt.Sprintf("Unexpected error running command: `%v`. Error: %s", cmdArgs, err.Error())
2022-12-27 22:52:20 +11:00
}
actual := strings.TrimSpace(output)
return actual == expected, fmt.Sprintf("Expected current branch name to be '%s', but got '%s'", expected, actual)
})
return self
}