mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-10-06 05:57:38 -04:00
Tags can only be pushed one at a time. Let the push command of the tags panel work on a range selection of tags too. It asks for one remote and pushes all selected tags to it with a single git command. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
80 lines
2.5 KiB
Go
80 lines
2.5 KiB
Go
package components
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"strings"
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
|
"github.com/samber/lo"
|
|
)
|
|
|
|
type Git struct {
|
|
*assertionHelper
|
|
shell *Shell
|
|
}
|
|
|
|
func (self *Git) CurrentBranchName(expectedName string) *Git {
|
|
return self.assert([]string{"git", "rev-parse", "--abbrev-ref", "HEAD"}, expectedName)
|
|
}
|
|
|
|
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) RemoteTagDeleted(ref string, tagName string) *Git {
|
|
return self.expect([]string{"git", "ls-remote", ref, fmt.Sprintf("refs/tags/%s", tagName)}, func(s string) (bool, string) {
|
|
return len(s) == 0, fmt.Sprintf("Expected tag %s to have been removed from %s", tagName, ref)
|
|
})
|
|
}
|
|
|
|
// Asserts the names of all tags on the remote, in alphabetical order
|
|
func (self *Git) RemoteTagNames(remote string, expectedNames []string) *Git {
|
|
return self.expect([]string{"git", "ls-remote", "--tags", "--refs", remote}, func(output string) (bool, string) {
|
|
names := lo.FilterMap(strings.Split(output, "\n"), func(line string, _ int) (string, bool) {
|
|
_, ref, found := strings.Cut(line, "\t")
|
|
return strings.TrimPrefix(ref, "refs/tags/"), found
|
|
})
|
|
actual := strings.Join(names, "\n")
|
|
expected := strings.Join(expectedNames, "\n")
|
|
return actual == expected, fmt.Sprintf("Expected the tags on %s to be\n%s\nbut got\n%s", remote, expected, actual)
|
|
})
|
|
}
|
|
|
|
func (self *Git) assert(cmdArgs []string, expected string) *Git {
|
|
self.expect(cmdArgs, func(output string) (bool, string) {
|
|
return output == expected, fmt.Sprintf("Expected current branch name to be '%s', but got '%s'", expected, output)
|
|
})
|
|
|
|
return self
|
|
}
|
|
|
|
func (self *Git) expect(cmdArgs []string, condition func(string) (bool, string)) *Git {
|
|
self.assertWithRetries(func() (bool, string) {
|
|
output, err := self.shell.runCommandWithOutput(cmdArgs)
|
|
if err != nil {
|
|
return false, fmt.Sprintf("Unexpected error running command: `%v`. Error: %s", cmdArgs, err.Error())
|
|
}
|
|
actual := strings.TrimSpace(output)
|
|
return condition(actual)
|
|
})
|
|
|
|
return self
|
|
}
|
|
|
|
func (self *Git) Version() *git_commands.GitVersion {
|
|
version, err := getGitVersion()
|
|
if err != nil {
|
|
log.Fatalf("Could not get git version: %v", err)
|
|
}
|
|
return version
|
|
}
|
|
|
|
func (self *Git) GetCommitHash(ref string) string {
|
|
output, err := self.shell.runCommandWithOutput([]string{"git", "rev-parse", ref})
|
|
if err != nil {
|
|
log.Fatalf("Could not get commit hash: %v", err)
|
|
}
|
|
return strings.TrimSpace(output)
|
|
}
|