aboutsummaryrefslogtreecommitdiffstats
path: root/repository.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.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.go')
-rw-r--r--repository.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/repository.go b/repository.go
index 4898838..1524a69 100644
--- a/repository.go
+++ b/repository.go
@@ -98,6 +98,10 @@ func InitWithOptions(s storage.Storer, worktree billy.Filesystem, options InitOp
options.DefaultBranch = plumbing.Master
}
+ if err := options.DefaultBranch.Validate(); err != nil {
+ return nil, err
+ }
+
r := newRepository(s, worktree)
_, err := r.Reference(plumbing.HEAD, false)
switch err {
@@ -724,7 +728,10 @@ func (r *Repository) DeleteBranch(name string) error {
// CreateTag creates a tag. If opts is included, the tag is an annotated tag,
// otherwise a lightweight tag is created.
func (r *Repository) CreateTag(name string, hash plumbing.Hash, opts *CreateTagOptions) (*plumbing.Reference, error) {
- rname := plumbing.ReferenceName(path.Join("refs", "tags", name))
+ rname := plumbing.NewTagReferenceName(name)
+ if err := rname.Validate(); err != nil {
+ return nil, err
+ }
_, err := r.Storer.Reference(rname)
switch err {