Ivan
Ivan

Reputation: 2320

Check remote repository for sha1

What is the most resource/network efficient command to check if the remote repository contains the <'sha1'>?

Is doing

git fetch
git branch -r --contains <sha1> | grep <branch>

the only way to perform this check?

There is also this option:

git ls-remote <repository URL><project> <refspec>

Is there a way to use this to perform the check in question? Would it be more efficient? If so, how?

Upvotes: 2

Views: 760

Answers (1)

JB.
JB.

Reputation: 42094

git ls-remote only gives you remote heads. So it's a start, but we're far from "any sha-1".

It seems like it's possible with git fetch, though it's obvious it wasn't written with that task in mind:

$ git fetch origin <sha1 that exists in remote>
From git.remote.org:path/to/repo
 * branch            28e9bb33a769d80f60a4c06a04b49179a34acc77 -> FETCH_HEAD
$ echo $?
0

$ git fetch origin <sha1 that doesn't exist in remote>
$ echo $?
1

Upvotes: 2

Related Questions