-
Notifications
You must be signed in to change notification settings - Fork 8.7k
respect git_protocol setting #810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -127,7 +127,7 @@ func runClone(cloneURL string, args []string) (target string, err error) { | |
| func repoClone(cmd *cobra.Command, args []string) error { | ||
| cloneURL := args[0] | ||
| if !strings.Contains(cloneURL, ":") { | ||
| cloneURL = fmt.Sprintf("https://github.com/%s.git", cloneURL) | ||
| cloneURL = formatRemoteURL(cmd, cloneURL) | ||
| } | ||
|
|
||
| var repo ghrepo.Interface | ||
|
|
@@ -158,7 +158,7 @@ func repoClone(cmd *cobra.Command, args []string) error { | |
| } | ||
|
|
||
| if parentRepo != nil { | ||
| err := addUpstreamRemote(parentRepo, cloneDir) | ||
| err := addUpstreamRemote(cmd, parentRepo, cloneDir) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -167,9 +167,8 @@ func repoClone(cmd *cobra.Command, args []string) error { | |
| return nil | ||
| } | ||
|
|
||
| func addUpstreamRemote(parentRepo ghrepo.Interface, cloneDir string) error { | ||
| // TODO: support SSH remote URLs | ||
| upstreamURL := fmt.Sprintf("https://github.com/%s.git", ghrepo.FullName(parentRepo)) | ||
| func addUpstreamRemote(cmd *cobra.Command, parentRepo ghrepo.Interface, cloneDir string) error { | ||
| upstreamURL := formatRemoteURL(cmd, ghrepo.FullName(parentRepo)) | ||
|
|
||
| cloneCmd := git.GitCommand("-C", cloneDir, "remote", "add", "-f", "upstream", upstreamURL) | ||
| cloneCmd.Stdout = os.Stdout | ||
|
|
@@ -267,14 +266,10 @@ func repoCreate(cmd *cobra.Command, args []string) error { | |
| fmt.Fprintln(out, repo.URL) | ||
| } | ||
|
|
||
| remoteURL := repo.URL + ".git" | ||
| remoteURL := formatRemoteURL(cmd, ghrepo.FullName(repo)) | ||
|
|
||
| if projectDirErr == nil { | ||
| // TODO: use git.AddRemote | ||
| remoteAdd := git.GitCommand("remote", "add", "origin", remoteURL) | ||
| remoteAdd.Stdout = os.Stdout | ||
| remoteAdd.Stderr = os.Stderr | ||
| err = run.PrepareCmd(remoteAdd).Run() | ||
| _, err = git.AddRemote("origin", remoteURL) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍👍this is easier to understand now |
||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -338,15 +333,15 @@ func repoFork(cmd *cobra.Command, args []string) error { | |
| return fmt.Errorf("unable to create client: %w", err) | ||
| } | ||
|
|
||
| var toFork ghrepo.Interface | ||
| var repoToFork ghrepo.Interface | ||
| inParent := false // whether or not we're forking the repo we're currently "in" | ||
| if len(args) == 0 { | ||
| baseRepo, err := determineBaseRepo(cmd, ctx) | ||
| if err != nil { | ||
| return fmt.Errorf("unable to determine base repository: %w", err) | ||
| } | ||
| inParent = true | ||
| toFork = baseRepo | ||
| repoToFork = baseRepo | ||
| } else { | ||
| repoArg := args[0] | ||
|
|
||
|
|
@@ -356,14 +351,23 @@ func repoFork(cmd *cobra.Command, args []string) error { | |
| return fmt.Errorf("did not understand argument: %w", err) | ||
| } | ||
|
|
||
| toFork, err = ghrepo.FromURL(parsedURL) | ||
| repoToFork, err = ghrepo.FromURL(parsedURL) | ||
| if err != nil { | ||
| return fmt.Errorf("did not understand argument: %w", err) | ||
| } | ||
|
|
||
| } else if strings.HasPrefix(repoArg, "git@") { | ||
| parsedURL, err := git.ParseURL(repoArg) | ||
| if err != nil { | ||
| return fmt.Errorf("did not understand argument: %w", err) | ||
| } | ||
| repoToFork, err = ghrepo.FromURL(parsedURL) | ||
| if err != nil { | ||
| return fmt.Errorf("did not understand argument: %w", err) | ||
| } | ||
| } else { | ||
| toFork = ghrepo.FromFullName(repoArg) | ||
| if toFork.RepoName() == "" || toFork.RepoOwner() == "" { | ||
| repoToFork = ghrepo.FromFullName(repoArg) | ||
| if repoToFork.RepoName() == "" || repoToFork.RepoOwner() == "" { | ||
| return fmt.Errorf("could not parse owner or repo name from %s", repoArg) | ||
| } | ||
| } | ||
|
|
@@ -372,12 +376,12 @@ func repoFork(cmd *cobra.Command, args []string) error { | |
| greenCheck := utils.Green("✓") | ||
| out := colorableOut(cmd) | ||
| s := utils.Spinner(out) | ||
| loading := utils.Gray("Forking ") + utils.Bold(utils.Gray(ghrepo.FullName(toFork))) + utils.Gray("...") | ||
| loading := utils.Gray("Forking ") + utils.Bold(utils.Gray(ghrepo.FullName(repoToFork))) + utils.Gray("...") | ||
| s.Suffix = " " + loading | ||
| s.FinalMSG = utils.Gray(fmt.Sprintf("- %s\n", loading)) | ||
| s.Start() | ||
|
|
||
| forkedRepo, err := api.ForkRepo(apiClient, toFork) | ||
| forkedRepo, err := api.ForkRepo(apiClient, repoToFork) | ||
| if err != nil { | ||
| s.Stop() | ||
| return fmt.Errorf("failed to fork: %w", err) | ||
|
|
@@ -437,7 +441,9 @@ func repoFork(cmd *cobra.Command, args []string) error { | |
| fmt.Fprintf(out, "%s Renamed %s remote to %s\n", greenCheck, utils.Bold(remoteName), utils.Bold(renameTarget)) | ||
| } | ||
|
|
||
| _, err = git.AddRemote(remoteName, forkedRepo.CloneURL) | ||
| forkedRepoCloneURL := formatRemoteURL(cmd, ghrepo.FullName(forkedRepo)) | ||
|
|
||
| _, err = git.AddRemote(remoteName, forkedRepoCloneURL) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to add remote: %w", err) | ||
| } | ||
|
|
@@ -458,7 +464,7 @@ func repoFork(cmd *cobra.Command, args []string) error { | |
| return fmt.Errorf("failed to clone fork: %w", err) | ||
| } | ||
|
|
||
| err = addUpstreamRemote(toFork, cloneDir) | ||
| err = addUpstreamRemote(cmd, repoToFork, cloneDir) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 this is nice