Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've used the following ant details to retrieve the checked out branch's latest commit ID, what caveats should I be concerned about using this method?

Are there edge cases where I wouldn't retrieve the expected values?

<scriptdef name="substring" language="javascript">
    <attribute name="text" />
    <attribute name="start" />
    <attribute name="end" />
    <attribute name="property" />
    <![CDATA[
       var text = attributes.get("text");
       var start = attributes.get("start");
       var end = attributes.get("end") || (text.length() - 1);
       project.setProperty(attributes.get("property"), text.substring(start, end));
     ]]>
</scriptdef>

<loadfile property="head.branch" srcfile="${basedir}/.git/HEAD" />
<substring text="${head.branch}" start="5" property="branch" />
<loadfile property="head.commitId" srcfile="${basedir}/.git/${branch}"/>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
625 views
Welcome To Ask or Share your Answers For Others

1 Answer

you can read the contents of .git/HEAD, then read the contents of the file that you get from that.

The caveat that you will run into is that the SHA-1 that you get from the above steps may be in a pack file (the way git compresses multiple changes together to save space). I would recommend using git instead of trying to manipulate the .git folder contents yourself.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...