我怎样才能获得最新提交的混帐的当前签出分支ID,用ANT,不具有活性的git安装? [英] How can I get the latest commit ID of the currently checked out branch in git, using ANT, without having an active git installation?
问题描述
我用下面的蚂蚁详细信息检索,签出的分支的最新提交身份证,有什么注意事项我应该担心使用这种方法?
是否有优势情况下,我不会取得预期值?
< scriptdef NAME =串LANGUAGE =JavaScript的>
<属性名=TEXT/>
<属性名=开始/>
<属性名=结束/>
<属性名=属性/>
<![CDATA [
VAR文本= attributes.get(文字);
VAR开始= attributes.get(开始);
VAR结束= attributes.get(结束)|| (text.length() - 1);
project.setProperty(attributes.get(财产),text.substring(开始,结束));
]]>
< / scriptdef><财产的loadFile =head.branchSRCFILE =$ {BASEDIR} / git的/ HEAD/>
<子文本=$ {} head.branch开始=5的属性=分支/>
<财产的loadFile =head.commitIdSRCFILE =$ {BASEDIR} / git的/ $ {}分支/>
您可以阅读内容的.git / HEAD
,然后读取文件的内容,你从得到的。
这是你会遇到需要说明的是,SHA-1,你从上面的步骤,获取可能是在包文件(GIT的方式融为一体presses多次更改起来以节省空间)。我会建议使用git的,而不是试图自己操作git的文件夹内容。
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}"/>
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.
这篇关于我怎样才能获得最新提交的混帐的当前签出分支ID,用ANT,不具有活性的git安装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!