X Tutup
Skip to content

Commit 667671f

Browse files
author
nate smith
committed
fix race condition, increase clarity
1 parent bd6e50a commit 667671f

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

pkg/cmd/repo/fork/fork.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,6 @@ func forkRun(opts *ForkOptions) error {
182182
return fmt.Errorf("failed to fork: %w", err)
183183
}
184184

185-
// Rename the forked repo if ForkName is specified in opts.
186-
if opts.ForkName != "" {
187-
forkedRepo, err = api.RenameRepo(apiClient, forkedRepo, opts.ForkName)
188-
if err != nil {
189-
return err
190-
}
191-
}
192-
193185
// This is weird. There is not an efficient way to determine via the GitHub API whether or not a
194186
// given user has forked a given repo. We noticed, also, that the create fork API endpoint just
195187
// 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 {
211203
}
212204
}
213205

206+
// Rename the forked repo if ForkName is specified in opts.
207+
if opts.ForkName != "" {
208+
forkedRepo, err = api.RenameRepo(apiClient, forkedRepo, opts.ForkName)
209+
if err != nil {
210+
return fmt.Errorf("could not rename fork: %w", err)
211+
}
212+
if connectedToTerminal {
213+
fmt.Fprintf(stderr, "%s Renamed fork to %s\n", cs.SuccessIconWithColor(cs.Green), cs.Bold(ghrepo.FullName(forkedRepo)))
214+
}
215+
}
216+
214217
if (inParent && (!opts.Remote && !opts.PromptRemote)) || (!inParent && (!opts.Clone && !opts.PromptClone)) {
215218
return nil
216219
}

pkg/cmd/repo/fork/fork_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ func TestRepoFork(t *testing.T) {
614614
httpmock.REST("PATCH", "repos/OWNER/REPO"),
615615
httpmock.StringResponse(renameResult))
616616
},
617-
wantErrOut: "✓ Created fork OWNER/NEW_REPO\n",
617+
wantErrOut: "✓ Created fork OWNER/REPO\n✓ Renamed fork to OWNER/NEW_REPO\n",
618618
},
619619
}
620620

0 commit comments

Comments
 (0)
X Tutup