private void pull() throws GitAPIException { Git git = recordGit(Git.wrap(repository)); PullCommand pull = git.pull() .setRebase(true); PullResult result = pull.call(); if (!result.isSuccessful()) { LOGGER.log(Level.WARNING, () -> String.format("Cannot pull from git '%s', branch '%s'", uri.toASCIIString(), branch)); if (LOGGER.isLoggable(Level.FINEST)) { Status status = git.status().call(); LOGGER.finest(() -> "git status cleanliness: " + status.isClean()); if (!status.isClean()) { LOGGER.finest(() -> "git status uncommitted changes: " + status.getUncommittedChanges()); LOGGER.finest(() -> "git status untracked: " + status.getUntracked()); } } } else { LOGGER.fine("Pull was successful."); } LOGGER.finest(() -> "git rebase result: " + result.getRebaseResult().getStatus().name()); LOGGER.finest(() -> "git fetch result: " + result.getFetchResult().getMessages()); }
public Collection<String> getTags(Repository repo, final ObjectId objectId) throws GitAPIException { try (Git git = Git.wrap(repo)) { try (RevWalk walk = new RevWalk(repo)) { Collection<String> tags = getTags(git, objectId, walk); walk.dispose(); return tags; } } }
public static boolean isRepositoryInDirtyState(Repository repo) throws GitAPIException { Git git = Git.wrap(repo); Status status = git.status().call(); // Git describe doesn't mind about untracked files when checking if // repo is dirty. JGit does this, so we cannot use the isClean method // to get the same behaviour. Instead check dirty state without // status.getUntracked().isEmpty() boolean isDirty = !(status.getAdded().isEmpty() && status.getChanged().isEmpty() && status.getRemoved().isEmpty() && status.getMissing().isEmpty() && status.getModified().isEmpty() && status.getConflicting().isEmpty()); return isDirty; } }
private void fetch() { FetchCommand fetchCommand = Git.wrap(git).fetch(); try { fetchCommand.setThin(true).call(); } catch (Exception e) { log.error("Failed to perform fetch", e); } }
walk.markStart(walk.parseCommit(repo.resolve("HEAD"))); List<Ref> tagRefs = Git.wrap(repo).tagList().call(); Pattern regex = Pattern.compile(matchPattern); log.info("Tag refs [{}]", tagRefs);
private void resetSoftToParent() throws IOException, GitAPIException, CheckoutConflictException { Ref ref = repo.exactRef(Constants.ORIG_HEAD); ObjectId orig_head = ref == null ? null : ref.getObjectId(); try (Git git = Git.wrap(repo)) { // we have already committed the cherry-picked commit. // what we need is to have changes introduced by this // commit to be on the index // resetting is a workaround git.reset().setMode(ResetType.SOFT) .setRef("HEAD~1").call(); //$NON-NLS-1$ } finally { // set ORIG_HEAD back to where we started because soft // reset moved it repo.writeOrigHead(orig_head); } }
private void autoStash() throws GitAPIException, IOException { if (repo.getConfig().getBoolean(ConfigConstants.CONFIG_REBASE_SECTION, ConfigConstants.CONFIG_KEY_AUTOSTASH, false)) { String message = MessageFormat.format( AUTOSTASH_MSG, Repository .shortenRefName(getHeadName(getHead()))); RevCommit stashCommit = Git.wrap(repo).stashCreate().setRef(null) .setWorkingDirectoryMessage( message) .call(); if (stashCommit != null) { FileUtils.mkdir(rebaseState.getDir()); rebaseState.createFile(AUTOSTASH, stashCommit.getName()); } } }
private boolean autoStashApply() throws IOException, GitAPIException { boolean conflicts = false; if (rebaseState.getFile(AUTOSTASH).exists()) { String stash = rebaseState.readFile(AUTOSTASH); try (Git git = Git.wrap(repo)) { git.stashApply().setStashRef(stash) .ignoreRepositoryState(true).setStrategy(strategy) .call(); } catch (StashApplyFailureException e) { conflicts = true; try (RevWalk rw = new RevWalk(repo)) { ObjectId stashId = repo.resolve(stash); RevCommit commit = rw.parseCommit(stashId); updateStashRef(commit, commit.getAuthorIdent(), commit.getShortMessage()); } } } return conflicts; }
fetchCallback.fetchingSubmodule(generator.getPath()); FetchCommand fetchCommand = Git.wrap(repository).fetch(); if (monitor != null) { fetchCommand.setProgressMonitor(monitor);
walk.parseCommit(repo.resolve(Constants.HEAD)), upstreamCommit)) { org.eclipse.jgit.api.Status status = Git.wrap(repo) .status().setIgnoreSubmodules(IgnoreSubmoduleMode.ALL).call(); if (status.hasUncommittedChanges()) {
public static Status getStatus(Repository repository) { try { return Git.wrap(repository).status().call(); } catch (GitAPIException e) { throw new RuntimeException(e); } }
Status status = Git.wrap(submoduleRepo).status().call(); return status.isClean() ? SubmoduleDeinitStatus.SUCCESS : SubmoduleDeinitStatus.DIRTY;
private Git gitRepo(Project project) { try { File gitDir = getRootGitDir(project.getProjectDir()); return Git.wrap(new FileRepository(gitDir)); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { chain.doFilter(request, response); try { for (final LazilyLoadedRepository repository : repositories) { Git.wrap(repository.get()).reset().setMode(HARD).call(); } } catch (GitAPIException e) { throw new ServletException(e); } }
public Collection<String> getTags(Repository repo, final ObjectId objectId) throws GitAPIException { try (Git git = Git.wrap(repo)) { try (RevWalk walk = new RevWalk(repo)) { Collection<String> tags = getTags(git, objectId, walk); walk.dispose(); return tags; } } }
@Override public CommitFilter setRepository(final Repository repository) { super.setRepository(repository); if (repository != null) { show = Git.wrap(repository).notesShow(); noteRefs = getNoteRefs(repository); } else { show = null; noteRefs = null; } return this; }
@Override public CommitFilter setRepository(final Repository repository) { super.setRepository(repository); if (repository != null) { show = Git.wrap(repository).notesShow(); noteRefs = getNoteRefs(repository); } else { show = null; noteRefs = null; } return this; }
private void checkoutAllBranches(Repository repository) throws GitAPIException { final Git git = Git.wrap(repository); for (final Ref ref : git.branchList().setListMode(ListBranchCommand.ListMode.REMOTE).call()) { final String refName = ref.getName(); final String branchName = refName.substring(refName.lastIndexOf('/') + 1); try { git.checkout().setCreateBranch(true).setName(branchName).setStartPoint("origin/" + branchName).call(); } catch (RefAlreadyExistsException e) { LOGGER.warning("Already exists, so ignoring " + e.getMessage()); } } }
private Ref branch(Git origin, String source, String target) throws Exception { final Repository repo = origin.getRepository(); return org.eclipse.jgit.api.Git.wrap(repo) .branchCreate() .setName(target) .setStartPoint(source) .call(); }
private Ref branch(Git origin, String source, String target) throws Exception { final Repository repo = origin.getRepository(); return org.eclipse.jgit.api.Git.wrap(repo) .branchCreate() .setName(target) .setStartPoint(source) .call(); }