8

My local git repository is inside encrypted volume. I would like to be able to run git pull --all only when the remote has new commits. However, I'm unable to use post-receive hook like here since I don't have the password to the encrypted volume. This means that even if the hook will be triggered I still don't know the password to mount the volume and to pull the new changes. So I'm looking for some other alternatives, one possible way I was thinking of was to ask the remote for the latest version SHA and compare it with the latest version SHA that the local copy knows, if they match I don't need to run pull command and if they don't match then I need to run the git pull command.

Is there a way I can run git rev-parse master on the remote repository?

You can get more background about my problem here

Community
  • 1
  • 1
e271p314
  • 3,841
  • 7
  • 36
  • 61

2 Answers2

3

You can't do that literally.

There are two easy approximations:

  • If you can use ssh (or some other accessor) on the remote, you can run git rev-parse and even git rev-list over there, which gets you as many SHA-1s as you want.
  • You can use git ls-remote to get the head SHA-1s from the remote (including refs/heads/master). All that will tell you is "same" or "different", assuming you have the head SHA-1s locally. If they are different, you can't tell precisely why (though you can get probably-enough if you walk the local revs).

There's something weird about the question, though: you say the local repo is in an encrypted volume to which you do not have the password. If that's so, how do you know what the local heads are, and/or their history? They're recorded inside the repo.

torek
  • 448,244
  • 59
  • 642
  • 775
  • Thanks a lot for answering my question. `git ls-remote` was the command I was looking for. Comparing the output of `git ls-remote` and `git rev-parse master` will tell me if my local repo is updated or not. As for your question you might want to take a look [here](http://stackoverflow.com/questions/19374975/how-to-make-my-local-git-copy-always-at-its-latest-version-automatically). I don't know the password of the encrypted volumes, only the users know the password. So they give it too me and then I can mount the volumes (and run the git commands). – e271p314 Oct 15 '13 at 21:20
  • Ah, OK. Perhaps this does not apply in this situation, then: it's possible for the local repo to be *ahead of* the remote, so that fetch or pull on the remote has no effect; and it's possible for the two to diverge, so that fetch brings new stuff, but local and remote are still not in sync. For instance, suppose local and remote are in sync at (say) `badcafe`, and then someone does a `git commit` locally, creating rev `defaced`. The rev numbers won't match but there's nothing to `fetch`; only `push` can bring these into sync. – torek Oct 15 '13 at 21:24
  • This is not an issue in my case since no one is editing the files in the encrypted volumes. Once in a while users ask the system to compile a binary from various sources. Each source is a local git repo inside an encrypted volume. Most of the repos don't need to be update only few of them, instead of running `git pull --all` for every repo I can run a fast check using your suggestion and to run pull only for the repos which require update. Since nobody edits the files in the local repository I'm sure your solution will work great. Thanks again :-) – e271p314 Oct 15 '13 at 21:34
  • You can also check for a tag/branch/commit on a remote using `ls-remote` using something like `git ls-remote [url] [tag/branch/commit]`. This will output the commit ID/hash of the given tag, branch, or commit (or none, if it doesn't exist). – geerlingguy Jul 30 '14 at 16:01
  • `git ls-remote [url] [tag/branch/commit]` is what I am looking for. – mainframer Jan 18 '22 at 03:24
0

Is there a reason you don't want to pull? if it's because of the merge involved in pulling you can always issue git fetch to get the headers and keeping the working copy unchanged

  • 1
    Takes too long, take a look [here](http://stackoverflow.com/questions/19374975/how-to-make-my-local-git-copy-always-at-its-latest-version-automatically) to get the over all picture. – e271p314 Oct 15 '13 at 20:27