Skip to content

rewrite gh repo create#4578

Merged
mislav merged 58 commits intotrunkfrom
repo-create-rewrite
Nov 17, 2021
Merged

rewrite gh repo create#4578
mislav merged 58 commits intotrunkfrom
repo-create-rewrite

Conversation

@meiji163
Copy link
Contributor

@meiji163 meiji163 commented Oct 20, 2021

This PR rewrites gh repo create following #4567 to fix bugs, improve UX, and add requested features (Ref: #2184).

Fixes #2166, Fixes #893, Fixes #2059, Fixes #2077

Changes

Interactive mode is only for gh repo create with no arguments. Otherwise, all arguments must be passed explicitly.

The new command is backward compatible for scripting purposes except:

  • the new command will not clone the new repo locally by default. To do this, pass the --clone flag
  • the new command will not behave differently if the current directory is a git repository.
  • to create a new remote repo from an existing local repo, the source directory must be supplied with the --source flag

For example, running gh repo create myrepo --public in a local repository will no longer add a remote. It assumes you just want to create a new repository on GitHub. To create a remote repo from your local git repo, use gh repo create myrepo --public --source=. instead

Flags

The following flags are deprecated:

  • --enable-wiki, replaced by --disable-wiki
  • --enable-issues, replaced by --disable-issues
  • --confirm

There are additional new flags:

  • --source: specify the path to the local git repo
  • --remote: specify the remote name to add (used with --source)
  • --push: push local commits to the new repo (used with --source)

see #4567 for more info

Todo

@meiji163 meiji163 assigned meiji163 and pxrth9 and unassigned meiji163 Oct 20, 2021
@meiji163 meiji163 added enhancement a request to improve CLI tech-debt A chore that addresses technical debt labels Oct 20, 2021
@pxrth9 pxrth9 linked an issue Oct 20, 2021 that may be closed by this pull request
@pxrth9 pxrth9 requested review from pxrth9 and removed request for pxrth9 October 27, 2021 18:26
Copy link
Contributor

@vilmibm vilmibm left a comment

Choose a reason for hiding this comment

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

this is coming along very well~

Copy link
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.

Getting close! I've tested this locally and I love how easy and clear it is to use via explicit command line flags.

Copy link
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.

Looking great!

Some results from my QA testing:

  • gh repo create --source . --private --template a/b - I have expected this to error out, but the template flag seems to be ignored.

  • gh repo create myrepo --source /tmp --private - Since /tmp is not a git repo, this fails, but the error message is misleading: fatal: not a git repository (or any of the parent directories): .git. The error message does not ever mention that /tmp was an invalid git directory, but perhaps it should?

  • gh repo create myrepo --source . --push --private - My local git repo has no commits, so I have expected this to fail with a descriptive error message, but I get: error: src refspec HEAD does not match any. The remote repo was created and added as a git remote, but I don't think the git error message is descriptive enough for the average user to realize what went wrong. Furthermore, retrying the command (perhaps after creating a git commit) will fail because the remote repo already exists. Perhaps --push should fail early if there are no commits?

@meiji163
Copy link
Contributor Author

meiji163 commented Nov 16, 2021

  • gh repo create myrepo --source /tmp --private - Since /tmp is not a git repo, this fails, but the error message is misleading: fatal: not a git repository (or any of the parent directories): .git. The error message does not ever mention that /tmp was an invalid git directory, but perhaps it should?
  • gh repo create myrepo --source . --push --private - My local git repo has no commits, so I have expected this to fail with a descriptive error message, but I get: error: src refspec HEAD does not match any. The remote repo was created and added as a git remote, but I don't think the git error message is descriptive enough for the average user to realize what went wrong.

I made the errors more descriptive by catching the 128 exit code from git. Let me know if you see any bugs or if the code can be improved

The command will now fail immediately if --push is enabled when there are no commits. Also, the user will not be prompted to push in interactive mode if there are no commits.

@meiji163 meiji163 requested a review from mislav November 16, 2021 21:46
Copy link
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.

Updates look good! Thank you for the hard work 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement a request to improve CLI tech-debt A chore that addresses technical debt

Projects

None yet

4 participants