fix race condition, increase clarity

This commit is contained in:
nate smith 2022-01-25 15:36:41 -06:00
parent bd6e50a08a
commit 667671f048
2 changed files with 12 additions and 9 deletions

View file

@ -182,14 +182,6 @@ func forkRun(opts *ForkOptions) error {
return fmt.Errorf("failed to fork: %w", err)
}
// Rename the forked repo if ForkName is specified in opts.
if opts.ForkName != "" {
forkedRepo, err = api.RenameRepo(apiClient, forkedRepo, opts.ForkName)
if err != nil {
return err
}
}
// This is weird. There is not an efficient way to determine via the GitHub API whether or not a
// given user has forked a given repo. We noticed, also, that the create fork API endpoint just
// returns the fork repo data even if it already exists -- with no change in status code or
@ -211,6 +203,17 @@ func forkRun(opts *ForkOptions) error {
}
}
// Rename the forked repo if ForkName is specified in opts.
if opts.ForkName != "" {
forkedRepo, err = api.RenameRepo(apiClient, forkedRepo, opts.ForkName)
if err != nil {
return fmt.Errorf("could not rename fork: %w", err)
}
if connectedToTerminal {
fmt.Fprintf(stderr, "%s Renamed fork to %s\n", cs.SuccessIconWithColor(cs.Green), cs.Bold(ghrepo.FullName(forkedRepo)))
}
}
if (inParent && (!opts.Remote && !opts.PromptRemote)) || (!inParent && (!opts.Clone && !opts.PromptClone)) {
return nil
}

View file

@ -614,7 +614,7 @@ func TestRepoFork(t *testing.T) {
httpmock.REST("PATCH", "repos/OWNER/REPO"),
httpmock.StringResponse(renameResult))
},
wantErrOut: "✓ Created fork OWNER/NEW_REPO\n",
wantErrOut: "✓ Created fork OWNER/REPO\n✓ Renamed fork to OWNER/NEW_REPO\n",
},
}