aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2020-08-31 17:43:27 +0200
committerGitHub <noreply@github.com>2020-08-31 17:43:27 +0200
commit6da5e5958ecc0e6f8da6ee2b6714e50b8ef26df4 (patch)
treec0eec2aae09993118c120fa04db57bf1bd1126f9
parent5bf939bc5c03b149e7ec80653bcaa901d05d0d44 (diff)
parent711b703b572e07d3d0437eae4662419b5c392a6b (diff)
downloadgo-git-6da5e5958ecc0e6f8da6ee2b6714e50b8ef26df4.tar.gz
Merge pull request #158 from chrisgavin/fix-force-push-delete-reference
git: remote, Fix deleting references when force pushing.
-rw-r--r--remote.go2
-rw-r--r--remote_test.go25
2 files changed, 26 insertions, 1 deletions
diff --git a/remote.go b/remote.go
index 39da24e..89b3051 100644
--- a/remote.go
+++ b/remote.go
@@ -126,7 +126,7 @@ func (r *Remote) PushContext(ctx context.Context, o *PushOptions) (err error) {
if o.Force {
for i := 0; i < len(o.RefSpecs); i++ {
rs := &o.RefSpecs[i]
- if !rs.IsForceUpdate() {
+ if !rs.IsForceUpdate() && !rs.IsDelete() {
o.RefSpecs[i] = config.RefSpec("+" + rs.String())
}
}
diff --git a/remote_test.go b/remote_test.go
index ce46390..c6ea9ea 100644
--- a/remote_test.go
+++ b/remote_test.go
@@ -558,6 +558,31 @@ func (s *RemoteSuite) TestPushDeleteReference(c *C) {
c.Assert(err, Equals, plumbing.ErrReferenceNotFound)
}
+func (s *RemoteSuite) TestForcePushDeleteReference(c *C) {
+ fs := fixtures.Basic().One().DotGit()
+ sto := filesystem.NewStorage(fs, cache.NewObjectLRUDefault())
+
+ r, err := PlainClone(c.MkDir(), true, &CloneOptions{
+ URL: fs.Root(),
+ })
+ c.Assert(err, IsNil)
+
+ remote, err := r.Remote(DefaultRemoteName)
+ c.Assert(err, IsNil)
+
+ err = remote.Push(&PushOptions{
+ RefSpecs: []config.RefSpec{":refs/heads/branch"},
+ Force: true,
+ })
+ c.Assert(err, IsNil)
+
+ _, err = sto.Reference(plumbing.ReferenceName("refs/heads/branch"))
+ c.Assert(err, Equals, plumbing.ErrReferenceNotFound)
+
+ _, err = r.Storer.Reference(plumbing.ReferenceName("refs/heads/branch"))
+ c.Assert(err, Equals, plumbing.ErrReferenceNotFound)
+}
+
func (s *RemoteSuite) TestPushRejectNonFastForward(c *C) {
fs := fixtures.Basic().One().DotGit()
server := filesystem.NewStorage(fs, cache.NewObjectLRUDefault())