threads / discuss / 30328

Is there a way to fetch commits that are detached

Subject: Is there a way to fetch commits that are detached

## tl;dr

2 messages between Apr 24, 2012 and Apr 24, 2012.

replies: 1people: 2as markdown or json

Allan Caffee· Apr 24, 2012, 21:49 UTC · lore

First some context: I'm trying to use the pre-receive hook to run some tests on a Hudson server before accepting the updates to a branch. At the moment I'm trying to have the Hudson job clone the repository (using the "git" protocol) and checkout the new ref as a detached head e.g.

$ git clone $GIT_REPOSITORY repository $ cd repository $ git checkout $GIT_COMMIT

But the checkout fails, apparently because the commit object hasn't been pulled into the local repository. Only a pack file is present in the local repository's objects directory which presumably doesn't have the commit.

Is there a way to explicitly fetch whatever objects are necessary to checkout the commit?

Would I be better off using git-archive to tar up a copy of the source instead, or some other means of copying the codebase over for testing?

Thanks, Allan

Junio C Hamano· Apr 24, 2012, 22:15 UTC · re: Allan Caffee · lore

Re: Is there a way to fetch commits that are detached

Allan Caffee <allan.caffee@gmail.com> writes:
> Is there a way to explicitly fetch whatever objects are necessary to checkout
> the commit?

One security principle built into git is that any object that is unreachable from refs/* is not to be exposed to outside world. If the commit is not on any ref, you shouldn't be able to obtain it remotely.

So you need to know which branch (or it could be a tag) the commit you want is on, fetch that branch or tag and then check the commit out.

← back to recent threads