src-d / go-git

Project has been moved to: https://github.com/go-git/go-git
https://github.com/go-git/go-git
Apache License 2.0
4.91k stars 542 forks source link

Don't include git reference in remote.PushContext #1304

Open carsonoid opened 4 years ago

carsonoid commented 4 years ago

Right now, non fast-forward errors during remote pushes create a new error which includes the git reference :https://github.com/src-d/go-git/blob/d6c4b113c17a011530e93f179b7ac27eb3f17b9b/remote.go#L793 worktree.go has a dedicated ErrNonFastForwardUpdate error which should be used instead.

The main issue is that these two bits of code work differently:

err := w.PullContext(ctx, options) // might return a git.ErrNonFastForwardUpdate
if err != nil && err == git.ErrNonFastForwardUpdate { 
  // this code might get  executed
}

err := r.PushContext(ctx, options) // might return result of fmt.Errorf("non-fast-forward update: %s", cmd.Name.String())
if err != nil && err == git.ErrNonFastForwardUpdate { 
  // this code can never get executed
}