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
macedogm authored and Mario Manno committed Jan 23, 2023
1 parent 8247b50 commit 8649ecc
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/git/git.go
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 @@ -97,9 +97,9 @@ func (g *Git) Head(branch string) (string, error) {
// Clone runs git clone with depth 1
func (g *Git) Clone(branch string) error {
if branch == "" {
return g.git("clone", "--depth=1", "-n", g.URL, g.Directory)
return g.git("clone", "--depth=1", "-n", "--", g.URL, g.Directory)
}
return g.git("clone", "--depth=1", "-n", "--branch", branch, 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 @@ -302,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 8649ecc

Please sign in to comment.