我编写了使用jgit的自定义ant任务。它应该使用本地存储库地址和目录地址,并将目录中的所有文件添加到索引中。它成功地构建了,但不幸的是,它无法工作。我对此完全陌生,所以我想知道你们中的一些人是否能帮我找到问题,或者我错过了什么。这是我的密码:
package customGitTasks;
import java.io.File;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.BuildException;
import org.eclipse.jgit.api.AddCommand;
import org.eclipse.jgit.api.Git;
public class GitAdd extends Task{
private String dir;
private String repository;
public void setRepository(String repository) {
this.repository = repository;
}
public void setDir(String dir) {
this.dir = dir;
}
public void execute() throws BuildException {
try {
Git git = Git.open(new File(repository));
AddCommand add = git.add();
add.addFilepattern(dir).call();
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
}
}谢谢
发布于 2014-07-18 12:20:19
JGit在其他git相关任务 (gitadd、gitcheckout、gitclone、gitinit)中提供了一个git添加ant任务。
要么使用该任务=> 把jarfile拿来,要么检查gitadd任务的来源以获得灵感。
Beware -在Windows 上运行时,需要修补git任务以使其工作:
// original line 149
//return new File(file).getCanonicalPath().substring(prefix.length() + 1);
String result = new File(file).getCanonicalPath().substring(prefix.length() + 1);
if (File.separatorChar != '/') {
result = result.replace(File.separatorChar, '/');
}
return result;意味着文件分配器必须是unix样式。
https://stackoverflow.com/questions/24824015
复制相似问题