0

I am trying to start using source indexing alongside Git on our build server (TeamCity).

I download this project: SourceServer-GitExtensions

While running it i noticed warnings/errors. digging into the script (which is PERL based), i noticed the script runs this function:

sub GetSha1OfFirstCommand {
my $result = `git rev-list --reverse master`;
my @ids = split(/\n/, $result);
return($ids[0]);
}

This is run in an attempt to get the repository's id (id of the first commit i assume).

The problem is, we are currently not using the master branch.

My question is -- is this a proper and robust way of getting the "Repository Id" ? Can i run something else to get the "current branch that is checked out" and not master?

Paul R
  • 208,748
  • 37
  • 389
  • 560
lysergic-acid
  • 19,570
  • 21
  • 109
  • 218

2 Answers2

3

The minimal changes would be to run this instead:

git rev-list --reverse HEAD

This will give you the revision list for the current branch.

David Brigada
  • 594
  • 2
  • 10
  • This works for me on a bare repo, as long as `HEAD` in that repo points to the correct branch. – David Brigada Dec 16 '11 at 22:07
  • It just occurred to me, even if you're on a different branch, as long as you had the same initial commit, it doesn't matter what branch you check initially. If you had two roots, then it will change. – David Brigada Dec 16 '11 at 22:08
2

This trys to get the commit id of the first commit. git rev-list --reverse master and getting the first id, which is what the code you have given does, should work ( mostly) as all the git repos come with a master branch and the first commit is done on master and any branch would have branched off from that. Mostly because a branch can have it's own history (git checkout --orphan) or there may not be a master. In that case a more robust one would be git rev-list --reverse HEAD. This would work even on a bare repo.

manojlds
  • 290,304
  • 63
  • 469
  • 417