diff options
| author | jannfis <jann@mistrust.net> | 2021-01-30 19:21:08 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-30 19:21:08 +0100 |
| commit | 84c46306929e276d995a38463f13e383fa57fc45 (patch) | |
| tree | f33e485090c402bcdb83309016e802dee4260196 /ext/git/client.go | |
| parent | c9e4de4b33a180e803ed01d28f37dc85e2a5fba3 (diff) | |
feat: Resolve symrefs to allow them as targetRevision for write back (#151)
Diffstat (limited to 'ext/git/client.go')
| -rw-r--r-- | ext/git/client.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/ext/git/client.go b/ext/git/client.go index 097ce9e..1c28491 100644 --- a/ext/git/client.go +++ b/ext/git/client.go @@ -63,6 +63,7 @@ type Client interface { Commit(pathSpec string, message string, signingKey string) error Push(remote string, branch string, force bool) error Add(path string) error + SymRefToBranch(symRef string) (string, error) } // nativeGitClient implements Client interface using git CLI @@ -514,6 +515,12 @@ func (m *nativeGitClient) VerifyCommitSignature(revision string) (string, error) return out, nil } +// Commit perfoms a git commit for the given pathSpec to the currently checked +// out branch. If pathSpec is empty, or the special value "*", all pending +// changes will be commited. If message is not the empty string, it will be +// used as the commit message, otherwise a default commit message will be used. +// If signingKey is not the empty string, commit will be signed with the given +// GPG key. func (m *nativeGitClient) Commit(pathSpec string, message string, signingKey string) error { defaultCommitMsg := "Update parameters" args := []string{"commit"} @@ -555,6 +562,8 @@ func (m *nativeGitClient) Branch(sourceBranch string, targetBranch string) error return nil } +// Push pushes local changes to the remote branch. If force is true, will force +// the remote to accept the push. func (m *nativeGitClient) Push(remote string, branch string, force bool) error { args := []string{"push"} if force { @@ -568,10 +577,23 @@ func (m *nativeGitClient) Push(remote string, branch string, force bool) error { return nil } +// Add adds a path spec to the repository func (m *nativeGitClient) Add(path string) error { return m.runCredentialedCmd("git", "add", path) } +// SymRefToBranch retrieves the branch name a symbolic ref points to +func (m *nativeGitClient) SymRefToBranch(symRef string) (string, error) { + output, err := m.runCmd("symbolic-ref", symRef) + if err != nil { + return "", fmt.Errorf("could not resolve symbolic ref '%s': %v", symRef, err) + } + if a := strings.SplitN(output, "refs/heads/", 2); len(a) == 2 { + return a[1], nil + } + return "", fmt.Errorf("no symbolic ref named '%s' could be found", symRef) +} + // runWrapper runs a custom command with all the semantics of running the Git client func (m *nativeGitClient) runGnuPGWrapper(wrapper string, args ...string) (string, error) { cmd := exec.Command(wrapper, args...) |
