Skip to content

Commit

Permalink
Fix up git package
Browse files Browse the repository at this point in the history
Signed-off-by: Guilherme Macedo <guilherme.macedo@suse.com>
  • Loading branch information
Mario Manno committed Jan 23, 2023
1 parent 5bd3575 commit 12397ee
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pkg/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (g *Git) LsRemote(branch string, commit string) (string, error) {
}

output := &bytes.Buffer{}
if err := g.gitCmd(output, "ls-remote", g.URL, formatRefForBranch(branch)); err != nil {
if err := g.gitCmd(output, "ls-remote", "--", g.URL, formatRefForBranch(branch)); err != nil {
return "", err
}

Expand Down Expand Up @@ -96,7 +96,10 @@ func (g *Git) Head(branch string) (string, error) {

// Clone runs git clone with depth 1
func (g *Git) Clone(branch string) error {
return g.git("clone", "--depth=1", "-n", "--branch", branch, g.URL, g.Directory)
if branch == "" {
return g.git("clone", "--depth=1", "-n", "--", g.URL, g.Directory)
}
return g.git("clone", "--depth=1", "-n", "--branch="+branch, "--", g.URL, g.Directory)
}

// Update updates git repo if remote sha has changed
Expand Down Expand Up @@ -299,22 +302,22 @@ func (g *Git) clone(branch string) error {
}

func (g *Git) fetchAndReset(rev string) error {
if err := g.git("-C", g.Directory, "fetch", "origin", rev); err != nil {
if err := g.git("-C", g.Directory, "fetch", "origin", "--", rev); err != nil {
return err
}
return g.reset("FETCH_HEAD")
}

func (g *Git) reset(rev string) error {
return g.git("-C", g.Directory, "reset", "--hard", rev)
return g.git("-C", g.Directory, "reset", "--hard", "--", rev)
}

func (g *Git) currentCommit() (string, error) {
return g.gitOutput("-C", g.Directory, "rev-parse", "HEAD")
}

func (g *Git) gitCmd(output io.Writer, args ...string) error {
kv := fmt.Sprintf("credential.helper=%s", "/bin/sh -c 'echo password=$GIT_PASSWORD'")
kv := fmt.Sprintf("credential.helper=%s", `/bin/sh -c 'echo "password=$GIT_PASSWORD"'`)
cmd := exec.Command("git", append([]string{"-c", kv}, args...)...)
cmd.Env = append(os.Environ(), fmt.Sprintf("GIT_PASSWORD=%s", g.password))
stderrBuf := &bytes.Buffer{}
Expand Down

0 comments on commit 12397ee

Please sign in to comment.