git-log error: ambiguous argument 'master'

1.9k views Asked by At

I'm running a maven build of a java project that is stored in a git repo. When the release plan runs on a build server (using Bamboo) it issues the following git command:

git log -n1 --date-order master

but recieves the following error:

fatal: ambiguous argument 'master': unknown revision or path not in the working tree.

I do, of course, have a master branch and when I pull down the repo and run the command locally it works fine. My guess is that there's different configuration on the build server but I'm at a loss for what to look for. I'm hoping one of you git experts will have some insight.

For reference, here is the actual error log I'm getting from the maven build. It occurs during the buildnumber-maven-plugin execution:

build   19-Aug-2015 15:10:28    [INFO] [INFO] --- buildnumber-maven-plugin:1.2:create (default) @ my-rest-project ---
build   19-Aug-2015 15:10:28    [INFO] [INFO] Verifying there are no local modifications ...
build   19-Aug-2015 15:10:28    [INFO] [INFO] Executing: /bin/sh -c cd /usr/local/atlassian/bamboo-home/xml-data/build-dir/MKL-RR-JOB1/target/checkout && git status --porcelain
build   19-Aug-2015 15:10:28    [INFO] [INFO] Working directory: /usr/local/atlassian/bamboo-home/xml-data/build-dir/MKL-RR-JOB1/target/checkout
build   19-Aug-2015 15:10:28    [INFO] [INFO] Executing: /bin/sh -c cd /usr/local/atlassian/bamboo-home/xml-data/build-dir/MKL-RR-JOB1/target/checkout && git log -n1 --date-order master
build   19-Aug-2015 15:10:28    [INFO] [INFO] Working directory: /usr/local/atlassian/bamboo-home/xml-data/build-dir/MKL-RR-JOB1/target/checkout
build   19-Aug-2015 15:10:28    [INFO] [ERROR] Provider message:
build   19-Aug-2015 15:10:28    [INFO] [ERROR] The git-log command failed.
build   19-Aug-2015 15:10:28    [INFO] [ERROR] Command output:
build   19-Aug-2015 15:10:28    [INFO] [ERROR] fatal: ambiguous argument 'master': unknown revision or path not in the working tree.
build   19-Aug-2015 15:10:28    [INFO] Use '--' to separate paths from revisions, like this:
build   19-Aug-2015 15:10:28    [INFO] 'git <command> [<revision>...] -- [<file>...]'
3

There are 3 answers

0
Planky On BEST ANSWER

It works when running the maven-release-plugin 2.2 and lower.

It turns out that there is some kind of conflict between the maven-release-plugin and the maven-buildnumber-plugin when the release plugin is between versions 2.3-2.5 (2.5 is the latest as of this writing).

I'm not sure what the cause of the error is exactly, but the logs show the release-plugin doing an extra git command in those versions and it somehow causes the buildnumber plugin which runs right after it to fail.

Specifically, it runs git ls-remote ssh://[email protected] and runs it in a temp directory rather than the directory that all the other git commands run in. I'm not sure if that's a Maven glitch or a Bamboo one. In any case, I know how to work around it now.

UPDATE: After running into another bamboo/maven-release/git issue that forced me to upgrade the maven-release-plugin to 2.5, I determined that the only way around all of this was to drop the buildnumber plugin. Ultimately it was the buildnumber plugin that was causing the issue and it wasn't important to my workflow after all.

1
manojlds On

The build server may just have the filed from your and not the git repository. This is a very common setting in many build servers, and you may want to check if this is the case.

Many build servers also provide option to have a repo checked out as well.

0
Gray On

fatal: ambiguous argument 'master': unknown revision or path not in the working tree.

This seems to be some git version issue where the git command (or package) running on our CI box was not compatible with the command generated by the buildnumer-maven-plugin. It worked for me locally on my Mac.

What fixed it on our CI box is to change the doUpdate to be false. We already had the doCheck setting as false so now our config looks like:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>buildnumber-maven-plugin</artifactId>
    ...
    <configuration>
        <doCheck>false</doCheck>
        <doUpdate>false</doUpdate>  <!-- changed this from true -->
    </configuration>
</plugin>

This causes the buildnumber-maven-plugin to issue the following git command which seems to be working fine everywhere:

[INFO] --- buildnumber-maven-plugin:1.4:create (default) @ parent ---
[INFO] Executing: /bin/sh -c cd '/build/parent' && 'git' 'rev-parse' '--verify' 'HEAD'