Skip to content

Commit 12397ee

Browse files
author
Mario Manno
committed
Fix up git package
Signed-off-by: Guilherme Macedo <[email protected]>
1 parent 5bd3575 commit 12397ee

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

pkg/git/git.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (g *Git) LsRemote(branch string, commit string) (string, error) {
6868
}
6969

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

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

9797
// Clone runs git clone with depth 1
9898
func (g *Git) Clone(branch string) error {
99-
return g.git("clone", "--depth=1", "-n", "--branch", branch, g.URL, g.Directory)
99+
if branch == "" {
100+
return g.git("clone", "--depth=1", "-n", "--", g.URL, g.Directory)
101+
}
102+
return g.git("clone", "--depth=1", "-n", "--branch="+branch, "--", g.URL, g.Directory)
100103
}
101104

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

301304
func (g *Git) fetchAndReset(rev string) error {
302-
if err := g.git("-C", g.Directory, "fetch", "origin", rev); err != nil {
305+
if err := g.git("-C", g.Directory, "fetch", "origin", "--", rev); err != nil {
303306
return err
304307
}
305308
return g.reset("FETCH_HEAD")
306309
}
307310

308311
func (g *Git) reset(rev string) error {
309-
return g.git("-C", g.Directory, "reset", "--hard", rev)
312+
return g.git("-C", g.Directory, "reset", "--hard", "--", rev)
310313
}
311314

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

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

0 commit comments

Comments
 (0)