(srcRepo ghrepo.Interface, remote string, opts *SyncOptions)
| 219 | var divergingError = errors.New("diverging changes") |
| 220 | |
| 221 | func executeLocalRepoSync(srcRepo ghrepo.Interface, remote string, opts *SyncOptions) error { |
| 222 | git := opts.Git |
| 223 | branch := opts.Branch |
| 224 | useForce := opts.Force |
| 225 | |
| 226 | hasLocalBranch := git.HasLocalBranch(branch) |
| 227 | if hasLocalBranch { |
| 228 | fastForward, err := git.IsAncestor(branch, "FETCH_HEAD") |
| 229 | if err != nil { |
| 230 | return err |
| 231 | } |
| 232 | if !fastForward && !useForce { |
| 233 | return divergingError |
| 234 | } |
| 235 | if fastForward && useForce { |
| 236 | useForce = false |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | currentBranch, err := git.CurrentBranch() |
| 241 | if err != nil && !errors.Is(err, gitpkg.ErrNotOnAnyBranch) { |
| 242 | return err |
| 243 | } |
| 244 | if currentBranch == branch { |
| 245 | if isDirty, err := git.IsDirty(); err == nil && isDirty { |
| 246 | return fmt.Errorf("refusing to sync due to uncommitted/untracked local changes\ntip: use `git stash --all` before retrying the sync and run `git stash pop` afterwards") |
| 247 | } else if err != nil { |
| 248 | return err |
| 249 | } |
| 250 | if useForce { |
| 251 | if err := git.ResetHard("FETCH_HEAD"); err != nil { |
| 252 | return err |
| 253 | } |
| 254 | } else { |
| 255 | if err := git.MergeFastForward("FETCH_HEAD"); err != nil { |
| 256 | return err |
| 257 | } |
| 258 | } |
| 259 | } else { |
| 260 | if hasLocalBranch { |
| 261 | if err := git.UpdateBranch(branch, "FETCH_HEAD"); err != nil { |
| 262 | return err |
| 263 | } |
| 264 | } else { |
| 265 | if err := git.CreateBranch(branch, "FETCH_HEAD", fmt.Sprintf("%s/%s", remote, branch)); err != nil { |
| 266 | return err |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | return nil |
| 272 | } |
| 273 | |
| 274 | // ExecuteRemoteRepoSync will take several steps to sync the source and destination repositories. |
| 275 | // First it will try to use the merge-upstream API endpoint. If this fails due to merge conflicts |
no test coverage detected