Search code examples
gitbuildcontinuous-integrationsource-server

Source Indexing with Git


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?


Solution

  • 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.