Skip to content

Commit aecfc01

Browse files
author
Nate Smith
authored
Merge pull request cli#3809 from cli/fork-test-cleanup
fork tests cleanup
2 parents af90f72 + b099877 commit aecfc01

File tree

3 files changed

+425
-566
lines changed

3 files changed

+425
-566
lines changed

pkg/cmd/repo/fork/fork.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@ import (
2222
"github.com/spf13/pflag"
2323
)
2424

25+
const defaultRemoteName = "origin"
26+
2527
type ForkOptions struct {
2628
HttpClient func() (*http.Client, error)
2729
Config func() (config.Config, error)
2830
IO *iostreams.IOStreams
2931
BaseRepo func() (ghrepo.Interface, error)
3032
Remotes func() (context.Remotes, error)
33+
Since func(time.Time) time.Duration
3134

3235
GitArgs []string
3336
Repository string
@@ -40,9 +43,9 @@ type ForkOptions struct {
4043
Rename bool
4144
}
4245

43-
var Since = func(t time.Time) time.Duration {
44-
return time.Since(t)
45-
}
46+
// TODO warn about useless flags (--remote, --remote-name) when running from outside a repository
47+
// TODO output over STDOUT not STDERR
48+
// TODO remote-name has no effect on its own; error that or change behavior
4649

4750
func NewCmdFork(f *cmdutil.Factory, runF func(*ForkOptions) error) *cobra.Command {
4851
opts := &ForkOptions{
@@ -51,6 +54,7 @@ func NewCmdFork(f *cmdutil.Factory, runF func(*ForkOptions) error) *cobra.Comman
5154
Config: f.Config,
5255
BaseRepo: f.BaseRepo,
5356
Remotes: f.Remotes,
57+
Since: time.Since,
5458
}
5559

5660
cmd := &cobra.Command{
@@ -110,7 +114,7 @@ Additional 'git clone' flags can be passed in by listing them after '--'.`,
110114

111115
cmd.Flags().BoolVar(&opts.Clone, "clone", false, "Clone the fork {true|false}")
112116
cmd.Flags().BoolVar(&opts.Remote, "remote", false, "Add remote for fork {true|false}")
113-
cmd.Flags().StringVar(&opts.RemoteName, "remote-name", "origin", "Specify a name for a fork's new remote.")
117+
cmd.Flags().StringVar(&opts.RemoteName, "remote-name", defaultRemoteName, "Specify a name for a fork's new remote.")
114118
cmd.Flags().StringVar(&opts.Organization, "org", "", "Create the fork in an organization")
115119

116120
return cmd
@@ -182,7 +186,7 @@ func forkRun(opts *ForkOptions) error {
182186
// returns the fork repo data even if it already exists -- with no change in status code or
183187
// anything. We thus check the created time to see if the repo is brand new or not; if it's not,
184188
// we assume the fork already existed and report an error.
185-
createdAgo := Since(forkedRepo.CreatedAt)
189+
createdAgo := opts.Since(forkedRepo.CreatedAt)
186190
if createdAgo > time.Minute {
187191
if connectedToTerminal {
188192
fmt.Fprintf(stderr, "%s %s %s\n",

0 commit comments

Comments
 (0)