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
}
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 dedicatedErrNonFastForwardUpdate
error which should be used instead.The main issue is that these two bits of code work differently: