/** * @param repo */ protected CustomDiffCommand(Git git) { super(git.getRepository()); this.git = git; }
final Git git = Git.createRepository(repoDir, hookDir, sslVerify); git.fetch(credentialsProvider, remote, refSpecList); git.syncRemote(remote); if (git.isKetchEnabled()) { git.convertRefTree(); git.updateLeaders(leaders); git.setHeadAsInitialized(); origin); logger.error(message); cleanupDir(git.getRepository().getDirectory()); throw new CloneException(message, e);
public List<String> execute() { existsBranch(git, sourceBranch); existsBranch(git, targetBranch); final Repository repo = git.getRepository(); final RevCommit lastSourceCommit = git.getLastCommit(sourceBranch); final RevCommit lastTargetCommit = git.getLastCommit(targetBranch); final RevCommit commonAncestor = getCommonAncestor(lastSourceCommit, lastTargetCommit); final List<RevCommit> commits = git.listCommits(commonAncestor, lastSourceCommit); Collections.reverse(commits); final String[] commitsIDs = commits.stream().map(AnyObjectId::getName).toArray(String[]::new); canMerge(repo, commonAncestor, lastSourceCommit, lastTargetCommit, sourceBranch, targetBranch); git.cherryPick(targetBranch, commitsIDs); if (logger.isDebugEnabled()) { logger.debug("Merging commits from <{}> to <{}>", sourceBranch, targetBranch); } return Arrays.asList(commitsIDs); }
public List<ObjectId> execute() { final List<ObjectId> result = new ArrayList<>(); for (final String id : ids) { try { final Ref refName = git.getRef(id); if (refName != null) { result.add(refName.getObjectId()); continue; } try { final ObjectId _id = ObjectId.fromString(id); if (git.getRepository().getObjectDatabase().has(_id)) { result.add(_id); } } catch (final IllegalArgumentException ignored) { } } catch (final java.io.IOException ignored) { } } return result; } }
origin.getRepository().getDirectory().toString(), false, CredentialsProvider.getDefault(), null).execute().get(); assertThat(git.getPathInfo("master", "pathx/").getPathType()).isEqualTo(NOT_FOUND); assertThat(git.getPathInfo("master", "path/to/file2.txt").getPathType()).isEqualTo(FILE); assertThat(git.getPathInfo("master", "path/to").getPathType()).isEqualTo(DIRECTORY);
final Git cloned = Git.createRepository(gitCloned, hooksDir); assertThat(new ListRefs(cloned.getRepository()).execute()).hasSize(1); assertThat(new ListRefs(cloned.getRepository()).execute().get(0).getName()).isEqualTo("refs/heads/user_branch"); File[] hooks = new File(cloned.getRepository().getDirectory(), "hooks").listFiles(); assertThat(hooks).isNotEmpty().isNotNull(); assertThat(hooks.length).isEqualTo(2);
public void execute() throws IOException, ConcurrentRefUpdateException { final ObjectId headId = git.getLastCommit(Constants.R_HEADS + name); final RefUpdate ru = git.getRepository().updateRef(Constants.R_HEADS + name); if (headId == null) { ru.setExpectedOldObjectId(ObjectId.zeroId()); } else { ru.setExpectedOldObjectId(headId); } ru.setNewObjectId(commit.getId()); ru.setRefLogMessage(commit.getShortMessage(), false); forceUpdate(ru, commit.getId()); }
public GetLastCommit(final Git git, final String branchName) { this(git, git.getRef(branchName)); }
final PathInfo result = gPath.getFileSystem().getGit().getPathInfo(gPath.getRefTree(), gPath.getPath());
private VersionAttributes buildAttrs(final JGitFileSystem fs, final String branchName, final String path) { final PathInfo pathInfo = fs.getGit().getPathInfo(branchName, path); final Ref refId = fs.getGit().getRef(branchName); final List<VersionRecord> records = new ArrayList<>(); final CommitHistory history = fs.getGit().listCommits(refId, pathInfo.getPath()); for (final RevCommit commit : history.getCommits()) { final String recordPath = history.trackedFileNameChangeFor(commit.getId());
public void execute() { final List<ObjectId> commits = git.resolveObjectIds(this.commits); if (commits.size() != this.commits.length) { throw new IOException("Couldn't resolve some commits."); final Ref headRef = git.getRef(targetBranch); if (headRef == null) { throw new IOException("Branch not found."); final RevCommit srcCommit = git.resolveRevCommit(src); git.refUpdate(targetBranch, srcCommit);
try { if (this.isForkOrigin(origin)) { git = Git.fork(this.getGitRepoContainerDir(), origin, fsName, throw new UnsupportedOperationException("Cannot make mirror repository when cloning subdirectory."); git = Git.cloneSubdirectory(repoDest, origin, subdirectory, config.isSslVerify()); } else { git = Git.clone(repoDest, origin, isMirror, git = Git.createRepository(repoDest, config.getHookDir(), config.isEnableKetch() ? leaders : null,
public boolean deleteAssetIfExists(final JGitPathImpl path, final DeleteOption... options) { final PathInfo result = path.getFileSystem().getGit().getPathInfo(path.getRefTree(), path.getPath()); if (result.getPathType().equals(PathType.DIRECTORY)) { if (deleteNonEmptyDirectory(options)) { deleteResource(path, options); return true; } final List<PathInfo> content = path.getFileSystem().getGit().listPathContent(path.getRefTree(), path.getPath()); if (content.size() == 1 && content.get(0).getPath().equals(path.getPath().substring(1) + "/.gitkeep")) { delete(path.resolve(".gitkeep")); return true; } throw new DirectoryNotEmptyException(path.toString()); } if (result.getPathType().equals(NOT_FOUND)) { return false; } deleteResource(path, options); return true; }
}}).execute(); final RevCommit commit = git.getLastCommit("master"); try { assertNotNull(git.listCommits(null, commit)); assertNotNull(git.listCommits(null, commit)); assertNotNull(git.listCommits(null, commit)); } catch (Exception ex) { assertNotNull(git.listCommits(null, commit)); fail("forced to fail!");
static Git createRepository(final File repoDir, final boolean sslVerify) { return createRepository(repoDir, null, sslVerify); }
private BasicFileAttributes buildAttrs(final JGitFileSystem fs, final String branchName, final String path) { final PathInfo pathInfo = fs.getGit().getPathInfo(branchName, path); final Ref ref = fs.getGit().getRef(branchName);
public Commit(final Git git, final String branchName, final CommitInfo commitInfo, final boolean amend, final ObjectId originId, final CommitContent content) { this.git = git; this.branchName = branchName; this.commitInfo = commitInfo; this.amend = amend; this.content = content; try { if (originId == null) { this.originId = git.getLastCommit(branchName); } else { this.originId = originId; } } catch (final Throwable t) { throw new RuntimeException(t); } }
final boolean batchState = fileSystem.isOnBatch(); final boolean amend = batchState && fileSystem.isHadCommitOnBatchState(path.getRoot()); final ObjectId oldHead = path.getFileSystem().getGit().getTreeFromRef(branchName); hasCommit = git.commit(branchName, fileSystem.getBatchCommitInfo(), amend, commitContent); } else { hasCommit = git.commit(branchName, commitInfo, amend, int value = fileSystem.incrementAndGetCommitCount(); if (value >= config.getCommitLimit()) { git.gc(); fileSystem.resetCommitCount(); final ObjectId newHead = path.getFileSystem().getGit().getTreeFromRef(branchName); final ObjectId newHead = path.getFileSystem().getGit().getTreeFromRef(branchName); List<WatchEvent<?>> postponedWatchEvents = compareDiffs(path.getFileSystem(), branchName,
public void deleteBranch(final JGitPathImpl path) { final Ref branch = path.getFileSystem().getGit().getRef(path.getRefTree()); if (branch == null) { throw new NoSuchFileException(path.toString()); } try { path.getFileSystem().lock(); path.getFileSystem().getGit().deleteRef(branch); } finally { path.getFileSystem().unlock(); } }
@Override public InputStream newInputStream(final Path path, final OpenOption... options) throws IllegalArgumentException, UnsupportedOperationException, IOException, SecurityException { checkNotNull("path", path); final JGitPathImpl gPath = toPathImpl(path); return gPath.getFileSystem().getGit().blobAsInputStream(gPath.getRefTree(), gPath.getPath()); }