Eclipse Git keyword expansion

馋奶兔 提交于 2019-12-06 06:02:38

问题


I need to to update my source code revision keywords (@version, @date, etc) every time I am checking out the source to the git-hub server.

As you might know:

The main problem with this in Git is that you can’t modify a file with information about the commit after you’ve committed, because Git checksums the file first.

Basically what I want to achieve is that my source code should look like below:

 * Git revision information:
 * 
 * @version $Revision: 1e7f611039399b32e9000ec454609a0641dde368 $
 * @author  $Author: Eugen Mihailescu <eugenmihailescux@gmail.com> $
 * @date    $Date:   Thu May 3 01:17:45 2012 +0200 $
 * 
 * $Id:  | Thu May 3 01:17:45 2012 +0200 | Eugen Mihailescu  $

Here and here you can find a full description of how you can achieve this in Git.

It turns out that you can write your own filters for doing substitutions in files on commit/checkout. These are the “clean” and “smudge” filters. In the .gitattributes file, you can set a filter for particular paths and then set up scripts that will process files just before they’re checked out (“smudge”, see Figure 7-2) and just before they’re committed.

So I know how to do it with git command. I've tested, it just works! My real issue is that I would like to achieve same thing by using Eclipse IDE. In Eclipse I have Eclipse Git, which is an Eclipse Team provider based on JGit, a pure Java implementation of the Git version control system.

In Eclipse EGit there is no such command "git checkout" but one could accomplish that by a hard reset (right-click your project then choose Team -> Reset -> Hard). Unfortunately this will not run your clean/smudge filters, in fact you will get the plain copy of your sources from the git hub without no keyword expansion.

I hope that I have described in detail the whole story because now I will ask:

  • is this possible in Eclipse using the EGit?

回答1:


This commit (August 2010) commented

Perform automatic CRLF to LF conversion during WorkingTreeIterator

WorkingTreeIterator now optionally performs CRLF to LF conversion for text files.
A basic framework is left in place to support enabling (or disabling) this feature based on gitattributes, and also to support the more generic smudge/clean filter system.
As there is no gitattribute support yet in JGit this is left unimplemented, but the mightNeedCleaning(), isBinary() and filterClean() methods will provide reasonable places to plug that into in the future.

I don't think gitattribute is fully supported in the latest JGit releases, and the latest revision of WorkingTreeIterator has still an empty filterClean() function.

So using JGit alone might not be enough to trigger your "filter content" driver.



来源:https://stackoverflow.com/questions/10426402/eclipse-git-keyword-expansion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!