aboutsummaryrefslogtreecommitdiffstats
path: root/repository_test.go
diff options
context:
space:
mode:
authorAyman Bagabas <ayman.bagabas@gmail.com>2023-11-28 14:31:04 -0500
committerAyman Bagabas <ayman.bagabas@gmail.com>2023-11-30 18:21:53 -0500
commitde1d5a5978b9599ca3dacd58bbf699e4bb4cf6bd (patch)
tree0b1cd5f542c58ff2f0cc0584a7fda7c600c4e37a /repository_test.go
parenta3b3d5347fda4f6392325d633f0ab308082c8843 (diff)
downloadgo-git-de1d5a5978b9599ca3dacd58bbf699e4bb4cf6bd.tar.gz
git: validate reference names
Check reference names format before creating branches/tags/remotes. This should probably be in a lower level somewhere in `plumbing`. Validating the names under `plumbing.NewReference*` is not possible since these functions don't return errors. Fixes: https://github.com/go-git/go-git/issues/929
Diffstat (limited to 'repository_test.go')
-rw-r--r--repository_test.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/repository_test.go b/repository_test.go
index 35a62f1..51df845 100644
--- a/repository_test.go
+++ b/repository_test.go
@@ -75,6 +75,13 @@ func (s *RepositorySuite) TestInitWithOptions(c *C) {
}
+func (s *RepositorySuite) TestInitWithInvalidDefaultBranch(c *C) {
+ _, err := InitWithOptions(memory.NewStorage(), memfs.New(), InitOptions{
+ DefaultBranch: "foo",
+ })
+ c.Assert(err, NotNil)
+}
+
func createCommit(c *C, r *Repository) {
// Create a commit so there is a HEAD to check
wt, err := r.Worktree()
@@ -391,6 +398,22 @@ func (s *RepositorySuite) TestDeleteRemote(c *C) {
c.Assert(alt, IsNil)
}
+func (s *RepositorySuite) TestEmptyCreateBranch(c *C) {
+ r, _ := Init(memory.NewStorage(), nil)
+ err := r.CreateBranch(&config.Branch{})
+
+ c.Assert(err, NotNil)
+}
+
+func (s *RepositorySuite) TestInvalidCreateBranch(c *C) {
+ r, _ := Init(memory.NewStorage(), nil)
+ err := r.CreateBranch(&config.Branch{
+ Name: "-foo",
+ })
+
+ c.Assert(err, NotNil)
+}
+
func (s *RepositorySuite) TestCreateBranchAndBranch(c *C) {
r, _ := Init(memory.NewStorage(), nil)
testBranch := &config.Branch{
@@ -2797,6 +2820,20 @@ func (s *RepositorySuite) TestDeleteTagAnnotatedUnpacked(c *C) {
c.Assert(err, Equals, plumbing.ErrObjectNotFound)
}
+func (s *RepositorySuite) TestInvalidTagName(c *C) {
+ r, err := Init(memory.NewStorage(), nil)
+ c.Assert(err, IsNil)
+ for i, name := range []string{
+ "",
+ "foo bar",
+ "foo\tbar",
+ "foo\nbar",
+ } {
+ _, err = r.CreateTag(name, plumbing.ZeroHash, nil)
+ c.Assert(err, NotNil, Commentf("case %d %q", i, name))
+ }
+}
+
func (s *RepositorySuite) TestBranches(c *C) {
f := fixtures.ByURL("https://github.com/git-fixtures/root-references.git").One()
sto := filesystem.NewStorage(f.DotGit(), cache.NewObjectLRUDefault())