I have been reading this post to git checkout by a specific date. I have been able to obtain the revision commit SHA code to the specific commit that I am targeting for the checkout, but when I am trying to actually run the git checkout command line I got the error:
error: pathspec 'de957d59f5ebef20f34155456b8ab46f127dc345 ' did not match any file(s) known to git.
Not sure what that means. I am running this command from ant 1.94 on my windows 7 machine
The ant command script looks as follow:
<target name="git.revlist" description="Revision list of repo for a particular timeframe" >
<exec executable="git" dir="${run.repo.dir}" failifexecutionfails="true" output="${output_commit_sha_file}" >
<arg line="rev-list -n 1 --before=${snapshot_before_date} ${repo_branch}"/>
</exec>
<loadfile property="output_commit_sha" srcfile="${output_commit_sha_file}" />
<exec executable="git" dir="${run.repo.dir}" failifexecutionfails="true" >
<arg line="checkout ${output_commit_sha}"/>
</exec>
</target>
Where the first execution actually retrieve the SHA (de957d59f5ebef20f34155456b8ab46f127dc345) code successfully, but when trying to use that for the second execution tasks command arguments, it throughs the above error.
Any ideas/recommendations on what I am missing here. Like I mentioned, I do have several task command lines that look like this and are used to perform other tasks, like git clone
and git log
, but this one seems to be missing something crucial.
Thanks in advance
In the error message, I noticed a space before the end quote:
I believe the
output
attribute of<exec>
inserts a newline at the end of the output file.<loadfile>
later converts the newline into a space.To avoid dealing with the space, consider saving the results of
git rev-list
to an Ant property by usingoutputproperty
instead ofoutput
:The above version is nice because it avoids having to create a file that stores the results of
git rev-list
. It also removes a call to<loadfile>
.By the way, you may want to use
failonerror="true"
instead offailifexecutionfails="true"
.failifexecutionfails
istrue
by default, so that can be omitted.failonerror
, however, isfalse
by default. Addingfailonerror="true"
to<exec>
is usually a good thing to do.