Git: get specific revision from remote server

I am setting up a test architecture. On this system, the virtual machine must check a specific code revision. The VM is completely clean and has no local (upgradeable) version of the repo. The code is hosted locally on the git server, on top of ssh with the username git. I have complete control over both cars.

A simple solution:

git clone --no-checkout git@gitserver:reponame.git
git checkout 8e8fdea8f8367f4a179d2faddbaadba495d6bc12

      

It works, but it does too much: it transmits the whole story over the network, which I want to avoid, if at all possible.

It seems to me, from the documentation, that the git clone

parameter can take --branch

, but that prevents me from specifying a specific revision. If it were, this combined with --depth 1

would work for me.

An alternative is to use git archive --remote

. I understand the security implications of allowing arbitrary changes to be received, and this is not an issue in this case, so I am running

git config --global --bool --add uploadArchive.allowUnreachable 1

      

on the git server as a git user.

Now in the git user shell I can do

git archive --format tar.gz --remote reponame.git 8e8fdea8f8367f4a179d2faddbaadba495d6bc12

      

Also, from my virtual machine, I can run

git archive --format tar.gz --remote git@gitserver:reponame.git master

      

However does not work:

git archive --format tar.gz --remote git@gitserver:reponame.git 8e8fdea8f8367f4a179d2faddbaadba495d6bc12

remote: fatal: no such ref: 8e8fdea8f8367f4a179d2faddbaadba495d6bc12
remote: git upload-archive: archiver died with error
fatal: sent error to the client: git upload-archive: archiver died with error

      

And yes, I'm pointing to the same repo that the revision is definitely in the repo, it just won't work with the revision number. One thing that might be the case is that if commands are executed via ssh, the file ~/.gitconfig

is not readable by default, although I could not find any information on this.

I am currently using bash as a shell for the git user. It will work in the future with a limited shell, but to show the underlying problem, I wanted to use a regular shell.

I am interested in both general comments on how I should get one revision of a clean machine, as well as a solution to the specific problem of not being able to use a git archive with a revision.


EDIT: torek gave me some versioning ideas (I'm running OSX, with stock git 1.8.5.2 and 2.0.1 installed via brew) and I did a little script wrapper around to git-upload-archive

figure out what's going on. Wrapper script:

/usr/local/bin/git --version > /tmp/version
tee /tmp/stdin | /usr/local/bin/git-upload-archive "$1" | tee /tmp/stdout

      

and calling the git archive with a parameter --exec

to run that script.

The introduced version is 2.0.1. However the same problem persists ... Since locally I can call git -archive with -remote and sha1 iff uploadarchive.allowunreachable

, remotely I cannot. Interestingly, request (c /tmp/stdin

) is exactly the same in both cases, the answer is different. As far as I can see, this is because git -upload-archive does not pick up the correct configuration when run over ssh; this can be shown using the local config in the repo, in which case it works (my point in the comments that it didn't work was because I was actually building /usr/bin/git-upload-archive

; an older version that doesn't allow this config flag).

The problem can be solved by calling /usr/local/bin/git upload-archive

instead /usr/local/bin/git-upload-archive

. It can even be provided as an argument to git -archive: --exec='/usr/local/bin/git-upload-archive'

doesn't work, --exec='/usr/local/bin/git upload-archive'

does.

So the problem works. I would still be interested (from an academic point of view) in why git -upload-archive does not pick up the config. Perhaps this is a bug that should be reported in the git project.

+3


source to share


1 answer


Just in case someone runs into this problem: 90% of the answer is defined in the question under the EDIT part. The last 10% is probably not worth diving. The important points I repeat here:



  • Take care that on OSX Mevericks the default GIT version is <2.0 and therefore does not support the tag uploadarchive.allowunreachable

    . When accessing GIT via SSH, it may choose a different version depending on whether you are starting an interactive SSH session or not (your path may be different).
  • git-upload-archive

    does not check the flag uploadarchive.allowunreachable

    in the global GIT config. This seems to be a bug in the GIT. The solution is not to use git-upload-archive

    but git upload-archive

    (i.e. Use a GIT script, with download-archive as the first argument). One way to do this is by sending --exec='/usr/local/bin/git upload-archive'

    a call git archive

    .
+1


source







All Articles