u.Fragment = ""
repo.remote = u.String()
}
+
+ if strings.HasPrefix(repo.ref, "-") {
+ return gitRepo{}, errors.Errorf("invalid refspec: %s", repo.ref)
+ }
+
return repo, nil
}
args = append(args, "--depth", "1")
}
- return append(args, "origin", ref)
+ return append(args, "origin", "--", ref)
}
// Check if a given git URL supports a shallow git clone,
})
args := fetchArgs(serverURL.String(), "master")
- exp := []string{"fetch", "--depth", "1", "origin", "master"}
+ exp := []string{"fetch", "--depth", "1", "origin", "--", "master"}
assert.Check(t, is.DeepEqual(exp, args))
}
})
args := fetchArgs(serverURL.String(), "master")
- exp := []string{"fetch", "origin", "master"}
+ exp := []string{"fetch", "origin", "--", "master"}
assert.Check(t, is.DeepEqual(exp, args))
}
func TestCloneArgsGit(t *testing.T) {
args := fetchArgs("git://github.com/docker/docker", "master")
- exp := []string{"fetch", "--depth", "1", "origin", "master"}
+ exp := []string{"fetch", "--depth", "1", "origin", "--", "master"}
assert.Check(t, is.DeepEqual(exp, args))
}
}
}
}
+
+func TestGitInvalidRef(t *testing.T) {
+ gitUrls := []string{
+ "git://github.com/moby/moby#--foo bar",
+ "git@github.com/moby/moby#--upload-pack=sleep;:",
+ "git@g.com:a/b.git#-B",
+ "git@g.com:a/b.git#with space",
+ }
+
+ for _, url := range gitUrls {
+ _, err := Clone(url)
+ assert.Assert(t, err != nil)
+ assert.Check(t, is.Contains(strings.ToLower(err.Error()), "invalid refspec"))
+ }
+}