aboutsummaryrefslogtreecommitdiffstats
path: root/worktree_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 /worktree_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 'worktree_test.go')
-rw-r--r--worktree_test.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/worktree_test.go b/worktree_test.go
index 180bfb0..5c9a4eb 100644
--- a/worktree_test.go
+++ b/worktree_test.go
@@ -785,6 +785,30 @@ func (s *WorktreeSuite) TestCheckoutCreateMissingBranch(c *C) {
c.Assert(err, Equals, ErrCreateRequiresBranch)
}
+func (s *WorktreeSuite) TestCheckoutCreateInvalidBranch(c *C) {
+ w := &Worktree{
+ r: s.Repository,
+ Filesystem: memfs.New(),
+ }
+
+ for _, name := range []plumbing.ReferenceName{
+ "foo",
+ "-",
+ "-foo",
+ "refs/heads//",
+ "refs/heads/..",
+ "refs/heads/a..b",
+ "refs/heads/.",
+ } {
+ err := w.Checkout(&CheckoutOptions{
+ Create: true,
+ Branch: name,
+ })
+
+ c.Assert(err, Equals, plumbing.ErrInvalidReferenceName)
+ }
+}
+
func (s *WorktreeSuite) TestCheckoutTag(c *C) {
f := fixtures.ByTag("tags").One()
r := s.NewRepositoryWithEmptyWorktree(f)