Skip to content

Add support for local paths#3918

Merged
bk2204 merged 1 commit intogit-lfs:masterfrom
bk2204:local-paths
Nov 15, 2019
Merged

Add support for local paths#3918
bk2204 merged 1 commit intogit-lfs:masterfrom
bk2204:local-paths

Conversation

@bk2204
Copy link
Member

@bk2204 bk2204 commented Nov 13, 2019

Currently, we only support local remotes using file URLs, but not local paths. This is a highly requested feature, however, so implement support for local paths as remotes.

First, fix the handling of local paths we already have: the handling of absolute Unix-style paths. Instead of checking for the remote to contain a file URL to determine whether to append "info/lfs" to the URL, look to see if the URL we're using is a file URL, which will catch local paths which will have been rewritten as such by this point.

If we get something that looks like it's not a URL, check if it's a file on the file system, and if so, don't attempt to interpret it as an SSH URL. This fixes the confusion with Windows paths, which resemble SSH-style locations with a single-letter alias as the host name.

Finally, when turning a local path into a file URL, turn the path into an absolute one if possible and rewrite it using slashes, which is required for file URLs. Add several tests for the various cases: one for Unix-style paths, one for native paths, and one for relative paths.

Fixes #3914.

@bk2204 bk2204 force-pushed the local-paths branch 3 times, most recently from aa9073c to 7097e2c Compare November 14, 2019 15:57
@bk2204 bk2204 requested a review from a team November 14, 2019 16:45
@bk2204 bk2204 marked this pull request as ready for review November 14, 2019 16:45
Currently, we only support local remotes using file URLs, but not local
paths.  This is a highly requested feature, however, so implement
support for local paths as remotes.

First, fix the handling of local paths we already have: the handling of
absolute Unix-style paths.  Instead of checking for the remote to
contain a file URL to determine whether to append "info/lfs" to the URL,
look to see if the URL we're using is a file URL, which will catch local
paths which will have been rewritten as such by this point.  The
"info/lfs" part of the URL is not handled by the transfer adapter, so we
don't want to add it on.

If we get something that looks like it's not a URL, check if it's a
file on the file system, and if so, don't attempt to interpret it as an
SSH URL.  This fixes the confusion with Windows paths, which resemble
SSH-style locations with a single-letter alias as the host name.

Finally, when turning a local path into a file URL, turn the path into
an absolute one if possible and rewrite it using slashes, which is
required for file URLs.  Add several tests for the various cases: one
for Unix-style paths, one for native paths, and one for relative paths.
Copy link
Member

@chrisd8088 chrisd8088 left a comment

Choose a reason for hiding this comment

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

Nice work! Thank you for tackling this oft-requested feature!

While it's a bit unfortunate that the logic in NewEndpoint() has to cover so many cases (literally, case blocks) as well as variations within those, I don't see any alternatives, given the range of possible inputs. Since this clearly improves the handling of relative local paths, it all looks good ... thank you!

@bk2204
Copy link
Member Author

bk2204 commented Nov 15, 2019

Yeah, I'd hope that we could have a more generic approach in the future, but for now, it's kind of a bear. The code is necessarily complicated by the fact that some Windows paths looks like SSH remotes; that's been the inconvenient issue preventing us from making progress on this before.

@bk2204 bk2204 merged commit 5fcef1b into git-lfs:master Nov 15, 2019
@bk2204 bk2204 deleted the local-paths branch November 15, 2019 18:53
chrisd8088 added a commit to chrisd8088/git-lfs that referenced this pull request Oct 16, 2023
Our Server Discovery documentation describes how we form Git LFS
server API endpoint URLs based on Git remotes and other Git and Git LFS
configurations.  This documentation was introduced in commit
21e1695 of PR git-lfs#1641 and has only
been lightly modified since then.

As discusssed in issue git-lfs#5528, we append "/info/lfs" to Git remote URLs,
but only after rewriting those URLs according to any "url.{name}.insteadOf"
configurations, which is somewhat counter to what is implied by Git's
own documentation of these settings.  We may change this behaviour
in a future Git LFS major release.  For the present, though, we simply
add a fuller description of how we convert Git remote URLs into Git LFS
API server URLs to our documentation, specifically touching on the
sequence in which we rewrite, convert, and append the "/info/lfs"
path segments to the remote URLs.

In PR git-lfs#3748 we added support for Git LFS endpoints defined by "file://"
URLs, and in PR git-lfs#3918 we enhanced this by also accepting local file paths
in remote URLs, so we also include comments on how we handle these
cases in our new documentation.

Further, although support for distinct URLs used only for upload operations
has existed since PR git-lfs#949, it is not mentioned in our Server Discovery
documentation, so we add notes on this feature now as well.

4469 - default remotes (lfsdefault, lfspushdefault)
5066 - autodetect, searchall
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.

git local clone failed

2 participants