本文整理了Java中org.eclipse.jgit.api.Git.init()
方法的一些代码示例,展示了Git.init()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Git.init()
方法的具体详情如下:
包路径:org.eclipse.jgit.api.Git
类名称:Git
方法名:init
[英]Return a command object to execute a init command
[中]返回命令对象以执行init命令
代码示例来源:origin: jphp-group/jphp
@Signature
public void __construct(File directory, boolean create) throws IOException, GitAPIException {
try {
__wrappedObject = Git.open(directory, FS.DETECTED);
} catch (RepositoryNotFoundException e) {
if (create) {
Git.init().setBare(false).setDirectory(directory).call();
__wrappedObject = Git.open(directory, FS.DETECTED);
}
}
}
代码示例来源:origin: centic9/jgit-cookbook
private static File createRepository() throws IOException, GitAPIException {
File dir = File.createTempFile("gitinit", ".test");
if(!dir.delete()) {
throw new IOException("Could not delete temporary file " + dir);
}
Git.init()
.setDirectory(dir)
.call();
try (Repository repository = FileRepositoryBuilder.create(new File(dir.getAbsolutePath(), ".git"))) {
System.out.println("Created a new repository at " + repository.getDirectory());
}
return dir;
}
}
代码示例来源:origin: centic9/jgit-cookbook
public static void main(String[] args) throws IOException, IllegalStateException, GitAPIException {
// prepare a new folder
File localPath = File.createTempFile("TestGitRepository", "");
if(!localPath.delete()) {
throw new IOException("Could not delete temporary file " + localPath);
}
// create the directory
try (Git git = Git.init().setDirectory(localPath).call()) {
System.out.println("Having repository: " + git.getRepository().getDirectory());
}
// clean up here to not keep using more and more disk-space for these samples
FileUtils.deleteDirectory(localPath);
}
}
代码示例来源:origin: centic9/jgit-cookbook
private static File createRepository() throws IOException, GitAPIException {
File dir = File.createTempFile("gitinit", ".test");
if(!dir.delete()) {
throw new IOException("Could not delete temporary file " + dir);
}
Git.init()
.setDirectory(dir)
.call();
try (Repository repository = FileRepositoryBuilder.create(new File(dir.getAbsolutePath(), ".git"))) {
System.out.println("Created a new repository at " + repository.getDirectory());
}
return dir;
}
}
代码示例来源:origin: centic9/jgit-cookbook
public static void main(String[] args) throws IOException, IllegalStateException, GitAPIException {
// prepare a new folder
File localPath = File.createTempFile("TestGitRepository", "");
if(!localPath.delete()) {
throw new IOException("Could not delete temporary file " + localPath);
}
// create the directory
try (Git git = Git.init().setDirectory(localPath).call()) {
System.out.println("Having repository: " + git.getRepository().getDirectory());
}
// clean up here to not keep using more and more disk-space for these samples
FileUtils.deleteDirectory(localPath);
}
}
代码示例来源:origin: centic9/jgit-cookbook
try (Git git = Git.init()
.setDirectory(dir)
.call()) {
代码示例来源:origin: centic9/jgit-cookbook
try (Git git = Git.init()
.setDirectory(dir)
.call()) {
代码示例来源:origin: FlowCI/flow-platform
/**
* Init git repo with bare
*
* @param gitPath xxx.git folder
* @throws GitException
*/
public static void init(Path gitPath, boolean bare) throws GitException {
try {
if (bare) {
Git.init().setBare(bare).setGitDir(gitPath.toFile()).call();
} else {
Git.init().setDirectory(gitPath.toFile()).call();
}
} catch (GitAPIException e) {
throw new GitException(e.getMessage());
}
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
private Repository init() throws GitAPIException {
InitCommand command = Git.init();
command.setBare(bare);
if (fs != null) {
command.setFs(fs);
}
if (directory != null) {
command.setDirectory(directory);
}
if (gitDir != null) {
command.setGitDir(gitDir);
}
return command.call().getRepository();
}
代码示例来源:origin: FlowCI/flow-platform
/**
* Create local .git with remote info
*
* @return .git file path, /targetDir/.git
*/
private File initGit(Set<String> checkoutFiles) throws GitException {
try (Git git = Git.init().setDirectory(targetDir.toFile()).call()) {
Repository repository = git.getRepository();
File gitDir = repository.getDirectory();
setSparseCheckout(gitDir, checkoutFiles);
configRemote(repository.getConfig(), "origin", gitUrl);
return gitDir;
} catch (GitAPIException e) {
throw new GitException("Fail to init git repo at: " + targetDir, e);
}
}
代码示例来源:origin: io.fabric8/fabric-git
private Git openOrInit(File localRepo) throws IOException {
try {
return Git.open(localRepo);
} catch (RepositoryNotFoundException e) {
try {
return Git.init().setDirectory(localRepo).call();
} catch (GitAPIException ex) {
throw new IOException(ex);
}
}
}
代码示例来源:origin: com.madgag/org.eclipse.jgit.pgm
@Override
protected void run() throws Exception {
InitCommand command = Git.init();
command.setBare(bare);
if (gitdir != null)
command.setDirectory(new File(gitdir));
Repository repository = command.call().getRepository();
outw.println(MessageFormat.format(
CLIText.get().initializedEmptyGitRepositoryIn, repository
.getDirectory().getAbsolutePath()));
}
}
代码示例来源:origin: sheimi/SGit
public boolean init() {
try {
Git.init().setDirectory(mRepo.getDir()).call();
} catch (Throwable e) {
setException(e);
return false;
}
return true;
}
}
代码示例来源:origin: maks/MGit
public boolean init() {
try {
Git.init().setDirectory(mRepo.getDir()).call();
} catch (Throwable e) {
setException(e);
return false;
}
return true;
}
}
代码示例来源:origin: com.walmartlabs.concord.it/concord-common-it
public static String createGitRepo(File src) throws IOException, GitAPIException {
Path tmpDir = createTempDir();
IOUtils.copy(src.toPath(), tmpDir);
Git repo = Git.init().setDirectory(tmpDir.toFile()).call();
repo.add().addFilepattern(".").call();
repo.commit().setMessage("import").call();
return tmpDir.toAbsolutePath().toString();
}
代码示例来源:origin: cfg4j/cfg4j
private Git createLocalRepo(Path path) throws IOException, GitAPIException {
Files.delete(path);
return Git.init()
.setDirectory(path.toFile())
.call();
}
代码示例来源:origin: org.kie.commons/kie-nio2-jgit
public static Git newRepository( final File repoFolder,
final boolean bare ) throws IOException {
checkNotNull( "repoFolder", repoFolder );
try {
return Git.init().setBare( bare ).setDirectory( repoFolder ).call();
} catch ( GitAPIException e ) {
throw new IOException( e );
}
}
代码示例来源:origin: org.uberfire/vfs-jgit
public static Git newRepository(final File repoFolder) throws IOException {
checkNotNull("repoFolder", repoFolder);
try {
return Git.init().setBare(true).setDirectory(repoFolder).call();
} catch (GitAPIException e) {
throw new IOException(e);
}
}
代码示例来源:origin: org.kie/kie-wb-tests-rest
@BeforeClass
public static void createGitRepository() throws GitAPIException, IOException {
gitRepository = new File(System.getProperty("user.dir"), "target/git-repository/");
Git git = Git.init().setDirectory(gitRepository).call();
URL pomUrl = RestTestBase.class.getResource("/pom.xml");
File pomFile = new File(gitRepository, "pom.xml");
FileUtils.copyURLToFile(pomUrl, pomFile);
git.add().addFilepattern("pom.xml").call();
git.commit().setMessage("Add pom.xml").call();
}
代码示例来源:origin: org.kie.commons/kie-nio2-jgit
protected Git setupGit( final File tempDir ) throws IOException, GitAPIException {
final Git git = Git.init().setBare( true ).setDirectory( tempDir ).call();
commit( git, "master", "name", "name@example.com", "cool1", null, null, false, new HashMap<String, File>() {{
put( "file1.txt", tempFile( "content" ) );
put( "file2.txt", tempFile( "content2" ) );
}} );
return git;
}
内容来源于网络,如有侵权,请联系作者删除!