Skip to content
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

Allow cloning over https instead of ssh #149

Closed
wants to merge 1 commit into from

Conversation

llucax
Copy link
Member

@llucax llucax commented Nov 9, 2015

If I try git hub clone https://github.com/author/repo then git-hub unhelpfully changes that to git@github.com:author/repo. The entire reason I used an https URL is because I want to use it instead of ssh. In fact, I have to because ssh is blocked in this environment.

@llucax llucax added this to the Future milestone Sep 16, 2015
@llucax
Copy link
Member

llucax commented Sep 16, 2015

Labeled as both enhancement and bug because supporting URLs for git hub clone was a hack in the first place, it was never supposed to add support for https. So is an enhancement in that sense, but from the user perspective is clearly a bug.

It's probably not too hard to fix though.

@llucax llucax modified the milestones: v0.10, Future Sep 16, 2015
@llucax llucax self-assigned this Sep 16, 2015
@jwilk
Copy link
Contributor

jwilk commented Sep 17, 2015

As a data point, I like the current behavior.
If I run git hub clone https://github.com/foo/bar, it's because the full URL is the easiest thing to copy&paste, not because I enjoy HTTPS.
Please keep an option to always clone over SSH, regardless of what the URL says.

@jamessan
Copy link
Contributor Author

I'd be fine with a git-config option to indicate I want to use https. That should satisfy both Jakub's use case and mine.

@llucax
Copy link
Member

llucax commented Sep 17, 2015

James McCoy, el 17 de September a las 04:38 me escribiste:

I'd be fine with a git-config option to indicate I want to use https.
That should satisfy both Jakub's use case and mine.

Haha, but I think that's terribly counter-intuitive. Really, you type
clone https://... and get a SSH based clone, or vice-versa?

For me that's the worse case scenario... I would be willing to make it
like clone --force-ssh https://..., but then all the convenience of
copy&paste is gone, I guess.

I think is reasonable to ask the user to do one more click to copy the
SSH URL instead of the HTTPS one for the sake of an intuitive CLI.

@llucax
Copy link
Member

llucax commented Nov 9, 2015

Relabeling as bug-only, as other types of URLs are supported via the config option hub.urltype. Also removing the difficutly-easy tag as it wasn't so easy 😁

llucax pushed a commit to llucax/git-hub that referenced this pull request Nov 9, 2015
Some very half baked support to use full GitHub clone URLs was added to
clone at some point, but this support is insuficient. It completely
ignores the URL itself so it will always clone using the current
`hub.urltype` scheme (which defaults to `ssh_url` and is probably too
obscure to ask the user to manually change it).

This commit makes the clone command to parse the URLs more intelligently
and set the `hub.urltype` config option as appropriate (it seems more
reasonable to think the user will like to use that instead, not only for
the cloning but also for other future operations, like pushing).

Fixes sociomantic-tsunami#149.
llucax pushed a commit to llucax/git-hub that referenced this pull request Nov 9, 2015
Some very half baked support to use full GitHub clone URLs was added to
clone at some point, but this support is insuficient. It completely
ignores the URL itself so it will always clone using the current
`hub.urltype` scheme (which defaults to `ssh_url` and is probably too
obscure to ask the user to manually change it).

This commit makes the clone command to parse the URLs more intelligently
and set the `hub.urltype` config option as appropriate (it seems more
reasonable to think the user will like to use that instead, not only for
the cloning but also for other future operations, like pushing).

Fixes sociomantic-tsunami#149.
llucax pushed a commit to llucax/git-hub that referenced this pull request Nov 9, 2015
Some very half baked support to use full GitHub clone URLs was added to
clone at some point, but this support is insuficient. It completely
ignores the URL itself so it will always clone using the current
`hub.urltype` scheme (which defaults to `ssh_url` and is probably too
obscure to ask the user to manually change it).

This commit makes the clone command to parse the URLs more intelligently
and set the `hub.urltype` config option as appropriate (it seems more
reasonable to think the user will like to use that instead, not only for
the cloning but also for other future operations, like pushing).

Fixes sociomantic-tsunami#149.
@llucax
Copy link
Member

llucax commented Nov 9, 2015

Fix attached.

@gkotian sorry for kind of destroying what you did in #160. 👼

@andrej-mitrovic-sociomantic I made this PR using my master branch so I can test #136 fix 💃

@jwilk I didn't include a way to force a URL type in this PR, I consider that a different issue (an enhancement). I'd be OK to add something like --force-urltype to the clone command (which can use the current hub.urltype if no option is used or could accept an arbitrary URL type). I don't think I'll fix this myself though, because I think is a bit too niche and not generally useful.

@llucax
Copy link
Member

llucax commented Nov 9, 2015

BTW, also UNTESTED. Help testing this is very much appreciated.

llucax pushed a commit to llucax/git-hub that referenced this pull request Nov 9, 2015
Some very half baked support to use full GitHub clone URLs was added to
clone at some point, but this support is insuficient. It completely
ignores the URL itself so it will always clone using the current
`hub.urltype` scheme (which defaults to `ssh_url` and is probably too
obscure to ask the user to manually change it).

This commit makes the clone command to parse the URLs more intelligently
and set the `hub.urltype` config option as appropriate (it seems more
reasonable to think the user will like to use that instead, not only for
the cloning but also for other future operations, like pushing).

Fixes sociomantic-tsunami#149.
@llucax
Copy link
Member

llucax commented Nov 9, 2015

I'd like to test at least:

  • clone repo
  • clone owner/repo
  • clone user/repo (the same as clone repo but explicitly setting the owner to the current user to test Error on trivially incorrect usage of clone command #160)
  • clone https://github.com/owner/repo.git (HTTP)
  • clone https://github.com/owner/repo (SVN, should be ignored with a warning)
  • clone git@github.com:/owner/repo.git (SSH)
  • clone git:github.com/owner/repo.git (git, I'm not sure it will work, is only in the API)
  • Any random piece of garbage you can think of to see if the error messages make sense (or how badly it crashes :D)

@jwilk
Copy link
Contributor

jwilk commented Nov 11, 2015

Typo: the current the configthe current config

I would have never thought that https://github.com/owner/repo has anything to do with SVN. It works with git clone just fine. In fact, that's the exact URL format that @jamessan wanted to use with git hub clone.

I'm getting 404 when trying to clone my own repos, regardless of URL type:

$ git hub -v clone didjvu
git command: ['git', 'config', 'hub.username'] {'stderr': -1, 'stdout': -1}
git command: ['git', 'config', 'hub.oauthtoken'] {'stderr': -1, 'stdout': -1}
git command: ['git', 'config', 'hub.upstream'] {'stderr': -1, 'stdout': -1}
git command: ['git', 'config', 'hub.forkrepo'] {'stderr': -1, 'stdout': -1}
git command: ['git', 'config', 'hub.forkremote'] {'stderr': -1, 'stdout': -1}
git command: ['git', 'config', 'hub.pullbase'] {'stderr': -1, 'stdout': -1}
git command: ['git', 'config', 'hub.urltype'] {'stderr': -1, 'stdout': -1}
git command: ['git', 'config', 'hub.baseurl'] {'stderr': -1, 'stdout': -1}
git command: ['git', 'config', '--bool', 'hub.forcerebase'] {'stderr': -1, 'stdout': -1}
git command: ['git', 'config', '--bool', 'hub.triangular'] {'stderr': -1, 'stdout': -1}
git command: ['git', 'config', 'hub.password'] {'stderr': -1, 'stdout': -1}
Request: GET https://api.github.com/repos/jwilk/jwilk/didjvu?
None
https://api.github.com/repos/jwilk/jwilk/didjvu?
Content-length: 0
Content-type: application/json
Authorization: <hidden>
Accept: application/vnd.github.v3+json
None
Error: GitHub error: Not Found
HTTP Error 404: Not Found
https://api.github.com/repos/jwilk/jwilk/didjvu?
<httplib.HTTPMessage instance at 0xf6c4620c>

I don't see any point in command-line option for forcing URL type.
OTOH configuration option for forcing URL type would be useful; but it's not a big deal, I can live without it.

llucax pushed a commit to llucax/git-hub that referenced this pull request Nov 11, 2015
Some very half baked support to use full GitHub clone URLs was added to
clone at some point, but this support is insuficient. It completely
ignores the URL itself so it will always clone using the current
`hub.urltype` scheme (which defaults to `ssh_url` and is probably too
obscure to ask the user to manually change it).

This commit makes the clone command to parse the URLs more intelligently
and set the `hub.urltype` config option as appropriate (it seems more
reasonable to think the user will like to use that instead, not only for
the cloning but also for other future operations, like pushing).

Fixes sociomantic-tsunami#149.
@llucax
Copy link
Member

llucax commented Nov 11, 2015

Arrrgh! Hopefully fixed. Thanks for the testing!

About SVN, OK, then I can simplify even further the heuristics to select the correct url type. Much better (and no mention to SVN in a git subcommand :D).

diff --git a/git-hub b/git-hub
index dc7a19d..464c7be 100755
--- a/git-hub
+++ b/git-hub
@@ -792,18 +792,12 @@ class CloneCmd (object):
                urltype = config.urltype
                if repo.endswith('.git'):
                        repo = repo[:-4] # remove suffix
-                       if repo.startswith('https://'):
-                               urltype = 'clone_url' # how GitHub calls HTTP
-                       elif repo.startswith('git:'):
-                               urltype = 'git_url'
-                       elif ':' in repo:
-                               urltype = 'ssh_url'
-               elif repo.startswith('https://'): # and it doesn't end with .git
-                       warnf("{} looks like a SVN URL, which doesn't make a "
-                                       "lot of sense to use with git, we'll "
-                                       "use the current the config option "
-                                       "hub.urltype ({}) instead.",
-                                       repo, urltype)
+               if repo.startswith('https://'):
+                       urltype = 'clone_url' # how GitHub calls HTTP
+               elif repo.startswith('git:'):
+                       urltype = 'git_url'
+               elif ':' in repo:
+                       urltype = 'ssh_url'
                # At this point we need to have an urltype
                if urltype is None:
                        die("Can't infer a urltype and can't find the config "
@@ -821,7 +815,7 @@ class CloneCmd (object):
        def setup_repo(cls, proj):
                # Own repo
                if proj.split('/')[0] == config.username:
-                       repo = req.get('/repos/%s/%s' % (config.username, proj))
+                       repo = req.get('/repos/' + proj)
                        if repo['fork']:
                                upstream = repo['parent']['full_name']
                        else:

@leandro-lucarella-sociomantic
Copy link
Contributor

Some basic testing for own repos seems to work fine.

@jwilk
Copy link
Contributor

jwilk commented Nov 11, 2015

Now it looks good to me.

Some very half baked support to use full GitHub clone URLs was added to
clone at some point, but this support is insuficient. It completely
ignores the URL itself so it will always clone using the current
`hub.urltype` scheme (which defaults to `ssh_url` and is probably too
obscure to ask the user to manually change it).

This commit makes the clone command to parse the URLs more intelligently
and set the `hub.urltype` config option as appropriate (it seems more
reasonable to think the user will like to use that instead, not only for
the cloning but also for other future operations, like pushing).

Fixes sociomantic-tsunami#149.
@llucax
Copy link
Member

llucax commented Dec 1, 2015

Merge, please? Maybe?

@gautam-kotian-sociomantic
Copy link
Contributor

LGTM.

@leandro-lucarella-sociomantic
Copy link
Contributor

OK, auto-merging as it seems like @mihails-strasuns-sociomantic is taking a nap 😝

@llucax llucax closed this in a392421 Dec 1, 2015
@leandro-lucarella-sociomantic
Copy link
Contributor

This pull request has been rebased via git hub pull rebase. Original pull request HEAD was 4cc377d, new (rebased) HEAD is a392421

@leandro-lucarella-sociomantic
Copy link
Contributor

BTW, I rebased this using #136 and it worked fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants