public GetLastCommit(final Git git, final String branchName) { this(git, git.getRef(branchName)); }
public GetFirstCommit(final Git git, final String branchName) { this(git, git.getRef(branchName)); }
private void existsBranch(final Git git, final String branch) { if (git.getRef(branch) == null) { throw new GitException(String.format("Branch <<%s>> does not exists", branch)); } }
private boolean existsBranch(final JGitPathImpl path) { return path.getFileSystem().getGit().getRef(path.getRefTree()) != null; }
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; } }
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(); } }
@Test public void listCommitsForUnmovedFile() throws Exception { final CommitHistory history = new ListCommits(git, git.getRef("master"), "non-moving.txt").execute(); assertEquals("non-moving.txt", history.getTrackedFilePath()); assertEquals(2, history.getCommits().size()); assertEquals("/non-moving.txt", history.trackedFileNameChangeFor(history.getCommits().get(0).getId())); assertEquals("/non-moving.txt", history.trackedFileNameChangeFor(history.getCommits().get(1).getId())); }
@Test public void listCommitsForUnmovedFile() throws Exception { final CommitHistory history = new ListCommits(git, git.getRef("master"), "non-moving.txt").execute(); assertEquals("non-moving.txt", history.getTrackedFilePath()); assertEquals(2, history.getCommits().size()); assertEquals("/non-moving.txt", history.trackedFileNameChangeFor(history.getCommits().get(0).getId())); assertEquals("/non-moving.txt", history.trackedFileNameChangeFor(history.getCommits().get(1).getId())); }
@Test public void listCommitsOnRootDirectoryViaEmpty() throws Exception { final CommitHistory history = new ListCommits(git, git.getRef("master"), "").execute(); assertEquals("/", history.getTrackedFilePath()); assertEquals(5, history.getCommits().size()); final RevCommit commit0 = history.getCommits().get(0); String oPath0 = history.trackedFileNameChangeFor(commit0.getId()); assertEquals("simulate checkout old version", commit0.getFullMessage()); assertEquals("/", oPath0); } }
@Test public void listCommitsOnRootDirectoryViaAbsolute() throws Exception { final CommitHistory history = new ListCommits(git, git.getRef("master"), "/").execute(); assertEquals("/", history.getTrackedFilePath()); assertEquals(5, history.getCommits().size()); final RevCommit commit0 = history.getCommits().get(0); String oPath0 = history.trackedFileNameChangeFor(commit0.getId()); assertEquals("simulate checkout old version", commit0.getFullMessage()); assertEquals("/", oPath0); }
@Test public void listCommitsOnDirectory() throws Exception { final CommitHistory history = new ListCommits(git, git.getRef("master"), "dir").execute(); assertEquals("dir", history.getTrackedFilePath()); assertEquals(1, history.getCommits().size()); final RevCommit commit0 = history.getCommits().get(0); String oPath0 = history.trackedFileNameChangeFor(commit0.getId()); assertEquals("move moving file to new dir", commit0.getFullMessage()); assertEquals("/dir", oPath0); }
@Test public void listCommitsOnRootDirectoryViaNull() throws Exception { final CommitHistory history = new ListCommits(git, git.getRef("master"), null).execute(); assertEquals("/", history.getTrackedFilePath()); assertEquals(5, history.getCommits().size()); final RevCommit commit0 = history.getCommits().get(0); String oPath0 = history.trackedFileNameChangeFor(commit0.getId()); assertEquals("simulate checkout old version", commit0.getFullMessage()); assertEquals("/", oPath0); }
@Test public void listCommitsOnRootDirectoryViaAbsolute() throws Exception { final CommitHistory history = new ListCommits(git, git.getRef("master"), "/").execute(); assertEquals("/", history.getTrackedFilePath()); assertEquals(5, history.getCommits().size()); final RevCommit commit0 = history.getCommits().get(0); String oPath0 = history.trackedFileNameChangeFor(commit0.getId()); assertEquals("simulate checkout old version", commit0.getFullMessage()); assertEquals("/", oPath0); }
@Test public void listCommitsOnRootDirectoryViaEmpty() throws Exception { final CommitHistory history = new ListCommits(git, git.getRef("master"), "").execute(); assertEquals("/", history.getTrackedFilePath()); assertEquals(5, history.getCommits().size()); final RevCommit commit0 = history.getCommits().get(0); String oPath0 = history.trackedFileNameChangeFor(commit0.getId()); assertEquals("simulate checkout old version", commit0.getFullMessage()); assertEquals("/", oPath0); } }
@Test public void listCommitsOnDirectory() throws Exception { final CommitHistory history = new ListCommits(git, git.getRef("master"), "dir").execute(); assertEquals("dir", history.getTrackedFilePath()); assertEquals(1, history.getCommits().size()); final RevCommit commit0 = history.getCommits().get(0); String oPath0 = history.trackedFileNameChangeFor(commit0.getId()); assertEquals("move moving file to new dir", commit0.getFullMessage()); assertEquals("/dir", oPath0); }
@Test public void listCommitsOnRootDirectoryViaNull() throws Exception { final CommitHistory history = new ListCommits(git, git.getRef("master"), null).execute(); assertEquals("/", history.getTrackedFilePath()); assertEquals(5, history.getCommits().size()); final RevCommit commit0 = history.getCommits().get(0); String oPath0 = history.trackedFileNameChangeFor(commit0.getId()); assertEquals("simulate checkout old version", commit0.getFullMessage()); assertEquals("/", oPath0); }
@Test public void listCommitsForMovedFile() throws Exception { final CommitHistory history = new ListCommits(git, git.getRef("master"), "dir/moving2.txt").execute(); assertEquals("dir/moving2.txt", history.getTrackedFilePath()); assertEquals(4, history.getCommits().size()); final RevCommit commit0 = history.getCommits().get(0); String oPath0 = history.trackedFileNameChangeFor(commit0.getId()); assertEquals("move moving file to new dir", commit0.getFullMessage()); assertEquals("/dir/moving2.txt", oPath0); final RevCommit commit1 = history.getCommits().get(1); String oPath1 = history.trackedFileNameChangeFor(commit1.getId()); assertEquals("change content, no moves", commit1.getFullMessage()); assertEquals("/moving1.txt", oPath1); final RevCommit commit2 = history.getCommits().get(2); String oPath2 = history.trackedFileNameChangeFor(commit2.getId()); assertEquals("rename moving file", commit2.getFullMessage()); assertEquals("/moving1.txt", oPath2); final RevCommit commit3 = history.getCommits().get(3); String oPath3 = history.trackedFileNameChangeFor(commit3.getId()); assertEquals("create files", commit3.getFullMessage()); assertEquals("/moving.txt", oPath3); }
@Test public void listCommitsForMovedFile() throws Exception { final CommitHistory history = new ListCommits(git, git.getRef("master"), "dir/moving2.txt").execute(); assertEquals("dir/moving2.txt", history.getTrackedFilePath()); assertEquals(4, history.getCommits().size()); final RevCommit commit0 = history.getCommits().get(0); String oPath0 = history.trackedFileNameChangeFor(commit0.getId()); assertEquals("move moving file to new dir", commit0.getFullMessage()); assertEquals("/dir/moving2.txt", oPath0); final RevCommit commit1 = history.getCommits().get(1); String oPath1 = history.trackedFileNameChangeFor(commit1.getId()); assertEquals("change content, no moves", commit1.getFullMessage()); assertEquals("/moving1.txt", oPath1); final RevCommit commit2 = history.getCommits().get(2); String oPath2 = history.trackedFileNameChangeFor(commit2.getId()); assertEquals("rename moving file", commit2.getFullMessage()); assertEquals("/moving1.txt", oPath2); final RevCommit commit3 = history.getCommits().get(3); String oPath3 = history.trackedFileNameChangeFor(commit3.getId()); assertEquals("create files", commit3.getFullMessage()); assertEquals("/moving.txt", oPath3); }
@Test public void listCommitsForRestoredFile() throws Exception { final CommitHistory history = new ListCommits(git, git.getRef("master"), "moving1.txt").execute(); assertEquals("moving1.txt", history.getTrackedFilePath()); assertEquals(4, history.getCommits().size()); final RevCommit commit0 = history.getCommits().get(0); String oPath0 = history.trackedFileNameChangeFor(commit0.getId()); assertEquals("simulate checkout old version", commit0.getFullMessage()); assertEquals("/moving1.txt", oPath0); final RevCommit commit1 = history.getCommits().get(1); String oPath1 = history.trackedFileNameChangeFor(commit1.getId()); assertEquals("change content, no moves", commit1.getFullMessage()); assertEquals("/moving1.txt", oPath1); final RevCommit commit2 = history.getCommits().get(2); String oPath2 = history.trackedFileNameChangeFor(commit2.getId()); assertEquals("rename moving file", commit2.getFullMessage()); assertEquals("/moving1.txt", oPath2); final RevCommit commit3 = history.getCommits().get(3); String oPath3 = history.trackedFileNameChangeFor(commit3.getId()); assertEquals("create files", commit3.getFullMessage()); assertEquals("/moving.txt", oPath3); }
@Test public void listCommitsForRestoredFile() throws Exception { final CommitHistory history = new ListCommits(git, git.getRef("master"), "moving1.txt").execute(); assertEquals("moving1.txt", history.getTrackedFilePath()); assertEquals(4, history.getCommits().size()); final RevCommit commit0 = history.getCommits().get(0); String oPath0 = history.trackedFileNameChangeFor(commit0.getId()); assertEquals("simulate checkout old version", commit0.getFullMessage()); assertEquals("/moving1.txt", oPath0); final RevCommit commit1 = history.getCommits().get(1); String oPath1 = history.trackedFileNameChangeFor(commit1.getId()); assertEquals("change content, no moves", commit1.getFullMessage()); assertEquals("/moving1.txt", oPath1); final RevCommit commit2 = history.getCommits().get(2); String oPath2 = history.trackedFileNameChangeFor(commit2.getId()); assertEquals("rename moving file", commit2.getFullMessage()); assertEquals("/moving1.txt", oPath2); final RevCommit commit3 = history.getCommits().get(3); String oPath3 = history.trackedFileNameChangeFor(commit3.getId()); assertEquals("create files", commit3.getFullMessage()); assertEquals("/moving.txt", oPath3); }