X Tutup
Skip to content

Respect clone target#727

Merged
mislav merged 4 commits intocli:masterfrom
thefotios:respect-clone-target
Apr 3, 2020
Merged

Respect clone target#727
mislav merged 4 commits intocli:masterfrom
thefotios:respect-clone-target

Conversation

@thefotios
Copy link
Copy Markdown
Contributor

Fixes #653

This allows a user to specify the target directory to clone to as part of the additional arguments.

It's not the prettiest implementation, but it works. It essentially parses the extra args to find any orphaned ones, Ideally we could somehow leverage git's actual command line arg parsing, maybe through something like this. But this is pretty much my first go code, so I wasn't really sure how to go about doing that.

Based on conversation in #721, this functionality was separated into it's own feature.

Copy link
Copy Markdown
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, this is amazing implementation and I like how you technically handled both flag parsing and tests 🏆

However, I would really really prefer if we did not involve any knowledge of git clone flags; i.e. if we avoided parsing those flags altogether. This is mostly for ease of maintenance and for forward-compatibility with future git.

How about we accept a 2nd argument to gh repo clone?

  • gh repo clone owner/repo → clones to repo
  • gh repo clone owner/repo dest → clones to dest
  • gh repo clone <repo> [<dir>] -- [<flags>...] → additional flags to git clone that do NOT include the destination

I think this would be a way simpler implementation, too.

@thefotios thefotios force-pushed the respect-clone-target branch from d079f13 to 59f239b Compare April 1, 2020 20:44
@thefotios
Copy link
Copy Markdown
Contributor Author

Ah, yea. The future compatibility is why I was thinking about using their parser, but your suggestion is 💯 better.

I left parseExtraArgs as a separate function for testability and in case there's ever another need to parse the args.

@thefotios
Copy link
Copy Markdown
Contributor Author

@mislav this is ready for re-review

Copy link
Copy Markdown
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! The approach looks solid to me ✨

command/repo.go Outdated
Long: `Clone a GitHub repository locally.

To pass 'git clone' options, separate them with '--'.`,
To pass 'git clone' options, separate them with '--'.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should say "flags" instead of "options" here, so that people don't think that all git clone options are accepted after the -- (<repo> and <directory> are not)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. The only options that git clone accepts are the repo and directory; everything else are flags. So this now has effectively the same function signature (except that flags have to come after the --).

Fixed in 199021d

command/repo.go Outdated
To pass 'git clone' options, separate them with '--'.`,
To pass 'git clone' options, separate them with '--'.

In order to clone to a specific directory, provide it before the '--' instead of after the other additional options.`,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm let's avoid adding this. It's technically true, but it makes help text harder to grok, and it should be obvious from the usage synopsis that <directory> should come before the --.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Fixed in 199021d

command/repo.go Outdated
RunE: repoView,
}

func parseExtraArgs(extraArgs []string) (args []string, target string) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this function has a generic-sounding name, but applies specifically to parsing clone arguments (it makes little sense otherwise). Since this function is shared across all command package, which is our biggest package, we could benefit from it having a more specific name, such as parseCloneArgs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right, go newb mistake ;) Fixed in 6428e3d

@thefotios
Copy link
Copy Markdown
Contributor Author

@mislav Thanks for the feedback; I made the requested changes if you want to resolve the conversations.

Copy link
Copy Markdown
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic! Thank you 🏆

@mislav mislav merged commit 43b28f7 into cli:master Apr 3, 2020
@jasonkarns
Copy link
Copy Markdown

👋 @thefotios there's a familiar face! 😸

@thefotios thefotios deleted the respect-clone-target branch September 1, 2020 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

repo clone should support cloning into a specific directory

3 participants

X Tutup