Skip to content

Accept raw remote URLs as valid - #1085

Closed
epriestley wants to merge 1 commit into
git-lfs:masterfrom
epriestley:invalid-remote-error
Closed

epriestley wants to merge 1 commit into
git-lfs:masterfrom
epriestley:invalid-remote-error

Conversation

@epriestley

Copy link
Copy Markdown

Fixes issue #1069, sort of, in theory. This is likely more of a starting point. Major issues:

  • No meaningful test coverage.
  • Pushing to a raw URL scans and tries to push every object in the repository.

Overview:

This treats any "ssh", "http", "https", "git" or protocol-free-with-a-colon-in-it remote name as a valid raw remote URL.

I'm not sure how to effectively test this, because it seems difficult to stub/simulate any of these protocols locally, and git-lfs won't work with file://, etc. Existing tests pass locally, and the existing test to verify that git-lfs push not-a-remote encounters an error passes (this is correctly detected as not being a valid remote).

I manually tested positive cases with, e.g.:

$ GIT_TRACE=1 git-lfs push [email protected]:epriestley/poems.git master
...
Git LFS: (1 of 7 files, 6 skipped) 11 B / 87.16 KB, 87.15 KB skipped    

One possible issue is that this causes this rev-list command to execute:

trace git-lfs: run_command: git rev-list --objects master --not [email protected]:epriestley/poems.git

git runs this, but it fails to exclude anything and lists every object in the repository.

A better strategy might be:

  • If the URL is raw, run git ls-remote <url> instead.
  • Pass the list of remote refs to --not instead of --remote <remote>.

I can pursue this refinement, but didn't want to get too far into things if I'm on the wrong track.

Fixes issue git-lfs#1069.

Currently, `git-lfs` operations only work on named remotes, but the equivalent
`git` operations accept raw remote URLs. Accept remote URLs in lieu of named
remotes if no named remote matches the argument.
@technoweenie technoweenie mentioned this pull request Mar 18, 2016
16 of 17 tasks
@epriestley

Copy link
Copy Markdown
Author

From #306, #295, etc., maybe I didn't dig deep enough into the test suite and http:// is already stubbed, which would be suitable here.

This issue is also probably adjacent to #295, at least, and maybe a few other things -- I can fish through issues and see what else I can dig up, this just seemed like the kind of thing that might be stepping into "major infrastructure change" territory so I didn't want to dig too deep if this going to snowball into more serious spelunking than I'm currently equipped to handle.

@technoweenie

Copy link
Copy Markdown
Contributor

Awesome. Definitely want some test coverage. The shell tests do setup a git server with an https endpoint that can be used. This should test both a remote that is named in git remote, and a remote that that isn't.

One possible issue is that this causes this rev-list command to execute:
$ git rev-list --objects master --not --remotes=[email protected]:epriestley/poems.git

I don't want to use git ls-remote for this, since that will hit the server. The --remotes option looks in the local ref from the remote in refs/remotes/*. LFS should only be scanning the range of commits from that ref to the current HEAD that it's going to be pushing. Using git ls-remote will hit the server, which could show a remote HEAD that is further ahead of the local repository.

What do you think about attempting to look up the remote name for a URL? If the URL has a remote name, continue passing --remotes. Otherwise, assume the repo has no local cache of that remote, and scan the entire history.

It may be worth creating a function that returns a git.RemoteList struct from:

$ git remote -v
dev http://github.dev/technoweenie/whatever.git (fetch)
dev http://github.dev/technoweenie/whatever.git (push)
origin  https://github.com/github/git-lfs (fetch)
origin  https://github.com/github/git-lfs (push)

Could even cache it in lfs.Configuration, to prevent potentially calling git remote multiple times in the same Git LFS process.

@epriestley

Copy link
Copy Markdown
Author

Cool, I'll see about getting proper coverage.

Using git ls-remote will hit the server, which could show a remote HEAD that is further ahead of the local repository.

It can't ever find any descendants of the current HEAD, can it (or if it somehow does, we don't need to push the file data)? The remote could be ahead chronologically, but it can't be ahead ahead unless something terrible happened and all bets are already off anyway (like someone pushed with lfs but skipped transmitting data), I think? But maybe I'm just misunderstanding or there's some scenario I'm not considering.

We (a code review tool called Phabricator) have an unusual situation where we sometimes push unreviewed code into a "staging area" remote which is mostly hidden from the user, identified only by URL, and never fetched, so the local repository will never know about most of the refs in it (and will know about none of the refs on the first push). This is unusual and you may not want to support it, but in our case there is never a named remote and the local repository will rarely have much information about refs present in the remote.

I'm not sure how common this is, although I'd imagine that if a push is using a raw URL, it's probably because there isn't a named local remote at least some of the time? But maybe there are situations where other tools pre-resolve the remote and drop the symbolic name for it, but it's still fundamentally origin or whatever.

@epriestley

Copy link
Copy Markdown
Author

For small repositories it's also believable that rev-list-ing everything and POSTing a little extra data is faster than eating an extra round trip with ls-remote, but that presumably breaks down by the time a repository reaches some realistic number of LFS objects.

@epriestley

Copy link
Copy Markdown
Author

Using git ls-remote will hit the server, which could show a remote HEAD that is further ahead of the local repository.

Oh, sorry, I misunderstood this at first until I read the message in f3bf4ea. The issue is not that a ref ahead of us is wrong, just that it's useless, since rev-list ... --not <ref we don't know the history of> is meaningless and git can't do anything with it.

I'm going to do a little more digging but don't have a better approach to suggest than the one you outline.

@epriestley

Copy link
Copy Markdown
Author

After some digging:

#144 has some discussion on the "what do we list to push" issue. I think that issue is actually resolved in master (since f3bf4ea)? @mhagger suggests the ls-remote approach there, with --ignore-missing.

#798, #278, and #295 are possibly adjacent. It looks like there may be some peril with host aliases if we try to guess which named remote corresponds to a URL, but that's fine. #693 is a vaguely related peril with insteadOf config. #864 is a copy of this, more or less. #754 looks like another one of the SSH host issues.

#431 and #436 have some cases with multiple remotes which LFS can't reasonably have perfect behavior on, which likely represent limits to how much we can possibly get right here. I think #580 is another copy of these. #930 is another one, although some users also reported the SSH aliases bug there. #1053 is approximately related.


So I think this is a maybe-reasonable way to break this down:

  • I'll cover this with tests and make rev-list fall back to a full list if it's interacting with a URL so we don't pass a nonsense --remote <url> argument. This should be strictly better than the behavior today ("don't work"), but not ideal.
  • Next, I'll try to guess which named remote a URL corresponds to so we can exclude refs with --not --remote <remote>. I think this will run into the insteadOf and "SSH Host Alias" issues, and I may be able to fix or mitigate them.
  • I'll keep an eye out on the origin stuff. I think it's better in modern code in master than some of those reports suggest and some of it fundamentally isn't tractable, but there may be opportunities to improve it.
  • When we still miss on finding local refs for the remote, I think the ls-remote + --ignore-missing --not <every ref> behavior from Does git media push need to be optimized for new branches? #144 is still better than nothing since it has a relatively small, relatively constant cost but potentially a big upside if even one ref isn't ahead of the local (and, selfishly, it will improve my bizarre case), but I can make a case for it later if I make it this far.

Comment thread git/git.go
}

switch u.Scheme {
case "ssh", "http", "https", "git":

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.

Will this honor pushInsteadOf ?

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.

Nope, but I think that'd be worthy of a separate pull request.

@technoweenie

Copy link
Copy Markdown
Contributor

Mockingbird is cool 👍

@technoweenie

Copy link
Copy Markdown
Contributor

Dang, what did I do??? The GitHub Platform team uses Marvel Comic characters in their media types. Since I'm a big comic nerd, they ping me on all new features to "approve" them. I approved one in this PR for some reason.

@technoweenie

Copy link
Copy Markdown
Contributor

I just commented here that I've moved this to the "nice to have" list for v1.2. However, I wouldn't mind shipping this mostly as-is, with more testing:

I'll cover this with tests and make rev-list fall back to a full list if it's interacting with a URL so we don't pass a nonsense --remote argument. This should be strictly better than the behavior today ("don't work"), but not ideal.

I personally agree with this notion:

I'm not sure how common this (hidden remotes) is, although I'd imagine that if a push is using a raw URL, it's probably because there isn't a named local remote at least some of the time?

Having a command that works, but attempts to upload too many objects seems preferable to it not working at all.

Comment thread lfs/config.go
return u
}

err := git.ValidateRemoteURL(remote)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could be usefull to convert err := git.ValidateRemoteURL in remote, err := git.NormalizeRemoteURL. If the user clones an url with a trailing /, es git clone https://github/repo.git/ the NewEndpointFromCloneURLWithConfig [1] adds an unwanted repo.git/.git/info/lfs layer to the Endpoint that should be repo.git/info/lfs

[1] lfs/endpoint.go#L41

@omonnier

Copy link
Copy Markdown

I'm currently working on integrating git-lfs into Gerrit repo tool, and I'm facing the same issue, because repo has an automatic fallback mechanism for ssh to https, in case the git push over ssh is failing. For that reason, repo is not using the remote name in the git push command, but the full url instead. I'm not sure to fully understand the plan for fixing that issue, but just wanted to let you know that it's preventing the integration of git-lfs into repo. I'm available for helping in writing some unit tests if needed.

@technoweenie technoweenie mentioned this pull request Aug 15, 2016
@technoweenie

Copy link
Copy Markdown
Contributor

I re-applied @epriestley's commit against master in #1451. I also added some basic tests for git lfs [fetch | pull | push] and applied @naufraghi's suggestion about handling remotes with trailing slashes.

@swisspol

swisspol commented Jan 19, 2018 •

Copy link
Copy Markdown
Contributor

@technoweenie Why did you close this PR? The issue it fixes is still not fixed: #1069.

@technoweenie

Copy link
Copy Markdown
Contributor

I closed it because the fix was applied in #1451. I confirmed that the issue is fixed just now too. Please open a new issue with details if you're still having problems.

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.

6 participants