Merge branch 'stable-4.2'
* stable-4.2: NoteMapTest: Open TreeWalk instances in try-with-resource ObjectDirectoryTest: Fix warnings about variable hiding PackWriterTest: Open RevWalk in try-with-resource PatchIdDiffFormatterTest: Open Git and PatchIdDiffFormatter in try-with-resource PathSuffixFilterTest: Open TreeWalk in try-with-resource PostOrderTreeWalkTest: Open TreeWalk in try-with-resource PullCommandWithRebaseTest: Open RevWalk in try-with-resource PushCommandTest: Open Git instances in try-with-resource RacyGitTests: Open NameConflictTreeWalk in try-with-resource RecursiveMergerTest: Open TreeWalk and BufferedReader in try-with-resource ReflogConfigTest: refactor commit method to avoid variable hiding Update .mailmap RefDirectoryTest: Fix warning about member variable hiding ReflogResolveTest: Open Git instances in try-with-resource ReflogTest: Open Git instances in try-with-resource RepoCommandTest: Open Git instances in try-with-resource Change-Id: I7964b699396629e31a9cc5600aedcf4be4e659a8 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
commit
4dcf34eddf
11
.mailmap
11
.mailmap
|
@ -1,5 +1,6 @@
|
||||||
Shawn Pearce <spearce@spearce.org> Shawn O. Pearce <sop@google.com>
|
Roberto Tyley <roberto.tyley@guardian.co.uk> roberto <roberto.tyley@guardian.co.uk>
|
||||||
Shawn Pearce <spearce@spearce.org> Shawn Pearce <sop@google.com>
|
Saša Živkov <sasa.zivkov@sap.com> Sasa Zivkov <sasa.zivkov@sap.com>
|
||||||
Shawn Pearce <spearce@spearce.org> Shawn O. Pearce <spearce@spearce.org>
|
Saša Živkov <sasa.zivkov@sap.com> Saša Živkov <zivkov@gmail.com>
|
||||||
Saša Živkov <sasa.zivkov@sap.com> Sasa Zivkov <sasa.zivkov@sap.com>
|
Shawn Pearce <spearce@spearce.org> Shawn O. Pearce <sop@google.com>
|
||||||
Saša Živkov <sasa.zivkov@sap.com> Saša Živkov <zivkov@gmail.com>
|
Shawn Pearce <spearce@spearce.org> Shawn Pearce <sop@google.com>
|
||||||
|
Shawn Pearce <spearce@spearce.org> Shawn O. Pearce <spearce@spearce.org>
|
||||||
|
|
|
@ -57,24 +57,27 @@ public void testClean() throws Exception {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSingleCommit() throws Exception {
|
public void testSingleCommit() throws Exception {
|
||||||
new Git(db).commit().setMessage("initial commit").call();
|
try (Git git = new Git(db)) {
|
||||||
|
git.commit().setMessage("initial commit").call();
|
||||||
|
|
||||||
assertEquals("6fd41be HEAD@{0}: commit (initial): initial commit",
|
assertEquals("6fd41be HEAD@{0}: commit (initial): initial commit",
|
||||||
execute("git reflog")[0]);
|
execute("git reflog")[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBranch() throws Exception {
|
public void testBranch() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
git.commit().setMessage("first commit").call();
|
git.commit().setMessage("first commit").call();
|
||||||
git.checkout().setCreateBranch(true).setName("side").call();
|
git.checkout().setCreateBranch(true).setName("side").call();
|
||||||
writeTrashFile("file", "side content");
|
writeTrashFile("file", "side content");
|
||||||
git.add().addFilepattern("file").call();
|
git.add().addFilepattern("file").call();
|
||||||
git.commit().setMessage("side commit").call();
|
git.commit().setMessage("side commit").call();
|
||||||
|
|
||||||
assertArrayEquals(new String[] {
|
assertArrayEquals(new String[] {
|
||||||
"38890c7 side@{0}: commit: side commit",
|
"38890c7 side@{0}: commit: side commit",
|
||||||
"d216986 side@{1}: branch: Created from commit first commit",
|
"d216986 side@{1}: branch: Created from commit first commit",
|
||||||
"" }, execute("git reflog refs/heads/side"));
|
"" }, execute("git reflog refs/heads/side"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -273,26 +273,27 @@ public void testPullFastForwardWithLocalCommitAndRebaseFlagSet() throws Exceptio
|
||||||
|
|
||||||
// Get the HEAD and HEAD~1 commits
|
// Get the HEAD and HEAD~1 commits
|
||||||
Repository targetRepo = target.getRepository();
|
Repository targetRepo = target.getRepository();
|
||||||
RevWalk revWalk = new RevWalk(targetRepo);
|
try (RevWalk revWalk = new RevWalk(targetRepo)) {
|
||||||
ObjectId headId = targetRepo.resolve(Constants.HEAD);
|
ObjectId headId = targetRepo.resolve(Constants.HEAD);
|
||||||
RevCommit root = revWalk.parseCommit(headId);
|
RevCommit root = revWalk.parseCommit(headId);
|
||||||
revWalk.markStart(root);
|
revWalk.markStart(root);
|
||||||
// HEAD
|
// HEAD
|
||||||
RevCommit head = revWalk.next();
|
RevCommit head = revWalk.next();
|
||||||
// HEAD~1
|
// HEAD~1
|
||||||
RevCommit beforeHead = revWalk.next();
|
RevCommit beforeHead = revWalk.next();
|
||||||
|
|
||||||
// verify the commit message on the HEAD commit
|
// verify the commit message on the HEAD commit
|
||||||
assertEquals(TARGET_COMMIT_MESSAGE, head.getFullMessage());
|
assertEquals(TARGET_COMMIT_MESSAGE, head.getFullMessage());
|
||||||
// verify the commit just before HEAD
|
// verify the commit just before HEAD
|
||||||
assertEquals(SOURCE_COMMIT_MESSAGE, beforeHead.getFullMessage());
|
assertEquals(SOURCE_COMMIT_MESSAGE, beforeHead.getFullMessage());
|
||||||
|
|
||||||
// verify file states
|
// verify file states
|
||||||
assertFileContentsEqual(sourceFile, SOURCE_FILE_CONTENTS);
|
assertFileContentsEqual(sourceFile, SOURCE_FILE_CONTENTS);
|
||||||
assertFileContentsEqual(newFile, NEW_FILE_CONTENTS);
|
assertFileContentsEqual(newFile, NEW_FILE_CONTENTS);
|
||||||
// verify repository state
|
// verify repository state
|
||||||
assertEquals(RepositoryState.SAFE, target
|
assertEquals(RepositoryState.SAFE, target
|
||||||
.getRepository().getRepositoryState());
|
.getRepository().getRepositoryState());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -90,26 +90,27 @@ public void testPush() throws JGitInternalException, IOException,
|
||||||
remoteConfig.update(config);
|
remoteConfig.update(config);
|
||||||
config.save();
|
config.save();
|
||||||
|
|
||||||
Git git1 = new Git(db);
|
try (Git git1 = new Git(db)) {
|
||||||
// create some refs via commits and tag
|
// create some refs via commits and tag
|
||||||
RevCommit commit = git1.commit().setMessage("initial commit").call();
|
RevCommit commit = git1.commit().setMessage("initial commit").call();
|
||||||
Ref tagRef = git1.tag().setName("tag").call();
|
Ref tagRef = git1.tag().setName("tag").call();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db2.resolve(commit.getId().getName() + "^{commit}");
|
db2.resolve(commit.getId().getName() + "^{commit}");
|
||||||
fail("id shouldn't exist yet");
|
fail("id shouldn't exist yet");
|
||||||
} catch (MissingObjectException e) {
|
} catch (MissingObjectException e) {
|
||||||
// we should get here
|
// we should get here
|
||||||
|
}
|
||||||
|
|
||||||
|
RefSpec spec = new RefSpec("refs/heads/master:refs/heads/x");
|
||||||
|
git1.push().setRemote("test").setRefSpecs(spec)
|
||||||
|
.call();
|
||||||
|
|
||||||
|
assertEquals(commit.getId(),
|
||||||
|
db2.resolve(commit.getId().getName() + "^{commit}"));
|
||||||
|
assertEquals(tagRef.getObjectId(),
|
||||||
|
db2.resolve(tagRef.getObjectId().getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
RefSpec spec = new RefSpec("refs/heads/master:refs/heads/x");
|
|
||||||
git1.push().setRemote("test").setRefSpecs(spec)
|
|
||||||
.call();
|
|
||||||
|
|
||||||
assertEquals(commit.getId(),
|
|
||||||
db2.resolve(commit.getId().getName() + "^{commit}"));
|
|
||||||
assertEquals(tagRef.getObjectId(),
|
|
||||||
db2.resolve(tagRef.getObjectId().getName()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -132,15 +133,16 @@ public void testPrePushHook() throws JGitInternalException, IOException,
|
||||||
+ hookOutput.toPath() + "\"\ncat - >>\"" + hookOutput.toPath()
|
+ hookOutput.toPath() + "\"\ncat - >>\"" + hookOutput.toPath()
|
||||||
+ "\"\nexit 0");
|
+ "\"\nexit 0");
|
||||||
|
|
||||||
Git git1 = new Git(db);
|
try (Git git1 = new Git(db)) {
|
||||||
// create some refs via commits and tag
|
// create some refs via commits and tag
|
||||||
RevCommit commit = git1.commit().setMessage("initial commit").call();
|
RevCommit commit = git1.commit().setMessage("initial commit").call();
|
||||||
|
|
||||||
RefSpec spec = new RefSpec("refs/heads/master:refs/heads/x");
|
RefSpec spec = new RefSpec("refs/heads/master:refs/heads/x");
|
||||||
git1.push().setRemote("test").setRefSpecs(spec).call();
|
git1.push().setRemote("test").setRefSpecs(spec).call();
|
||||||
assertEquals("1:test, 2:" + uri + ", 3:\n" + "refs/heads/master "
|
assertEquals("1:test, 2:" + uri + ", 3:\n" + "refs/heads/master "
|
||||||
+ commit.getName() + " refs/heads/x "
|
+ commit.getName() + " refs/heads/x "
|
||||||
+ ObjectId.zeroId().name(), read(hookOutput));
|
+ ObjectId.zeroId().name(), read(hookOutput));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private File writeHookFile(final String name, final String data)
|
private File writeHookFile(final String name, final String data)
|
||||||
|
@ -160,45 +162,45 @@ public void testTrackingUpdate() throws Exception {
|
||||||
String branch = "refs/heads/master";
|
String branch = "refs/heads/master";
|
||||||
String trackingBranch = "refs/remotes/" + remote + "/master";
|
String trackingBranch = "refs/remotes/" + remote + "/master";
|
||||||
|
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
|
RevCommit commit1 = git.commit().setMessage("Initial commit")
|
||||||
|
.call();
|
||||||
|
|
||||||
RevCommit commit1 = git.commit().setMessage("Initial commit")
|
RefUpdate branchRefUpdate = db.updateRef(branch);
|
||||||
.call();
|
branchRefUpdate.setNewObjectId(commit1.getId());
|
||||||
|
branchRefUpdate.update();
|
||||||
|
|
||||||
RefUpdate branchRefUpdate = db.updateRef(branch);
|
RefUpdate trackingBranchRefUpdate = db.updateRef(trackingBranch);
|
||||||
branchRefUpdate.setNewObjectId(commit1.getId());
|
trackingBranchRefUpdate.setNewObjectId(commit1.getId());
|
||||||
branchRefUpdate.update();
|
trackingBranchRefUpdate.update();
|
||||||
|
|
||||||
RefUpdate trackingBranchRefUpdate = db.updateRef(trackingBranch);
|
final StoredConfig config = db.getConfig();
|
||||||
trackingBranchRefUpdate.setNewObjectId(commit1.getId());
|
RemoteConfig remoteConfig = new RemoteConfig(config, remote);
|
||||||
trackingBranchRefUpdate.update();
|
URIish uri = new URIish(db2.getDirectory().toURI().toURL());
|
||||||
|
remoteConfig.addURI(uri);
|
||||||
final StoredConfig config = db.getConfig();
|
remoteConfig.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/"
|
||||||
RemoteConfig remoteConfig = new RemoteConfig(config, remote);
|
+ remote + "/*"));
|
||||||
URIish uri = new URIish(db2.getDirectory().toURI().toURL());
|
remoteConfig.update(config);
|
||||||
remoteConfig.addURI(uri);
|
config.save();
|
||||||
remoteConfig.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/"
|
|
||||||
+ remote + "/*"));
|
|
||||||
remoteConfig.update(config);
|
|
||||||
config.save();
|
|
||||||
|
|
||||||
|
|
||||||
RevCommit commit2 = git.commit().setMessage("Commit to push").call();
|
RevCommit commit2 = git.commit().setMessage("Commit to push").call();
|
||||||
|
|
||||||
RefSpec spec = new RefSpec(branch + ":" + branch);
|
RefSpec spec = new RefSpec(branch + ":" + branch);
|
||||||
Iterable<PushResult> resultIterable = git.push().setRemote(remote)
|
Iterable<PushResult> resultIterable = git.push().setRemote(remote)
|
||||||
.setRefSpecs(spec).call();
|
.setRefSpecs(spec).call();
|
||||||
|
|
||||||
PushResult result = resultIterable.iterator().next();
|
PushResult result = resultIterable.iterator().next();
|
||||||
TrackingRefUpdate trackingRefUpdate = result
|
TrackingRefUpdate trackingRefUpdate = result
|
||||||
.getTrackingRefUpdate(trackingBranch);
|
.getTrackingRefUpdate(trackingBranch);
|
||||||
|
|
||||||
assertNotNull(trackingRefUpdate);
|
assertNotNull(trackingRefUpdate);
|
||||||
assertEquals(trackingBranch, trackingRefUpdate.getLocalName());
|
assertEquals(trackingBranch, trackingRefUpdate.getLocalName());
|
||||||
assertEquals(branch, trackingRefUpdate.getRemoteName());
|
assertEquals(branch, trackingRefUpdate.getRemoteName());
|
||||||
assertEquals(commit2.getId(), trackingRefUpdate.getNewObjectId());
|
assertEquals(commit2.getId(), trackingRefUpdate.getNewObjectId());
|
||||||
assertEquals(commit2.getId(), db.resolve(trackingBranch));
|
assertEquals(commit2.getId(), db.resolve(trackingBranch));
|
||||||
assertEquals(commit2.getId(), db2.resolve(branch));
|
assertEquals(commit2.getId(), db2.resolve(branch));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -208,40 +210,38 @@ public void testTrackingUpdate() throws Exception {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testPushRefUpdate() throws Exception {
|
public void testPushRefUpdate() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db);
|
||||||
Git git2 = new Git(createBareRepository());
|
Git git2 = new Git(createBareRepository())) {
|
||||||
|
final StoredConfig config = git.getRepository().getConfig();
|
||||||
|
RemoteConfig remoteConfig = new RemoteConfig(config, "test");
|
||||||
|
URIish uri = new URIish(git2.getRepository().getDirectory().toURI()
|
||||||
|
.toURL());
|
||||||
|
remoteConfig.addURI(uri);
|
||||||
|
remoteConfig.addPushRefSpec(new RefSpec("+refs/heads/*:refs/heads/*"));
|
||||||
|
remoteConfig.update(config);
|
||||||
|
config.save();
|
||||||
|
|
||||||
final StoredConfig config = git.getRepository().getConfig();
|
writeTrashFile("f", "content of f");
|
||||||
RemoteConfig remoteConfig = new RemoteConfig(config, "test");
|
git.add().addFilepattern("f").call();
|
||||||
URIish uri = new URIish(git2.getRepository().getDirectory().toURI()
|
RevCommit commit = git.commit().setMessage("adding f").call();
|
||||||
.toURL());
|
|
||||||
remoteConfig.addURI(uri);
|
|
||||||
remoteConfig.addPushRefSpec(new RefSpec("+refs/heads/*:refs/heads/*"));
|
|
||||||
remoteConfig.update(config);
|
|
||||||
config.save();
|
|
||||||
|
|
||||||
writeTrashFile("f", "content of f");
|
assertEquals(null, git2.getRepository().resolve("refs/heads/master"));
|
||||||
git.add().addFilepattern("f").call();
|
|
||||||
RevCommit commit = git.commit().setMessage("adding f").call();
|
|
||||||
|
|
||||||
assertEquals(null, git2.getRepository().resolve("refs/heads/master"));
|
|
||||||
git.push().setRemote("test").call();
|
|
||||||
assertEquals(commit.getId(),
|
|
||||||
git2.getRepository().resolve("refs/heads/master"));
|
|
||||||
|
|
||||||
git.branchCreate().setName("refs/heads/test").call();
|
|
||||||
git.checkout().setName("refs/heads/test").call();
|
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < 6; i++) {
|
|
||||||
writeTrashFile("f" + i, "content of f" + i);
|
|
||||||
git.add().addFilepattern("f" + i).call();
|
|
||||||
commit = git.commit().setMessage("adding f" + i).call();
|
|
||||||
git.push().setRemote("test").call();
|
git.push().setRemote("test").call();
|
||||||
git2.getRepository().getAllRefs();
|
assertEquals(commit.getId(),
|
||||||
assertEquals("failed to update on attempt " + i, commit.getId(),
|
git2.getRepository().resolve("refs/heads/master"));
|
||||||
git2.getRepository().resolve("refs/heads/test"));
|
|
||||||
|
|
||||||
|
git.branchCreate().setName("refs/heads/test").call();
|
||||||
|
git.checkout().setName("refs/heads/test").call();
|
||||||
|
|
||||||
|
for (int i = 0; i < 6; i++) {
|
||||||
|
writeTrashFile("f" + i, "content of f" + i);
|
||||||
|
git.add().addFilepattern("f" + i).call();
|
||||||
|
commit = git.commit().setMessage("adding f" + i).call();
|
||||||
|
git.push().setRemote("test").call();
|
||||||
|
git2.getRepository().getAllRefs();
|
||||||
|
assertEquals("failed to update on attempt " + i, commit.getId(),
|
||||||
|
git2.getRepository().resolve("refs/heads/test"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,28 +252,26 @@ public void testPushRefUpdate() throws Exception {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testPushWithRefSpecFromConfig() throws Exception {
|
public void testPushWithRefSpecFromConfig() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db);
|
||||||
Git git2 = new Git(createBareRepository());
|
Git git2 = new Git(createBareRepository())) {
|
||||||
|
final StoredConfig config = git.getRepository().getConfig();
|
||||||
final StoredConfig config = git.getRepository().getConfig();
|
RemoteConfig remoteConfig = new RemoteConfig(config, "test");
|
||||||
RemoteConfig remoteConfig = new RemoteConfig(config, "test");
|
URIish uri = new URIish(git2.getRepository().getDirectory().toURI()
|
||||||
URIish uri = new URIish(git2.getRepository().getDirectory().toURI()
|
.toURL());
|
||||||
.toURL());
|
remoteConfig.addURI(uri);
|
||||||
remoteConfig.addURI(uri);
|
remoteConfig.addPushRefSpec(new RefSpec("HEAD:refs/heads/newbranch"));
|
||||||
remoteConfig.addPushRefSpec(new RefSpec("HEAD:refs/heads/newbranch"));
|
remoteConfig.update(config);
|
||||||
remoteConfig.update(config);
|
config.save();
|
||||||
config.save();
|
|
||||||
|
|
||||||
writeTrashFile("f", "content of f");
|
|
||||||
git.add().addFilepattern("f").call();
|
|
||||||
RevCommit commit = git.commit().setMessage("adding f").call();
|
|
||||||
|
|
||||||
assertEquals(null, git2.getRepository().resolve("refs/heads/master"));
|
|
||||||
git.push().setRemote("test").call();
|
|
||||||
assertEquals(commit.getId(),
|
|
||||||
git2.getRepository().resolve("refs/heads/newbranch"));
|
|
||||||
|
|
||||||
|
writeTrashFile("f", "content of f");
|
||||||
|
git.add().addFilepattern("f").call();
|
||||||
|
RevCommit commit = git.commit().setMessage("adding f").call();
|
||||||
|
|
||||||
|
assertEquals(null, git2.getRepository().resolve("refs/heads/master"));
|
||||||
|
git.push().setRemote("test").call();
|
||||||
|
assertEquals(commit.getId(),
|
||||||
|
git2.getRepository().resolve("refs/heads/newbranch"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -283,38 +281,37 @@ public void testPushWithRefSpecFromConfig() throws Exception {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testPushWithoutPushRefSpec() throws Exception {
|
public void testPushWithoutPushRefSpec() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db);
|
||||||
Git git2 = new Git(createBareRepository());
|
Git git2 = new Git(createBareRepository())) {
|
||||||
|
final StoredConfig config = git.getRepository().getConfig();
|
||||||
|
RemoteConfig remoteConfig = new RemoteConfig(config, "test");
|
||||||
|
URIish uri = new URIish(git2.getRepository().getDirectory().toURI()
|
||||||
|
.toURL());
|
||||||
|
remoteConfig.addURI(uri);
|
||||||
|
remoteConfig.addFetchRefSpec(new RefSpec(
|
||||||
|
"+refs/heads/*:refs/remotes/origin/*"));
|
||||||
|
remoteConfig.update(config);
|
||||||
|
config.save();
|
||||||
|
|
||||||
final StoredConfig config = git.getRepository().getConfig();
|
writeTrashFile("f", "content of f");
|
||||||
RemoteConfig remoteConfig = new RemoteConfig(config, "test");
|
git.add().addFilepattern("f").call();
|
||||||
URIish uri = new URIish(git2.getRepository().getDirectory().toURI()
|
RevCommit commit = git.commit().setMessage("adding f").call();
|
||||||
.toURL());
|
|
||||||
remoteConfig.addURI(uri);
|
|
||||||
remoteConfig.addFetchRefSpec(new RefSpec(
|
|
||||||
"+refs/heads/*:refs/remotes/origin/*"));
|
|
||||||
remoteConfig.update(config);
|
|
||||||
config.save();
|
|
||||||
|
|
||||||
writeTrashFile("f", "content of f");
|
git.checkout().setName("not-pushed").setCreateBranch(true).call();
|
||||||
git.add().addFilepattern("f").call();
|
git.checkout().setName("branchtopush").setCreateBranch(true).call();
|
||||||
RevCommit commit = git.commit().setMessage("adding f").call();
|
|
||||||
|
|
||||||
git.checkout().setName("not-pushed").setCreateBranch(true).call();
|
|
||||||
git.checkout().setName("branchtopush").setCreateBranch(true).call();
|
|
||||||
|
|
||||||
assertEquals(null,
|
|
||||||
git2.getRepository().resolve("refs/heads/branchtopush"));
|
|
||||||
assertEquals(null, git2.getRepository()
|
|
||||||
.resolve("refs/heads/not-pushed"));
|
|
||||||
assertEquals(null, git2.getRepository().resolve("refs/heads/master"));
|
|
||||||
git.push().setRemote("test").call();
|
|
||||||
assertEquals(commit.getId(),
|
|
||||||
git2.getRepository().resolve("refs/heads/branchtopush"));
|
|
||||||
assertEquals(null, git2.getRepository()
|
|
||||||
.resolve("refs/heads/not-pushed"));
|
|
||||||
assertEquals(null, git2.getRepository().resolve("refs/heads/master"));
|
|
||||||
|
|
||||||
|
assertEquals(null,
|
||||||
|
git2.getRepository().resolve("refs/heads/branchtopush"));
|
||||||
|
assertEquals(null, git2.getRepository()
|
||||||
|
.resolve("refs/heads/not-pushed"));
|
||||||
|
assertEquals(null, git2.getRepository().resolve("refs/heads/master"));
|
||||||
|
git.push().setRemote("test").call();
|
||||||
|
assertEquals(commit.getId(),
|
||||||
|
git2.getRepository().resolve("refs/heads/branchtopush"));
|
||||||
|
assertEquals(null, git2.getRepository()
|
||||||
|
.resolve("refs/heads/not-pushed"));
|
||||||
|
assertEquals(null, git2.getRepository().resolve("refs/heads/master"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -335,51 +332,51 @@ public void testPushAfterGC() throws Exception {
|
||||||
remoteConfig.update(config);
|
remoteConfig.update(config);
|
||||||
config.save();
|
config.save();
|
||||||
|
|
||||||
Git git1 = new Git(db);
|
try (Git git1 = new Git(db);
|
||||||
Git git2 = new Git(db2);
|
Git git2 = new Git(db2)) {
|
||||||
|
// push master (with a new commit) to the remote
|
||||||
|
git1.commit().setMessage("initial commit").call();
|
||||||
|
|
||||||
// push master (with a new commit) to the remote
|
RefSpec spec = new RefSpec("refs/heads/*:refs/heads/*");
|
||||||
git1.commit().setMessage("initial commit").call();
|
|
||||||
|
|
||||||
RefSpec spec = new RefSpec("refs/heads/*:refs/heads/*");
|
|
||||||
git1.push().setRemote("test").setRefSpecs(spec).call();
|
|
||||||
|
|
||||||
// create an unrelated ref and a commit on our remote
|
|
||||||
git2.branchCreate().setName("refs/heads/other").call();
|
|
||||||
git2.checkout().setName("refs/heads/other").call();
|
|
||||||
|
|
||||||
writeTrashFile("a", "content of a");
|
|
||||||
git2.add().addFilepattern("a").call();
|
|
||||||
RevCommit commit2 = git2.commit().setMessage("adding a").call();
|
|
||||||
|
|
||||||
// run a gc to ensure we have a bitmap index
|
|
||||||
Properties res = git1.gc().setExpire(null).call();
|
|
||||||
assertEquals(7, res.size());
|
|
||||||
|
|
||||||
// create another commit so we have something else to push
|
|
||||||
writeTrashFile("b", "content of b");
|
|
||||||
git1.add().addFilepattern("b").call();
|
|
||||||
RevCommit commit3 = git1.commit().setMessage("adding b").call();
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Re-run the push. Failure may happen here.
|
|
||||||
git1.push().setRemote("test").setRefSpecs(spec).call();
|
git1.push().setRemote("test").setRefSpecs(spec).call();
|
||||||
} catch (TransportException e) {
|
|
||||||
assertTrue("should be caused by a MissingObjectException", e
|
|
||||||
.getCause().getCause() instanceof MissingObjectException);
|
|
||||||
fail("caught MissingObjectException for a change we don't have");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remote will have both a and b. Master will have only b
|
// create an unrelated ref and a commit on our remote
|
||||||
try {
|
git2.branchCreate().setName("refs/heads/other").call();
|
||||||
db.resolve(commit2.getId().getName() + "^{commit}");
|
git2.checkout().setName("refs/heads/other").call();
|
||||||
fail("id shouldn't exist locally");
|
|
||||||
} catch (MissingObjectException e) {
|
writeTrashFile("a", "content of a");
|
||||||
// we should get here
|
git2.add().addFilepattern("a").call();
|
||||||
|
RevCommit commit2 = git2.commit().setMessage("adding a").call();
|
||||||
|
|
||||||
|
// run a gc to ensure we have a bitmap index
|
||||||
|
Properties res = git1.gc().setExpire(null).call();
|
||||||
|
assertEquals(7, res.size());
|
||||||
|
|
||||||
|
// create another commit so we have something else to push
|
||||||
|
writeTrashFile("b", "content of b");
|
||||||
|
git1.add().addFilepattern("b").call();
|
||||||
|
RevCommit commit3 = git1.commit().setMessage("adding b").call();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Re-run the push. Failure may happen here.
|
||||||
|
git1.push().setRemote("test").setRefSpecs(spec).call();
|
||||||
|
} catch (TransportException e) {
|
||||||
|
assertTrue("should be caused by a MissingObjectException", e
|
||||||
|
.getCause().getCause() instanceof MissingObjectException);
|
||||||
|
fail("caught MissingObjectException for a change we don't have");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remote will have both a and b. Master will have only b
|
||||||
|
try {
|
||||||
|
db.resolve(commit2.getId().getName() + "^{commit}");
|
||||||
|
fail("id shouldn't exist locally");
|
||||||
|
} catch (MissingObjectException e) {
|
||||||
|
// we should get here
|
||||||
|
}
|
||||||
|
assertEquals(commit2.getId(),
|
||||||
|
db2.resolve(commit2.getId().getName() + "^{commit}"));
|
||||||
|
assertEquals(commit3.getId(),
|
||||||
|
db2.resolve(commit3.getId().getName() + "^{commit}"));
|
||||||
}
|
}
|
||||||
assertEquals(commit2.getId(),
|
|
||||||
db2.resolve(commit2.getId().getName() + "^{commit}"));
|
|
||||||
assertEquals(commit3.getId(),
|
|
||||||
db2.resolve(commit3.getId().getName() + "^{commit}"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,21 +61,22 @@ public void testDiff() throws Exception {
|
||||||
File folder = new File(db.getDirectory().getParent(), "folder");
|
File folder = new File(db.getDirectory().getParent(), "folder");
|
||||||
folder.mkdir();
|
folder.mkdir();
|
||||||
write(new File(folder, "folder.txt"), "folder");
|
write(new File(folder, "folder.txt"), "folder");
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db);
|
||||||
git.add().addFilepattern(".").call();
|
PatchIdDiffFormatter df = new PatchIdDiffFormatter()) {
|
||||||
git.commit().setMessage("Initial commit").call();
|
git.add().addFilepattern(".").call();
|
||||||
write(new File(folder, "folder.txt"), "folder change");
|
git.commit().setMessage("Initial commit").call();
|
||||||
|
write(new File(folder, "folder.txt"), "folder change");
|
||||||
|
|
||||||
PatchIdDiffFormatter df = new PatchIdDiffFormatter();
|
df.setRepository(db);
|
||||||
df.setRepository(db);
|
df.setPathFilter(PathFilter.create("folder"));
|
||||||
df.setPathFilter(PathFilter.create("folder"));
|
DirCacheIterator oldTree = new DirCacheIterator(db.readDirCache());
|
||||||
DirCacheIterator oldTree = new DirCacheIterator(db.readDirCache());
|
FileTreeIterator newTree = new FileTreeIterator(db);
|
||||||
FileTreeIterator newTree = new FileTreeIterator(db);
|
df.format(oldTree, newTree);
|
||||||
df.format(oldTree, newTree);
|
df.flush();
|
||||||
df.flush();
|
|
||||||
|
|
||||||
assertEquals("1ff64e0f9333e9b81967c3e8d7a81362b14d5441", df
|
assertEquals("1ff64e0f9333e9b81967c3e8d7a81362b14d5441", df
|
||||||
.getCalulatedPatchId().name());
|
.getCalulatedPatchId().name());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -84,37 +85,40 @@ public void testSameDiff() throws Exception {
|
||||||
File folder = new File(db.getDirectory().getParent(), "folder");
|
File folder = new File(db.getDirectory().getParent(), "folder");
|
||||||
folder.mkdir();
|
folder.mkdir();
|
||||||
write(new File(folder, "folder.txt"), "\n\n\n\nfolder");
|
write(new File(folder, "folder.txt"), "\n\n\n\nfolder");
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
git.add().addFilepattern(".").call();
|
git.add().addFilepattern(".").call();
|
||||||
git.commit().setMessage("Initial commit").call();
|
git.commit().setMessage("Initial commit").call();
|
||||||
write(new File(folder, "folder.txt"), "\n\n\n\nfolder change");
|
write(new File(folder, "folder.txt"), "\n\n\n\nfolder change");
|
||||||
|
|
||||||
PatchIdDiffFormatter df = new PatchIdDiffFormatter();
|
try (PatchIdDiffFormatter df = new PatchIdDiffFormatter()) {
|
||||||
df.setRepository(db);
|
df.setRepository(db);
|
||||||
df.setPathFilter(PathFilter.create("folder"));
|
df.setPathFilter(PathFilter.create("folder"));
|
||||||
DirCacheIterator oldTree = new DirCacheIterator(db.readDirCache());
|
DirCacheIterator oldTree = new DirCacheIterator(db.readDirCache());
|
||||||
FileTreeIterator newTree = new FileTreeIterator(db);
|
FileTreeIterator newTree = new FileTreeIterator(db);
|
||||||
df.format(oldTree, newTree);
|
df.format(oldTree, newTree);
|
||||||
df.flush();
|
df.flush();
|
||||||
|
|
||||||
assertEquals("08fca5ac531383eb1da8bf6b6f7cf44411281407", df
|
assertEquals("08fca5ac531383eb1da8bf6b6f7cf44411281407", df
|
||||||
.getCalulatedPatchId().name());
|
.getCalulatedPatchId().name());
|
||||||
|
}
|
||||||
|
|
||||||
write(new File(folder, "folder.txt"), "a\n\n\n\nfolder");
|
write(new File(folder, "folder.txt"), "a\n\n\n\nfolder");
|
||||||
git.add().addFilepattern(".").call();
|
git.add().addFilepattern(".").call();
|
||||||
git.commit().setMessage("Initial commit").call();
|
git.commit().setMessage("Initial commit").call();
|
||||||
write(new File(folder, "folder.txt"), "a\n\n\n\nfolder change");
|
write(new File(folder, "folder.txt"), "a\n\n\n\nfolder change");
|
||||||
|
|
||||||
df = new PatchIdDiffFormatter();
|
try (PatchIdDiffFormatter df = new PatchIdDiffFormatter()) {
|
||||||
df.setRepository(db);
|
df.setRepository(db);
|
||||||
df.setPathFilter(PathFilter.create("folder"));
|
df.setPathFilter(PathFilter.create("folder"));
|
||||||
oldTree = new DirCacheIterator(db.readDirCache());
|
DirCacheIterator oldTree = new DirCacheIterator(db.readDirCache());
|
||||||
newTree = new FileTreeIterator(db);
|
FileTreeIterator newTree = new FileTreeIterator(db);
|
||||||
df.format(oldTree, newTree);
|
df.format(oldTree, newTree);
|
||||||
df.flush();
|
df.flush();
|
||||||
|
|
||||||
assertEquals("08fca5ac531383eb1da8bf6b6f7cf44411281407", df
|
assertEquals("08fca5ac531383eb1da8bf6b6f7cf44411281407", df
|
||||||
.getCalulatedPatchId().name());
|
.getCalulatedPatchId().name());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,38 +82,42 @@ public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
defaultDb = createWorkRepository();
|
defaultDb = createWorkRepository();
|
||||||
Git git = new Git(defaultDb);
|
try (Git git = new Git(defaultDb)) {
|
||||||
JGitTestUtil.writeTrashFile(defaultDb, "hello.txt", "branch world");
|
JGitTestUtil.writeTrashFile(defaultDb, "hello.txt", "branch world");
|
||||||
git.add().addFilepattern("hello.txt").call();
|
git.add().addFilepattern("hello.txt").call();
|
||||||
oldCommitId = git.commit().setMessage("Initial commit").call().getId();
|
oldCommitId = git.commit().setMessage("Initial commit").call().getId();
|
||||||
git.checkout().setName(BRANCH).setCreateBranch(true).call();
|
git.checkout().setName(BRANCH).setCreateBranch(true).call();
|
||||||
git.checkout().setName("master").call();
|
git.checkout().setName("master").call();
|
||||||
git.tag().setName(TAG).call();
|
git.tag().setName(TAG).call();
|
||||||
JGitTestUtil.writeTrashFile(defaultDb, "hello.txt", "master world");
|
JGitTestUtil.writeTrashFile(defaultDb, "hello.txt", "master world");
|
||||||
git.add().addFilepattern("hello.txt").call();
|
git.add().addFilepattern("hello.txt").call();
|
||||||
git.commit().setMessage("Second commit").call();
|
git.commit().setMessage("Second commit").call();
|
||||||
addRepoToClose(defaultDb);
|
addRepoToClose(defaultDb);
|
||||||
|
}
|
||||||
|
|
||||||
notDefaultDb = createWorkRepository();
|
notDefaultDb = createWorkRepository();
|
||||||
git = new Git(notDefaultDb);
|
try (Git git = new Git(notDefaultDb)) {
|
||||||
JGitTestUtil.writeTrashFile(notDefaultDb, "world.txt", "hello");
|
JGitTestUtil.writeTrashFile(notDefaultDb, "world.txt", "hello");
|
||||||
git.add().addFilepattern("world.txt").call();
|
git.add().addFilepattern("world.txt").call();
|
||||||
git.commit().setMessage("Initial commit").call();
|
git.commit().setMessage("Initial commit").call();
|
||||||
addRepoToClose(notDefaultDb);
|
addRepoToClose(notDefaultDb);
|
||||||
|
}
|
||||||
|
|
||||||
groupADb = createWorkRepository();
|
groupADb = createWorkRepository();
|
||||||
git = new Git(groupADb);
|
try (Git git = new Git(groupADb)) {
|
||||||
JGitTestUtil.writeTrashFile(groupADb, "a.txt", "world");
|
JGitTestUtil.writeTrashFile(groupADb, "a.txt", "world");
|
||||||
git.add().addFilepattern("a.txt").call();
|
git.add().addFilepattern("a.txt").call();
|
||||||
git.commit().setMessage("Initial commit").call();
|
git.commit().setMessage("Initial commit").call();
|
||||||
addRepoToClose(groupADb);
|
addRepoToClose(groupADb);
|
||||||
|
}
|
||||||
|
|
||||||
groupBDb = createWorkRepository();
|
groupBDb = createWorkRepository();
|
||||||
git = new Git(groupBDb);
|
try (Git git = new Git(groupBDb)) {
|
||||||
JGitTestUtil.writeTrashFile(groupBDb, "b.txt", "world");
|
JGitTestUtil.writeTrashFile(groupBDb, "b.txt", "world");
|
||||||
git.add().addFilepattern("b.txt").call();
|
git.add().addFilepattern("b.txt").call();
|
||||||
git.commit().setMessage("Initial commit").call();
|
git.commit().setMessage("Initial commit").call();
|
||||||
addRepoToClose(groupBDb);
|
addRepoToClose(groupBDb);
|
||||||
|
}
|
||||||
|
|
||||||
resolveRelativeUris();
|
resolveRelativeUris();
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,18 +62,18 @@ public void testConcurrentInsertionOfBlobsToTheSameNewFanOutDirectory()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
ExecutorService e = Executors.newCachedThreadPool();
|
ExecutorService e = Executors.newCachedThreadPool();
|
||||||
for (int i=0; i < 100; ++i) {
|
for (int i=0; i < 100; ++i) {
|
||||||
ObjectDirectory db = createBareRepository().getObjectDatabase();
|
ObjectDirectory dir = createBareRepository().getObjectDatabase();
|
||||||
for (Future f : e.invokeAll(blobInsertersForTheSameFanOutDir(db))) {
|
for (Future f : e.invokeAll(blobInsertersForTheSameFanOutDir(dir))) {
|
||||||
f.get();
|
f.get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Collection<Callable<ObjectId>> blobInsertersForTheSameFanOutDir(
|
private Collection<Callable<ObjectId>> blobInsertersForTheSameFanOutDir(
|
||||||
final ObjectDirectory db) {
|
final ObjectDirectory dir) {
|
||||||
Callable<ObjectId> callable = new Callable<ObjectId>() {
|
Callable<ObjectId> callable = new Callable<ObjectId>() {
|
||||||
public ObjectId call() throws Exception {
|
public ObjectId call() throws Exception {
|
||||||
return db.newInserter().insert(Constants.OBJ_BLOB, new byte[0]);
|
return dir.newInserter().insert(Constants.OBJ_BLOB, new byte[0]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return Collections.nCopies(4, callable);
|
return Collections.nCopies(4, callable);
|
||||||
|
|
|
@ -342,12 +342,13 @@ public void testWritePack3() throws MissingObjectException, IOException {
|
||||||
ObjectId.fromString("902d5476fa249b7abc9d84c611577a81381f0327"),
|
ObjectId.fromString("902d5476fa249b7abc9d84c611577a81381f0327"),
|
||||||
ObjectId.fromString("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259"),
|
ObjectId.fromString("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259"),
|
||||||
ObjectId.fromString("6ff87c4664981e4397625791c8ea3bbb5f2279a3") };
|
ObjectId.fromString("6ff87c4664981e4397625791c8ea3bbb5f2279a3") };
|
||||||
final RevWalk parser = new RevWalk(db);
|
try (final RevWalk parser = new RevWalk(db)) {
|
||||||
final RevObject forcedOrderRevs[] = new RevObject[forcedOrder.length];
|
final RevObject forcedOrderRevs[] = new RevObject[forcedOrder.length];
|
||||||
for (int i = 0; i < forcedOrder.length; i++)
|
for (int i = 0; i < forcedOrder.length; i++)
|
||||||
forcedOrderRevs[i] = parser.parseAny(forcedOrder[i]);
|
forcedOrderRevs[i] = parser.parseAny(forcedOrder[i]);
|
||||||
|
|
||||||
createVerifyOpenPack(Arrays.asList(forcedOrderRevs));
|
createVerifyOpenPack(Arrays.asList(forcedOrderRevs));
|
||||||
|
}
|
||||||
|
|
||||||
assertEquals(forcedOrder.length, writer.getObjectCount());
|
assertEquals(forcedOrder.length, writer.getObjectCount());
|
||||||
verifyObjectsOrder(forcedOrder);
|
verifyObjectsOrder(forcedOrder);
|
||||||
|
|
|
@ -1444,8 +1444,8 @@ public void start(int totalTasks) {
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
public void beginTask(String title, int totalWork) {
|
public void beginTask(String title, int total) {
|
||||||
this.totalWork = totalWork;
|
this.totalWork = total;
|
||||||
lastWork = 0;
|
lastWork = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -82,38 +82,42 @@ public void testIterator() throws IllegalStateException, IOException,
|
||||||
}
|
}
|
||||||
FileTreeIteratorWithTimeControl fileIt = new FileTreeIteratorWithTimeControl(
|
FileTreeIteratorWithTimeControl fileIt = new FileTreeIteratorWithTimeControl(
|
||||||
db, modTimes);
|
db, modTimes);
|
||||||
NameConflictTreeWalk tw = new NameConflictTreeWalk(db);
|
try (NameConflictTreeWalk tw = new NameConflictTreeWalk(db)) {
|
||||||
tw.addTree(fileIt);
|
tw.addTree(fileIt);
|
||||||
tw.setRecursive(true);
|
tw.setRecursive(true);
|
||||||
FileTreeIterator t;
|
FileTreeIterator t;
|
||||||
long t0 = 0;
|
long t0 = 0;
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
assertTrue(tw.next());
|
assertTrue(tw.next());
|
||||||
t = tw.getTree(0, FileTreeIterator.class);
|
t = tw.getTree(0, FileTreeIterator.class);
|
||||||
if (i == 0)
|
if (i == 0) {
|
||||||
t0 = t.getEntryLastModified();
|
t0 = t.getEntryLastModified();
|
||||||
else
|
} else {
|
||||||
assertEquals(t0, t.getEntryLastModified());
|
assertEquals(t0, t.getEntryLastModified());
|
||||||
}
|
}
|
||||||
long t1 = 0;
|
}
|
||||||
for (int i = 0; i < 10; i++) {
|
long t1 = 0;
|
||||||
assertTrue(tw.next());
|
for (int i = 0; i < 10; i++) {
|
||||||
t = tw.getTree(0, FileTreeIterator.class);
|
assertTrue(tw.next());
|
||||||
if (i == 0) {
|
t = tw.getTree(0, FileTreeIterator.class);
|
||||||
t1 = t.getEntryLastModified();
|
if (i == 0) {
|
||||||
assertTrue(t1 > t0);
|
t1 = t.getEntryLastModified();
|
||||||
} else
|
assertTrue(t1 > t0);
|
||||||
assertEquals(t1, t.getEntryLastModified());
|
} else {
|
||||||
}
|
assertEquals(t1, t.getEntryLastModified());
|
||||||
long t2 = 0;
|
}
|
||||||
for (int i = 0; i < 10; i++) {
|
}
|
||||||
assertTrue(tw.next());
|
long t2 = 0;
|
||||||
t = tw.getTree(0, FileTreeIterator.class);
|
for (int i = 0; i < 10; i++) {
|
||||||
if (i == 0) {
|
assertTrue(tw.next());
|
||||||
t2 = t.getEntryLastModified();
|
t = tw.getTree(0, FileTreeIterator.class);
|
||||||
assertTrue(t2 > t1);
|
if (i == 0) {
|
||||||
} else
|
t2 = t.getEntryLastModified();
|
||||||
assertEquals(t2, t.getEntryLastModified());
|
assertTrue(t2 > t1);
|
||||||
|
} else {
|
||||||
|
assertEquals(t2, t.getEntryLastModified());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,8 +70,7 @@ public void testlogAllRefUpdates() throws Exception {
|
||||||
|
|
||||||
// do one commit and check that reflog size is 0: no reflogs should be
|
// do one commit and check that reflog size is 0: no reflogs should be
|
||||||
// written
|
// written
|
||||||
commit("A Commit\n", new PersonIdent(author, commitTime, tz),
|
commit("A Commit\n", commitTime, tz);
|
||||||
new PersonIdent(committer, commitTime, tz));
|
|
||||||
commitTime += 60 * 1000;
|
commitTime += 60 * 1000;
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"Reflog for HEAD still contain no entry",
|
"Reflog for HEAD still contain no entry",
|
||||||
|
@ -83,8 +82,7 @@ public void testlogAllRefUpdates() throws Exception {
|
||||||
assertTrue(cfg.get(CoreConfig.KEY).isLogAllRefUpdates());
|
assertTrue(cfg.get(CoreConfig.KEY).isLogAllRefUpdates());
|
||||||
|
|
||||||
// do one commit and check that reflog size is increased to 1
|
// do one commit and check that reflog size is increased to 1
|
||||||
commit("A Commit\n", new PersonIdent(author, commitTime, tz),
|
commit("A Commit\n", commitTime, tz);
|
||||||
new PersonIdent(committer, commitTime, tz));
|
|
||||||
commitTime += 60 * 1000;
|
commitTime += 60 * 1000;
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"Reflog for HEAD should contain one entry",
|
"Reflog for HEAD should contain one entry",
|
||||||
|
@ -96,18 +94,17 @@ public void testlogAllRefUpdates() throws Exception {
|
||||||
assertFalse(cfg.get(CoreConfig.KEY).isLogAllRefUpdates());
|
assertFalse(cfg.get(CoreConfig.KEY).isLogAllRefUpdates());
|
||||||
|
|
||||||
// do one commit and check that reflog size is 2
|
// do one commit and check that reflog size is 2
|
||||||
commit("A Commit\n", new PersonIdent(author, commitTime, tz),
|
commit("A Commit\n", commitTime, tz);
|
||||||
new PersonIdent(committer, commitTime, tz));
|
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"Reflog for HEAD should contain two entries",
|
"Reflog for HEAD should contain two entries",
|
||||||
db.getReflogReader(Constants.HEAD).getReverseEntries().size() == 2);
|
db.getReflogReader(Constants.HEAD).getReverseEntries().size() == 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void commit(String commitMsg, PersonIdent author,
|
private void commit(String commitMsg, long commitTime, int tz)
|
||||||
PersonIdent committer) throws IOException {
|
throws IOException {
|
||||||
final CommitBuilder commit = new CommitBuilder();
|
final CommitBuilder commit = new CommitBuilder();
|
||||||
commit.setAuthor(author);
|
commit.setAuthor(new PersonIdent(author, commitTime, tz));
|
||||||
commit.setCommitter(committer);
|
commit.setCommitter(new PersonIdent(committer, commitTime, tz));
|
||||||
commit.setMessage(commitMsg);
|
commit.setMessage(commitMsg);
|
||||||
ObjectId id;
|
ObjectId id;
|
||||||
try (ObjectInserter inserter = db.newObjectInserter()) {
|
try (ObjectInserter inserter = db.newObjectInserter()) {
|
||||||
|
|
|
@ -60,117 +60,123 @@ public class ReflogResolveTest extends RepositoryTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveMasterCommits() throws Exception {
|
public void resolveMasterCommits() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
writeTrashFile("file.txt", "content");
|
writeTrashFile("file.txt", "content");
|
||||||
git.add().addFilepattern("file.txt").call();
|
git.add().addFilepattern("file.txt").call();
|
||||||
RevCommit c1 = git.commit().setMessage("create file").call();
|
RevCommit c1 = git.commit().setMessage("create file").call();
|
||||||
writeTrashFile("file.txt", "content2");
|
writeTrashFile("file.txt", "content2");
|
||||||
git.add().addFilepattern("file.txt").call();
|
git.add().addFilepattern("file.txt").call();
|
||||||
RevCommit c2 = git.commit().setMessage("edit file").call();
|
RevCommit c2 = git.commit().setMessage("edit file").call();
|
||||||
|
|
||||||
assertEquals(c2, db.resolve("master@{0}"));
|
assertEquals(c2, db.resolve("master@{0}"));
|
||||||
assertEquals(c1, db.resolve("master@{1}"));
|
assertEquals(c1, db.resolve("master@{1}"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveUnnamedCurrentBranchCommits() throws Exception {
|
public void resolveUnnamedCurrentBranchCommits() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
writeTrashFile("file.txt", "content");
|
writeTrashFile("file.txt", "content");
|
||||||
git.add().addFilepattern("file.txt").call();
|
git.add().addFilepattern("file.txt").call();
|
||||||
RevCommit c1 = git.commit().setMessage("create file").call();
|
RevCommit c1 = git.commit().setMessage("create file").call();
|
||||||
writeTrashFile("file.txt", "content2");
|
writeTrashFile("file.txt", "content2");
|
||||||
git.add().addFilepattern("file.txt").call();
|
git.add().addFilepattern("file.txt").call();
|
||||||
RevCommit c2 = git.commit().setMessage("edit file").call();
|
RevCommit c2 = git.commit().setMessage("edit file").call();
|
||||||
|
|
||||||
assertEquals(c2, db.resolve("master@{0}"));
|
assertEquals(c2, db.resolve("master@{0}"));
|
||||||
assertEquals(c1, db.resolve("master@{1}"));
|
assertEquals(c1, db.resolve("master@{1}"));
|
||||||
|
|
||||||
git.checkout().setCreateBranch(true).setName("newbranch")
|
git.checkout().setCreateBranch(true).setName("newbranch")
|
||||||
.setStartPoint(c1).call();
|
.setStartPoint(c1).call();
|
||||||
|
|
||||||
// same as current branch, e.g. master
|
// same as current branch, e.g. master
|
||||||
assertEquals(c1, db.resolve("@{0}"));
|
assertEquals(c1, db.resolve("@{0}"));
|
||||||
try {
|
try {
|
||||||
|
assertEquals(c1, db.resolve("@{1}"));
|
||||||
|
fail(); // Looking at wrong ref, e.g HEAD
|
||||||
|
} catch (RevisionSyntaxException e) {
|
||||||
|
assertNotNull(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// detached head, read HEAD reflog
|
||||||
|
git.checkout().setName(c2.getName()).call();
|
||||||
|
assertEquals(c2, db.resolve("@{0}"));
|
||||||
assertEquals(c1, db.resolve("@{1}"));
|
assertEquals(c1, db.resolve("@{1}"));
|
||||||
fail(); // Looking at wrong ref, e.g HEAD
|
assertEquals(c2, db.resolve("@{2}"));
|
||||||
} catch (RevisionSyntaxException e) {
|
|
||||||
assertNotNull(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// detached head, read HEAD reflog
|
|
||||||
git.checkout().setName(c2.getName()).call();
|
|
||||||
assertEquals(c2, db.resolve("@{0}"));
|
|
||||||
assertEquals(c1, db.resolve("@{1}"));
|
|
||||||
assertEquals(c2, db.resolve("@{2}"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveReflogParent() throws Exception {
|
public void resolveReflogParent() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
writeTrashFile("file.txt", "content");
|
writeTrashFile("file.txt", "content");
|
||||||
git.add().addFilepattern("file.txt").call();
|
git.add().addFilepattern("file.txt").call();
|
||||||
RevCommit c1 = git.commit().setMessage("create file").call();
|
RevCommit c1 = git.commit().setMessage("create file").call();
|
||||||
writeTrashFile("file.txt", "content2");
|
writeTrashFile("file.txt", "content2");
|
||||||
git.add().addFilepattern("file.txt").call();
|
git.add().addFilepattern("file.txt").call();
|
||||||
git.commit().setMessage("edit file").call();
|
git.commit().setMessage("edit file").call();
|
||||||
|
|
||||||
assertEquals(c1, db.resolve("master@{0}~1"));
|
assertEquals(c1, db.resolve("master@{0}~1"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveNonExistingBranch() throws Exception {
|
public void resolveNonExistingBranch() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
writeTrashFile("file.txt", "content");
|
writeTrashFile("file.txt", "content");
|
||||||
git.add().addFilepattern("file.txt").call();
|
git.add().addFilepattern("file.txt").call();
|
||||||
git.commit().setMessage("create file").call();
|
git.commit().setMessage("create file").call();
|
||||||
assertNull(db.resolve("notabranch@{7}"));
|
assertNull(db.resolve("notabranch@{7}"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolvePreviousBranch() throws Exception {
|
public void resolvePreviousBranch() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
writeTrashFile("file.txt", "content");
|
writeTrashFile("file.txt", "content");
|
||||||
git.add().addFilepattern("file.txt").call();
|
git.add().addFilepattern("file.txt").call();
|
||||||
RevCommit c1 = git.commit().setMessage("create file").call();
|
RevCommit c1 = git.commit().setMessage("create file").call();
|
||||||
writeTrashFile("file.txt", "content2");
|
writeTrashFile("file.txt", "content2");
|
||||||
git.add().addFilepattern("file.txt").call();
|
git.add().addFilepattern("file.txt").call();
|
||||||
RevCommit c2 = git.commit().setMessage("edit file").call();
|
RevCommit c2 = git.commit().setMessage("edit file").call();
|
||||||
|
|
||||||
git.checkout().setCreateBranch(true).setName("newbranch")
|
git.checkout().setCreateBranch(true).setName("newbranch")
|
||||||
.setStartPoint(c1).call();
|
.setStartPoint(c1).call();
|
||||||
|
|
||||||
git.checkout().setName(c1.getName()).call();
|
git.checkout().setName(c1.getName()).call();
|
||||||
|
|
||||||
git.checkout().setName("master").call();
|
git.checkout().setName("master").call();
|
||||||
|
|
||||||
assertEquals(c1.getName(), db.simplify("@{-1}"));
|
assertEquals(c1.getName(), db.simplify("@{-1}"));
|
||||||
assertEquals("newbranch", db.simplify("@{-2}"));
|
assertEquals("newbranch", db.simplify("@{-2}"));
|
||||||
assertEquals("master", db.simplify("@{-3}"));
|
assertEquals("master", db.simplify("@{-3}"));
|
||||||
|
|
||||||
// chained expression
|
// chained expression
|
||||||
try {
|
try {
|
||||||
// Cannot refer to reflog of detached head
|
// Cannot refer to reflog of detached head
|
||||||
db.resolve("@{-1}@{0}");
|
db.resolve("@{-1}@{0}");
|
||||||
fail();
|
fail();
|
||||||
} catch (RevisionSyntaxException e) {
|
} catch (RevisionSyntaxException e) {
|
||||||
// good
|
// good
|
||||||
|
}
|
||||||
|
assertEquals(c1.getName(), db.resolve("@{-2}@{0}").getName());
|
||||||
|
|
||||||
|
assertEquals(c2.getName(), db.resolve("@{-3}@{0}").getName());
|
||||||
}
|
}
|
||||||
assertEquals(c1.getName(), db.resolve("@{-2}@{0}").getName());
|
|
||||||
|
|
||||||
assertEquals(c2.getName(), db.resolve("@{-3}@{0}").getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveDate() throws Exception {
|
public void resolveDate() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
writeTrashFile("file.txt", "content");
|
writeTrashFile("file.txt", "content");
|
||||||
git.add().addFilepattern("file.txt").call();
|
git.add().addFilepattern("file.txt").call();
|
||||||
git.commit().setMessage("create file").call();
|
git.commit().setMessage("create file").call();
|
||||||
try {
|
try {
|
||||||
db.resolve("master@{yesterday}");
|
db.resolve("master@{yesterday}");
|
||||||
fail("Exception not thrown");
|
fail("Exception not thrown");
|
||||||
} catch (RevisionSyntaxException e) {
|
} catch (RevisionSyntaxException e) {
|
||||||
assertNotNull(e);
|
assertNotNull(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -872,32 +872,31 @@ private boolean validateStates(IndexState indexState,
|
||||||
|
|
||||||
private String contentAsString(Repository r, ObjectId treeId, String path)
|
private String contentAsString(Repository r, ObjectId treeId, String path)
|
||||||
throws MissingObjectException, IOException {
|
throws MissingObjectException, IOException {
|
||||||
TreeWalk tw = new TreeWalk(r);
|
AnyObjectId blobId;
|
||||||
tw.addTree(treeId);
|
try (TreeWalk tw = new TreeWalk(r)) {
|
||||||
tw.setFilter(PathFilter.create(path));
|
tw.addTree(treeId);
|
||||||
tw.setRecursive(true);
|
tw.setFilter(PathFilter.create(path));
|
||||||
if (!tw.next())
|
tw.setRecursive(true);
|
||||||
return null;
|
if (!tw.next()) {
|
||||||
AnyObjectId blobId = tw.getObjectId(0);
|
return null;
|
||||||
|
}
|
||||||
|
blobId = tw.getObjectId(0);
|
||||||
|
}
|
||||||
|
|
||||||
StringBuilder result = new StringBuilder();
|
StringBuilder result = new StringBuilder();
|
||||||
BufferedReader br = null;
|
|
||||||
ObjectReader or = r.newObjectReader();
|
ObjectReader or = r.newObjectReader();
|
||||||
try {
|
try (BufferedReader br = new BufferedReader(
|
||||||
br = new BufferedReader(new InputStreamReader(or.open(blobId)
|
new InputStreamReader(or.open(blobId).openStream()))) {
|
||||||
.openStream()));
|
|
||||||
String line;
|
String line;
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
while ((line = br.readLine()) != null) {
|
while ((line = br.readLine()) != null) {
|
||||||
if (!first)
|
if (!first) {
|
||||||
result.append('\n');
|
result.append('\n');
|
||||||
|
}
|
||||||
result.append(line);
|
result.append(line);
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
return result.toString();
|
return result.toString();
|
||||||
} finally {
|
|
||||||
if (br != null)
|
|
||||||
br.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -403,10 +403,12 @@ public void testLeafSplitsWhenFull() throws Exception {
|
||||||
}
|
}
|
||||||
|
|
||||||
RevCommit n = commitNoteMap(map);
|
RevCommit n = commitNoteMap(map);
|
||||||
TreeWalk tw = new TreeWalk(reader);
|
try (TreeWalk tw = new TreeWalk(reader)) {
|
||||||
tw.reset(n.getTree());
|
tw.reset(n.getTree());
|
||||||
while (tw.next())
|
while (tw.next()) {
|
||||||
assertFalse("no fan-out subtree", tw.isSubtree());
|
assertFalse("no fan-out subtree", tw.isSubtree());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 254; i < 256; i++) {
|
for (int i = 254; i < 256; i++) {
|
||||||
idBuf.setByte(Constants.OBJECT_ID_LENGTH - 1, i);
|
idBuf.setByte(Constants.OBJECT_ID_LENGTH - 1, i);
|
||||||
|
@ -418,13 +420,15 @@ public void testLeafSplitsWhenFull() throws Exception {
|
||||||
|
|
||||||
// The 00 bucket is fully split.
|
// The 00 bucket is fully split.
|
||||||
String path = fanout(38, idBuf.name());
|
String path = fanout(38, idBuf.name());
|
||||||
tw = TreeWalk.forPath(reader, path, n.getTree());
|
try (TreeWalk tw = TreeWalk.forPath(reader, path, n.getTree())) {
|
||||||
assertNotNull("has " + path, tw);
|
assertNotNull("has " + path, tw);
|
||||||
|
}
|
||||||
|
|
||||||
// The other bucket is not.
|
// The other bucket is not.
|
||||||
path = fanout(2, data1.name());
|
path = fanout(2, data1.name());
|
||||||
tw = TreeWalk.forPath(reader, path, n.getTree());
|
try (TreeWalk tw = TreeWalk.forPath(reader, path, n.getTree())) {
|
||||||
assertNotNull("has " + path, tw);
|
assertNotNull("has " + path, tw);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -60,124 +60,124 @@
|
||||||
public class PostOrderTreeWalkTest extends RepositoryTestCase {
|
public class PostOrderTreeWalkTest extends RepositoryTestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testInitialize_NoPostOrder() throws Exception {
|
public void testInitialize_NoPostOrder() throws Exception {
|
||||||
final TreeWalk tw = new TreeWalk(db);
|
try (final TreeWalk tw = new TreeWalk(db)) {
|
||||||
assertFalse(tw.isPostOrderTraversal());
|
assertFalse(tw.isPostOrderTraversal());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInitialize_TogglePostOrder() throws Exception {
|
public void testInitialize_TogglePostOrder() throws Exception {
|
||||||
final TreeWalk tw = new TreeWalk(db);
|
try (final TreeWalk tw = new TreeWalk(db)) {
|
||||||
assertFalse(tw.isPostOrderTraversal());
|
assertFalse(tw.isPostOrderTraversal());
|
||||||
tw.setPostOrderTraversal(true);
|
tw.setPostOrderTraversal(true);
|
||||||
assertTrue(tw.isPostOrderTraversal());
|
assertTrue(tw.isPostOrderTraversal());
|
||||||
tw.setPostOrderTraversal(false);
|
tw.setPostOrderTraversal(false);
|
||||||
assertFalse(tw.isPostOrderTraversal());
|
assertFalse(tw.isPostOrderTraversal());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResetDoesNotAffectPostOrder() throws Exception {
|
public void testResetDoesNotAffectPostOrder() throws Exception {
|
||||||
final TreeWalk tw = new TreeWalk(db);
|
try (final TreeWalk tw = new TreeWalk(db)) {
|
||||||
tw.setPostOrderTraversal(true);
|
tw.setPostOrderTraversal(true);
|
||||||
assertTrue(tw.isPostOrderTraversal());
|
assertTrue(tw.isPostOrderTraversal());
|
||||||
tw.reset();
|
tw.reset();
|
||||||
assertTrue(tw.isPostOrderTraversal());
|
assertTrue(tw.isPostOrderTraversal());
|
||||||
|
|
||||||
tw.setPostOrderTraversal(false);
|
tw.setPostOrderTraversal(false);
|
||||||
assertFalse(tw.isPostOrderTraversal());
|
assertFalse(tw.isPostOrderTraversal());
|
||||||
tw.reset();
|
tw.reset();
|
||||||
assertFalse(tw.isPostOrderTraversal());
|
assertFalse(tw.isPostOrderTraversal());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoPostOrder() throws Exception {
|
public void testNoPostOrder() throws Exception {
|
||||||
final DirCache tree = db.readDirCache();
|
final DirCache tree = db.readDirCache();
|
||||||
{
|
final DirCacheBuilder b = tree.builder();
|
||||||
final DirCacheBuilder b = tree.builder();
|
|
||||||
|
|
||||||
b.add(makeFile("a"));
|
b.add(makeFile("a"));
|
||||||
b.add(makeFile("b/c"));
|
b.add(makeFile("b/c"));
|
||||||
b.add(makeFile("b/d"));
|
b.add(makeFile("b/d"));
|
||||||
b.add(makeFile("q"));
|
b.add(makeFile("q"));
|
||||||
|
|
||||||
b.finish();
|
b.finish();
|
||||||
assertEquals(4, tree.getEntryCount());
|
assertEquals(4, tree.getEntryCount());
|
||||||
|
|
||||||
|
try (final TreeWalk tw = new TreeWalk(db)) {
|
||||||
|
tw.setPostOrderTraversal(false);
|
||||||
|
tw.addTree(new DirCacheIterator(tree));
|
||||||
|
|
||||||
|
assertModes("a", REGULAR_FILE, tw);
|
||||||
|
assertModes("b", TREE, tw);
|
||||||
|
assertTrue(tw.isSubtree());
|
||||||
|
assertFalse(tw.isPostChildren());
|
||||||
|
tw.enterSubtree();
|
||||||
|
assertModes("b/c", REGULAR_FILE, tw);
|
||||||
|
assertModes("b/d", REGULAR_FILE, tw);
|
||||||
|
assertModes("q", REGULAR_FILE, tw);
|
||||||
}
|
}
|
||||||
|
|
||||||
final TreeWalk tw = new TreeWalk(db);
|
|
||||||
tw.setPostOrderTraversal(false);
|
|
||||||
tw.addTree(new DirCacheIterator(tree));
|
|
||||||
|
|
||||||
assertModes("a", REGULAR_FILE, tw);
|
|
||||||
assertModes("b", TREE, tw);
|
|
||||||
assertTrue(tw.isSubtree());
|
|
||||||
assertFalse(tw.isPostChildren());
|
|
||||||
tw.enterSubtree();
|
|
||||||
assertModes("b/c", REGULAR_FILE, tw);
|
|
||||||
assertModes("b/d", REGULAR_FILE, tw);
|
|
||||||
assertModes("q", REGULAR_FILE, tw);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWithPostOrder_EnterSubtree() throws Exception {
|
public void testWithPostOrder_EnterSubtree() throws Exception {
|
||||||
final DirCache tree = db.readDirCache();
|
final DirCache tree = db.readDirCache();
|
||||||
{
|
final DirCacheBuilder b = tree.builder();
|
||||||
final DirCacheBuilder b = tree.builder();
|
|
||||||
|
|
||||||
b.add(makeFile("a"));
|
b.add(makeFile("a"));
|
||||||
b.add(makeFile("b/c"));
|
b.add(makeFile("b/c"));
|
||||||
b.add(makeFile("b/d"));
|
b.add(makeFile("b/d"));
|
||||||
b.add(makeFile("q"));
|
b.add(makeFile("q"));
|
||||||
|
|
||||||
b.finish();
|
b.finish();
|
||||||
assertEquals(4, tree.getEntryCount());
|
assertEquals(4, tree.getEntryCount());
|
||||||
|
|
||||||
|
try (final TreeWalk tw = new TreeWalk(db)) {
|
||||||
|
tw.setPostOrderTraversal(true);
|
||||||
|
tw.addTree(new DirCacheIterator(tree));
|
||||||
|
|
||||||
|
assertModes("a", REGULAR_FILE, tw);
|
||||||
|
|
||||||
|
assertModes("b", TREE, tw);
|
||||||
|
assertTrue(tw.isSubtree());
|
||||||
|
assertFalse(tw.isPostChildren());
|
||||||
|
tw.enterSubtree();
|
||||||
|
assertModes("b/c", REGULAR_FILE, tw);
|
||||||
|
assertModes("b/d", REGULAR_FILE, tw);
|
||||||
|
|
||||||
|
assertModes("b", TREE, tw);
|
||||||
|
assertTrue(tw.isSubtree());
|
||||||
|
assertTrue(tw.isPostChildren());
|
||||||
|
|
||||||
|
assertModes("q", REGULAR_FILE, tw);
|
||||||
}
|
}
|
||||||
|
|
||||||
final TreeWalk tw = new TreeWalk(db);
|
|
||||||
tw.setPostOrderTraversal(true);
|
|
||||||
tw.addTree(new DirCacheIterator(tree));
|
|
||||||
|
|
||||||
assertModes("a", REGULAR_FILE, tw);
|
|
||||||
|
|
||||||
assertModes("b", TREE, tw);
|
|
||||||
assertTrue(tw.isSubtree());
|
|
||||||
assertFalse(tw.isPostChildren());
|
|
||||||
tw.enterSubtree();
|
|
||||||
assertModes("b/c", REGULAR_FILE, tw);
|
|
||||||
assertModes("b/d", REGULAR_FILE, tw);
|
|
||||||
|
|
||||||
assertModes("b", TREE, tw);
|
|
||||||
assertTrue(tw.isSubtree());
|
|
||||||
assertTrue(tw.isPostChildren());
|
|
||||||
|
|
||||||
assertModes("q", REGULAR_FILE, tw);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWithPostOrder_NoEnterSubtree() throws Exception {
|
public void testWithPostOrder_NoEnterSubtree() throws Exception {
|
||||||
final DirCache tree = db.readDirCache();
|
final DirCache tree = db.readDirCache();
|
||||||
{
|
final DirCacheBuilder b = tree.builder();
|
||||||
final DirCacheBuilder b = tree.builder();
|
|
||||||
|
|
||||||
b.add(makeFile("a"));
|
b.add(makeFile("a"));
|
||||||
b.add(makeFile("b/c"));
|
b.add(makeFile("b/c"));
|
||||||
b.add(makeFile("b/d"));
|
b.add(makeFile("b/d"));
|
||||||
b.add(makeFile("q"));
|
b.add(makeFile("q"));
|
||||||
|
|
||||||
b.finish();
|
b.finish();
|
||||||
assertEquals(4, tree.getEntryCount());
|
assertEquals(4, tree.getEntryCount());
|
||||||
|
|
||||||
|
try (final TreeWalk tw = new TreeWalk(db)) {
|
||||||
|
tw.setPostOrderTraversal(true);
|
||||||
|
tw.addTree(new DirCacheIterator(tree));
|
||||||
|
|
||||||
|
assertModes("a", REGULAR_FILE, tw);
|
||||||
|
|
||||||
|
assertModes("b", TREE, tw);
|
||||||
|
assertTrue(tw.isSubtree());
|
||||||
|
assertFalse(tw.isPostChildren());
|
||||||
|
|
||||||
|
assertModes("q", REGULAR_FILE, tw);
|
||||||
}
|
}
|
||||||
|
|
||||||
final TreeWalk tw = new TreeWalk(db);
|
|
||||||
tw.setPostOrderTraversal(true);
|
|
||||||
tw.addTree(new DirCacheIterator(tree));
|
|
||||||
|
|
||||||
assertModes("a", REGULAR_FILE, tw);
|
|
||||||
|
|
||||||
assertModes("b", TREE, tw);
|
|
||||||
assertTrue(tw.isSubtree());
|
|
||||||
assertFalse(tw.isPostChildren());
|
|
||||||
|
|
||||||
assertModes("q", REGULAR_FILE, tw);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private DirCacheEntry makeFile(final String path) throws Exception {
|
private DirCacheEntry makeFile(final String path) throws Exception {
|
||||||
|
|
|
@ -113,15 +113,16 @@ private List<String> getMatchingPaths(String suffixFilter,
|
||||||
|
|
||||||
private List<String> getMatchingPaths(String suffixFilter,
|
private List<String> getMatchingPaths(String suffixFilter,
|
||||||
final ObjectId treeId, boolean recursiveWalk) throws IOException {
|
final ObjectId treeId, boolean recursiveWalk) throws IOException {
|
||||||
final TreeWalk tw = new TreeWalk(db);
|
try (final TreeWalk tw = new TreeWalk(db)) {
|
||||||
tw.setFilter(PathSuffixFilter.create(suffixFilter));
|
tw.setFilter(PathSuffixFilter.create(suffixFilter));
|
||||||
tw.setRecursive(recursiveWalk);
|
tw.setRecursive(recursiveWalk);
|
||||||
tw.addTree(treeId);
|
tw.addTree(treeId);
|
||||||
|
|
||||||
List<String> paths = new ArrayList<String>();
|
List<String> paths = new ArrayList<String>();
|
||||||
while (tw.next())
|
while (tw.next())
|
||||||
paths.add(tw.getPathString());
|
paths.add(tw.getPathString());
|
||||||
return paths;
|
return paths;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue