zwol
zwol

Reputation: 140609

Test whether a <repository> is acceptable to `git clone` without actually cloning it

Given an arbitrary string that might or might not be acceptable to git clone as its <repository> argument, is there a way (presumably using low-level "plumbing" commands) to determine whether this string could be cloned, without actually doing the clone?

Specifically, I want to reject strings that git clone cannot parse as a <repository>, or that would require use of a "remote helper" that is not installed, but I do not want to do any actual network communication at this stage of the process. (Therefore, strings that would fail to clone because the remote repository does not exist or isn't willing to communicate with me should be accepted.)

Upvotes: 1

Views: 419

Answers (2)

bk2204
bk2204

Reputation: 76509

As LeGEC mentioned, it's possible to test this with network connectivity, using git ls-remote, but if you don't want to perform a network operation, there's no way to do this. That's because Git can invoke helpers for various kinds of remotes, including HTTPS, and it won't invoke those helpers unless an actual network operation is occurring.

You could try looking for the remote helper with which or command -v (the latter is POSIX; the former is not), but that won't help if it's actually located in $GIT_EXEC_PATH. Otherwise, you'll have to do the parsing yourself, which, as someone who's done this for Git LFS, I can tell you is not exactly trivial. The source code is your reference here.

Upvotes: 0

LeGEC
LeGEC

Reputation: 51850

There are other commands that can communicate with a remote, and check that the repository is valid, for example :

git ls-remote <url>

Upvotes: 1

Related Questions