Remove old code paths and improve code comments for `repo sync` by samcoe · Pull Request #7610 · cli/cli · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions pkg/cmd/repo/sync/http.go
12 changes: 10 additions & 2 deletions pkg/cmd/repo/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,13 @@ func executeLocalRepoSync(srcRepo ghrepo.Interface, remote string, opts *SyncOpt
return nil
}

// ExecuteRemoteRepoSync will take several steps to sync the source and destination repositories.
// First it will try to use the merge-upstream API endpoint. If this fails due to merge conflicts
// or unknown merge issues then it will fallback to using the low level git references API endpoint.
// The reason the fallback is necessary is to better support these error cases. The git references API
// endpoint allows us to sync repositories that are not fast-forward merge compatible. Additionally,
// the git references API endpoint gives more detailed error responses as to why the sync failed.
// Unless the --force flag is specified we will not perform non-fast-forward merges.
func executeRemoteRepoSync(client *api.Client, destRepo, srcRepo ghrepo.Interface, opts *SyncOptions) (string, error) {
branchName := opts.Branch
if branchName == "" {
Expand Down Expand Up @@ -317,8 +324,9 @@ func executeRemoteRepoSync(client *api.Client, destRepo, srcRepo ghrepo.Interfac
return "", err
}

// This is not a great way to detect the error returned by the API
// Unfortunately API returns 422 for multiple reasons
// Using string comparison is a brittle way to determine the error returned by the API
// endpoint but unfortunately the API returns 422 for many reasons so we must
// interpret the message provide better error messaging for our users.
err = syncFork(client, destRepo, branchName, commit.Object.SHA, opts.Force)
var httpErr api.HTTPError
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/repo/sync/sync_test.go