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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…