本文整理匯總了Java中org.eclipse.jgit.api.errors.GitAPIException類的典型用法代碼示例。如果您正苦於以下問題:Java GitAPIException類的具體用法?Java GitAPIException怎麽用?Java GitAPIException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
GitAPIException類屬於org.eclipse.jgit.api.errors包,在下文中一共展示了GitAPIException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: invoke
import org.eclipse.jgit.api.errors.GitAPIException; //導入依賴的package包/類
@Override
public Boolean invoke(File file, VirtualChannel channel){
try{
Git git = Git.cloneRepository()
.setURI(url)
.setDirectory(localDir)
.setTransportConfigCallback(getTransportConfigCallback())
.setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password))
.call();
// Default branch to checkout is master
if(branch==null || branch.isEmpty()){
branch = "master";
} else if (cloneType.equals("branch")){
branch = "origin" + File.separator + branch;
}
git.checkout().setName(branch).call();
git.close();
}catch(GitAPIException e){
status = false;
e.printStackTrace(listener.getLogger());
}
return status;
}
示例2: clone
import org.eclipse.jgit.api.errors.GitAPIException; //導入依賴的package包/類
/**
* Cloning the remote git repo to local directory
* @param remoteUri remote git url e.g. git://gitli.example.com/project/repo.git
* @param localDir local destination clone directory
* @throws IOException
* @throws GitAPIException
*/
public static void clone(String remoteUri, String localDir) throws IOException, GitAPIException {
//create local git directory
File localGitRepo = new File(localDir);
if (localGitRepo.exists()) {
if (localGitRepo.isDirectory()) {
// clean up directory
FileUtils.cleanDirectory(localGitRepo);
} else {
throw new IOException("File exists: " + localDir);
}
} else {
localGitRepo.mkdirs();
}
Git g = Git.cloneRepository().setURI(remoteUri).setDirectory(localGitRepo).call();
g.close();
}
示例3: run
import org.eclipse.jgit.api.errors.GitAPIException; //導入依賴的package包/類
@Override
protected void run () throws GitException {
Repository repository = getRepository();
org.eclipse.jgit.api.BlameCommand cmd = new Git(repository).blame();
cmd.setFilePath(Utils.getRelativePath(getRepository().getWorkTree(), file));
if (revision != null) {
cmd.setStartCommit(Utils.findCommit(repository, revision));
} else if (repository.getConfig().get(WorkingTreeOptions.KEY).getAutoCRLF() != CoreConfig.AutoCRLF.FALSE) {
// work-around for autocrlf
cmd.setTextComparator(new AutoCRLFComparator());
}
cmd.setFollowFileRenames(true);
try {
BlameResult cmdResult = cmd.call();
if (cmdResult != null) {
result = getClassFactory().createBlameResult(cmdResult, repository);
}
} catch (GitAPIException ex) {
throw new GitException(ex);
}
}
示例4: main
import org.eclipse.jgit.api.errors.GitAPIException; //導入依賴的package包/類
public static void main(String[] args) throws IOException, GitAPIException {
Repository repo = Commands.getRepo(Consts.META_REPO_PATH);
Git git = new Git(repo);
// Create a new branch
git.branchCreate().setName("newBranch").call();
// Checkout the new branch
git.checkout().setName("newBranch").call();
// List the existing branches
List<Ref> listRefsBranches = git.branchList().setListMode(ListMode.ALL).call();
listRefsBranches.forEach((refBranch) -> {
System.out.println("Branch : " + refBranch.getName());
});
// Go back on "master" branch and remove the created one
git.checkout().setName("master");
git.branchDelete().setBranchNames("newBranch");
}
示例5: run
import org.eclipse.jgit.api.errors.GitAPIException; //導入依賴的package包/類
@Override
protected void run () throws GitException {
Repository repository = getRepository();
try {
RevObject obj = Utils.findObject(repository, taggedObject);
TagCommand cmd = new Git(repository).tag();
cmd.setName(tagName);
cmd.setForceUpdate(forceUpdate);
cmd.setObjectId(obj);
cmd.setAnnotated(message != null && !message.isEmpty() || signed);
if (cmd.isAnnotated()) {
cmd.setMessage(message);
cmd.setSigned(signed);
}
cmd.call();
ListTagCommand tagCmd = new ListTagCommand(repository, getClassFactory(), false, new DelegatingGitProgressMonitor(monitor));
tagCmd.run();
Map<String, GitTag> tags = tagCmd.getTags();
tag = tags.get(tagName);
} catch (JGitInternalException | GitAPIException ex) {
throw new GitException(ex);
}
}
示例6: main
import org.eclipse.jgit.api.errors.GitAPIException; //導入依賴的package包/類
public static void main(String[] args) throws IOException, GitAPIException {
Repository repo = new FileRepository(Consts.META_REPO_PATH + ".git");
// get a list of all known heads, tags, remotes, ...
Collection<Ref> allRefs = repo.getAllRefs().values();
// a RevWalk allows to walk over commits based on some filtering that is defined
try (RevWalk revWalk = new RevWalk(repo)) {
for (Ref ref : allRefs) {
revWalk.markStart(revWalk.parseCommit(ref.getObjectId()));
}
System.out.println("Walking all commits starting with " + allRefs.size() + " refs: " + allRefs);
int count = 0;
for (RevCommit commit : revWalk) {
System.out.println("Commit: " + commit);
count++;
}
System.out.println("Had " + count + " commits");
}
}
示例7: checkoutBranch
import org.eclipse.jgit.api.errors.GitAPIException; //導入依賴的package包/類
private Ref checkoutBranch(File projectDir, String branch)
throws GitAPIException {
Git git = this.gitFactory.open(projectDir);
CheckoutCommand command = git.checkout().setName(branch);
try {
if (shouldTrack(git, branch)) {
trackBranch(command, branch);
}
return command.call();
}
catch (GitAPIException e) {
deleteBaseDirIfExists();
throw e;
} finally {
git.close();
}
}
示例8: main
import org.eclipse.jgit.api.errors.GitAPIException; //導入依賴的package包/類
public static void main(String[] args) throws IOException, GitAPIException {
Repository repo = Commands.getRepo(Consts.META_REPO_PATH);
// Get the id of the tree associated to the two commits
ObjectId head = repo.resolve("HEAD^{tree}");
ObjectId previousHead = repo.resolve("HEAD~^{tree}");
List<DiffEntry> list = listDiffs(repo, previousHead, head);
if(list != null){
// Simply display the diff between the two commits
list.forEach((diff) -> {
System.out.println(diff);
});
}
}
示例9: cloneRepositoryToTempFolder
import org.eclipse.jgit.api.errors.GitAPIException; //導入依賴的package包/類
public Repository cloneRepositoryToTempFolder(boolean checkoutAll) throws GitAPIException, IOException {
this.targetFolder = createTempFolder(repositoryName);
final Repository repository = Git.cloneRepository()
.setURI(repositoryUrl)
.setDirectory(targetFolder)
.setCloneAllBranches(true)
.setBranch("master")
.call()
.getRepository();
if (checkoutAll) {
checkoutAllBranches(repository);
}
LOGGER.info("Cloned test repository to: " + targetFolder);
return repository;
}
示例10: applyStashChangesLocally
import org.eclipse.jgit.api.errors.GitAPIException; //導入依賴的package包/類
private void applyStashChangesLocally(List<RevCommit> stashesToApply) throws GitAPIException {
RevCommit tmpCommit = null;
// We cannot just apply changes from stash one after the other
// as git will complain about uncommitted changes when trying
// to apply second consecutive stash.
// So we create temporary commits to overcome this issue
// and reset softly on the way to have it all as local changes
for (final RevCommit stash : stashesToApply) {
if (stash == null){
continue;
}
git.stashApply().setStashRef(stash.getName()).call();
if (tmpCommit != null) {
git.reset().setRef(ONE_BACK).setMode(SOFT).call();
}
tmpCommit = createTemporaryCommit();
}
if (tmpCommit != null) {
git.reset().setRef(ONE_BACK).setMode(SOFT).call();
}
git.stashDrop().setAll(true).call();
}
示例11: should_find_local_newly_staged_files_as_new
import org.eclipse.jgit.api.errors.GitAPIException; //導入依賴的package包/類
@Test
public void should_find_local_newly_staged_files_as_new() throws IOException, GitAPIException {
//given
Configuration configuration = createConfiguration("a4261d5", "1ee4abf");
final File testFile = gitFolder.newFile("core/src/test/java/org/arquillian/smart/testing/CalculatorTest.java");
Files.write(testFile.toPath(), getContentsOfClass().getBytes(), StandardOpenOption.APPEND);
GitRepositoryOperations.addFile(gitFolder.getRoot(), testFile.getAbsolutePath());
final NewTestsDetector newTestsDetector =
new NewTestsDetector(new GitChangeResolver(), new NoopStorage(), gitFolder.getRoot(), path -> true, configuration);
// when
final Collection<TestSelection> newTests = newTestsDetector.getTests();
// then
assertThat(newTests).extracting(TestSelection::getClassName)
.containsOnly("org.arquillian.smart.testing.CalculatorTest",
"org.arquillian.smart.testing.vcs.git.NewFilesDetectorTest");
}
示例12: should_find_modified_staged_tests_as_changed
import org.eclipse.jgit.api.errors.GitAPIException; //導入依賴的package包/類
@Test
public void should_find_modified_staged_tests_as_changed() throws IOException, GitAPIException {
//given
Configuration configuration = createConfiguration("7699c2c", "04d04fe");
final Path testFile = Paths.get(gitFolder.getRoot().getAbsolutePath(),
"core/src/test/java/org/arquillian/smart/testing/FilesTest.java");
Files.write(testFile, "//This is a test".getBytes(), StandardOpenOption.APPEND);
GitRepositoryOperations.addFile(gitFolder.getRoot(), testFile.toString());
final ChangedTestsDetector changedTestsDetector =
new ChangedTestsDetector(new GitChangeResolver(), new NoopStorage(), gitFolder.getRoot(),
className -> className.endsWith("Test"), configuration);
// when
final Collection<TestSelection> newTests = changedTestsDetector.getTests();
// then
assertThat(newTests).extracting(TestSelection::getClassName)
.containsOnly("org.arquillian.smart.testing.vcs.git.NewFilesDetectorTest",
"org.arquillian.smart.testing.FilesTest");
}
示例13: should_fetch_all_untracked_files_for_first_commit
import org.eclipse.jgit.api.errors.GitAPIException; //導入依賴的package包/類
@Test
public void should_fetch_all_untracked_files_for_first_commit() throws IOException, GitAPIException {
// given
final File parent = gitFolder.newFolder("parent");
final File newGitFolder = parent.getParentFile();
gitFolder.newFile("parent/foo.txt");
try (Git git = Git.init()
.setDirectory(newGitFolder)
.call()) {
}
this.gitChangeResolver = new GitChangeResolver();
// when
final Set<Change> untrackedChanges = gitChangeResolver.diff(newGitFolder, "HEAD~0", "HEAD");
// then
assertThat(untrackedChanges).hasSize(1).extracting(Change::getLocation, Change::getChangeType).containsOnly(tuple(
relative("parent/foo.txt"), ChangeType.ADD));
}
示例14: testPushOK
import org.eclipse.jgit.api.errors.GitAPIException; //導入依賴的package包/類
@Test
public void testPushOK()
throws URISyntaxException, IOException, InvalidRemoteException, TransportException, GitAPIException, NoRepositorySelected {
gitAccess.setRepository(LOCAL_TEST_REPOSITPRY);
final StoredConfig config = gitAccess.getRepository().getConfig();
RemoteConfig remoteConfig = new RemoteConfig(config, "origin");
URIish uri = new URIish(db2.getDirectory().toURI().toURL());
remoteConfig.addURI(uri);
remoteConfig.update(config);
config.save();
gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
gitAccess.commit("file test added");
gitAccess.push("", "");
assertEquals(db1.resolve(gitAccess.getLastLocalCommit().getName() + "^{commit}"),
db2.resolve(gitAccess.getLastLocalCommit().getName() + "^{commit}"));
}
示例15: deleteTag
import org.eclipse.jgit.api.errors.GitAPIException; //導入依賴的package包/類
public void deleteTag(String tag) {
String refName = GitUtils.tag2ref(tag);
ObjectId commitId = getRevCommit(refName).getId();
try {
git().tagDelete().setTags(tag).call();
} catch (GitAPIException e) {
throw new RuntimeException(e);
}
Subject subject = SecurityUtils.getSubject();
GitPlex.getInstance(UnitOfWork.class).doAsync(new Runnable() {
@Override
public void run() {
ThreadContext.bind(subject);
try {
Project project = GitPlex.getInstance(ProjectManager.class).load(getId());
GitPlex.getInstance(ListenerRegistry.class).post(
new RefUpdated(project, refName, commitId, ObjectId.zeroId()));
} finally {
ThreadContext.unbindSubject();
}
}
});
}