import static java.nio.charset.StandardCharsets.UTF_8;
import static org.eclipse.jgit.util.FileUtils.RECURSIVE;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
try (Git git = new Git(db)) {
DirCache dc = git.add().addFilepattern("a.txt").call();
- dc.getEntry(0).getObjectId();
+ ObjectId oid = dc.getEntry(0).getObjectId();
try (PrintWriter writer = new PrintWriter(file, UTF_8.name())) {
writer.print("other content");
}
dc = git.add().addFilepattern("a.txt").call();
-
+ assertNotEquals(oid, dc.getEntry(0).getObjectId());
assertEquals(
"[a.txt, mode:100644, content:other content]",
indexState(CONTENT));
try (Git git = new Git(db)) {
DirCache dc = git.add().addFilepattern("a.txt").call();
- dc.getEntry(0).getObjectId();
+ ObjectId oid = dc.getEntry(0).getObjectId();
git.commit().setMessage("commit a.txt").call();
}
dc = git.add().addFilepattern("a.txt").call();
-
+ assertNotEquals(oid, dc.getEntry(0).getObjectId());
assertEquals(
"[a.txt, mode:100644, content:other content]",
indexState(CONTENT));
try (Git git = new Git(db)) {
DirCache dc = git.add().addFilepattern("a.txt").call();
- dc.getEntry(0).getObjectId();
+ ObjectId oid = dc.getEntry(0).getObjectId();
FileUtils.delete(file);
// is supposed to do nothing
dc = git.add().addFilepattern("a.txt").call();
-
+ assertEquals(oid, dc.getEntry(0).getObjectId());
assertEquals(
"[a.txt, mode:100644, content:content]",
indexState(CONTENT));
git.commit().setMessage("commit a.txt").call();
- dc.getEntry(0).getObjectId();
+ ObjectId oid = dc.getEntry(0).getObjectId();
FileUtils.delete(file);
// is supposed to do nothing
dc = git.add().addFilepattern("a.txt").call();
-
+ assertEquals(oid, dc.getEntry(0).getObjectId());
assertEquals(
"[a.txt, mode:100644, content:content]",
indexState(CONTENT));
// template)
chars = commit.getFullMessage().getBytes(UTF_8);
int lineStart = 0;
- int lineEnd = 0;
for (int i = 0; i < 4; i++) {
lineStart = RawParseUtils.nextLF(chars, lineStart);
}
- lineEnd = RawParseUtils.nextLF(chars, lineStart);
+ int lineEnd = RawParseUtils.nextLF(chars, lineStart);
String line = RawParseUtils.decode(chars, lineStart, lineEnd);
// we should find the untouched template
chars = commit.getFullMessage().getBytes(UTF_8);
lineStart = 0;
- lineEnd = 0;
for (int i = 0; i < 4; i++) {
lineStart = RawParseUtils.nextLF(chars, lineStart);
}
lineEnd = RawParseUtils.nextLF(chars, lineStart);
- line = RawParseUtils.decode(chars, lineStart, lineEnd);
+ RawParseUtils.decode(chars, lineStart, lineEnd);
assertTrue(commit.getFullMessage()
.contains("Change-Id: I" + ObjectId.zeroId().getName()));
@Test
public void testUpdateWorkingDirectoryFromIndex() throws Exception {
CheckoutCommand co = git.checkout();
- File written = writeTrashFile(FILE1, "3a");
+ writeTrashFile(FILE1, "3a");
git.add().addFilepattern(FILE1).call();
- written = writeTrashFile(FILE1, "");
+ File written = writeTrashFile(FILE1, "");
assertEquals("", read(written));
co.addPath(FILE1).call();
assertEquals("3a", read(written));
public void testUpdateWorkingDirectoryFromHeadWithIndexChange()
throws Exception {
CheckoutCommand co = git.checkout();
- File written = writeTrashFile(FILE1, "3a");
+ writeTrashFile(FILE1, "3a");
git.add().addFilepattern(FILE1).call();
- written = writeTrashFile(FILE1, "");
+ File written = writeTrashFile(FILE1, "");
assertEquals("", read(written));
co.addPath(FILE1).setStartPoint("HEAD").call();
assertEquals("3", read(written));
RevCommit stashed = git.stashCreate().call();
assertNotNull(stashed);
stashRef = git.getRepository().exactRef(Constants.R_STASH);
- assertEquals(stashed,
- git.getRepository().exactRef(Constants.R_STASH).getObjectId());
+ assertEquals(stashed, stashRef.getObjectId());
try {
assertNull(git.stashDrop().setStashRef(100).call());
fail("Exception not thrown");
RevCommit stashed = git.stashCreate().call();
assertNotNull(stashed);
stashRef = git.getRepository().exactRef(Constants.R_STASH);
- assertEquals(stashed,
- git.getRepository().exactRef(Constants.R_STASH).getObjectId());
+ assertEquals(stashed, stashRef.getObjectId());
assertNull(git.stashDrop().call());
stashRef = git.getRepository().exactRef(Constants.R_STASH);
assertNull(stashRef);
UTF_8))) {
r.lines().forEach(line -> {
// Parse the line and add to result map
- int start = 0;
int i = line.indexOf(':');
String path = line.substring(0, i).trim();
- start = i + 1;
+ int start = i + 1;
i = line.indexOf(':', start);
String key = line.substring(start, i).trim();
String value = line.substring(i + 1).trim();
@Test
public void testRefsCacheAfterUpdate() throws Exception {
// Do not use the default repo for this case.
- List<Ref> allRefs = db.getRefDatabase().getRefs();
ObjectId oldValue = db.resolve("HEAD");
ObjectId newValue = db.resolve("HEAD^");
// first make HEAD refer to loose ref
update = updateRef.update();
assertEquals(Result.FAST_FORWARD, update);
- allRefs = db.getRefDatabase().getRefs();
+ List<Ref> allRefs = db.getRefDatabase().getRefs();
Ref master = getRef(allRefs, "refs/heads/master").get();
Ref head = getRef(allRefs, "HEAD").get();
assertEquals("refs/heads/master", master.getName());
@Test
public void testRefsCacheAfterUpdateLooseOnly() throws Exception {
// Do not use the default repo for this case.
- List<Ref> allRefs = db.getRefDatabase().getRefs();
ObjectId oldValue = db.resolve("HEAD");
writeSymref(Constants.HEAD, "refs/heads/newref");
RefUpdate updateRef = db.updateRef(Constants.HEAD);
Result update = updateRef.update();
assertEquals(Result.NEW, update);
- allRefs = db.getRefDatabase().getRefs();
+ List<Ref> allRefs = db.getRefDatabase().getRefs();
Ref head = getRef(allRefs, "HEAD").get();
Ref newref = getRef(allRefs, "refs/heads/newref").get();
assertEquals("refs/heads/newref", newref.getName());
@Test
public void testCommitTemplateEncoding()
throws ConfigInvalidException, IOException {
- Config config = new Config(null);
File workTree = tmp.newFolder("dummy-worktree");
Repository repo = FileRepositoryBuilder
.create(new File(workTree, ".git"));
String templateContent = "content of the template";
JGitTestUtil.write(tempFile, templateContent);
String expectedTemplatePath = tempFile.getPath();
- config = parse("[i18n]\n\tcommitEncoding = utf-8\n"
+ Config config = parse("[i18n]\n\tcommitEncoding = utf-8\n"
+ "[commit]\n\ttemplate = "
+ Config.escapeValue(expectedTemplatePath) + "\n");
assertEquals(templateContent,
@Test(expected = ConfigInvalidException.class)
public void testCommitTemplateWithInvalidEncoding()
throws ConfigInvalidException, IOException {
- Config config = new Config(null);
File workTree = tmp.newFolder("dummy-worktree");
File tempFile = tmp.newFile("testCommitTemplate-");
Repository repo = FileRepositoryBuilder
repo.create();
String templateContent = "content of the template";
JGitTestUtil.write(tempFile, templateContent);
- config = parse("[i18n]\n\tcommitEncoding = invalidEcoding\n"
+ Config config = parse("[i18n]\n\tcommitEncoding = invalidEcoding\n"
+ "[commit]\n\ttemplate = "
+ Config.escapeValue(tempFile.getPath()) + "\n");
config.get(CommitConfig.KEY).getCommitTemplateContent(repo);
@Test(expected = FileNotFoundException.class)
public void testCommitTemplateWithInvalidPath()
throws ConfigInvalidException, IOException {
- Config config = new Config(null);
File workTree = tmp.newFolder("dummy-worktree");
File tempFile = tmp.newFile("testCommitTemplate-");
Repository repo = FileRepositoryBuilder
JGitTestUtil.write(tempFile, templateContent);
// commit message encoding
String expectedTemplatePath = "~/nonExistingTemplate";
- config = parse("[commit]\n\ttemplate = " + expectedTemplatePath + "\n");
+ Config config = parse(
+ "[commit]\n\ttemplate = " + expectedTemplatePath + "\n");
String templatePath = config.get(CommitConfig.KEY)
.getCommitTemplatePath();
assertEquals(expectedTemplatePath, templatePath);
git.checkout().setName("master").call();
mergeResult = git.merge().include(commitX).setStrategy(strategy)
.call();
+ assertEquals(MergeResult.MergeStatus.MERGED,
+ mergeResult.getMergeStatus());
// Now, merge commit A and B (i.e. "master" and "second-branch").
// None of them have the file "a", so there is no conflict, BUT while
git.add().addFilepattern("c").call();
RevCommit commitI = git.commit().setMessage("Initial commit").call();
- File a = writeTrashFile("a", "content in Ancestor");
+ writeTrashFile("a", "content in Ancestor");
git.add().addFilepattern("a").call();
RevCommit commitA1 = git.commit().setMessage("Ancestor 1").call();
- a = writeTrashFile("a", "content in Child 1 (commited on master)");
+ writeTrashFile("a", "content in Child 1 (commited on master)");
git.add().addFilepattern("a").call();
// commit C1M
git.commit().setMessage("Child 1 on master").call();
git.checkout().setCreateBranch(true).setStartPoint(commitI).setName("branch-to-merge").call();
// "a" becomes executable in A2
- a = writeTrashFile("a", "content in Ancestor");
+ File a = writeTrashFile("a", "content in Ancestor");
a.setExecutable(true);
git.add().addFilepattern("a").call();
RevCommit commitA2 = git.commit().setMessage("Ancestor 2").call();
// second branch
git.checkout().setCreateBranch(true).setStartPoint(commitA1).setName("second-branch").call();
- a = writeTrashFile("a", "content in Child 2 (commited on second-branch)");
+ writeTrashFile("a", "content in Child 2 (commited on second-branch)");
git.add().addFilepattern("a").call();
// commit C2S
git.commit().setMessage("Child 2 on second-branch").call();
"-Xep:UnusedException:ERROR",
"-Xep:UnusedMethod:WARN",
"-Xep:UnusedNestedClass:ERROR",
- "-Xep:UnusedVariable:WARN",
+ "-Xep:UnusedVariable:ERROR",
"-Xep:URLEqualsHashCode:ERROR",
"-Xep:UseBinds:ERROR",
"-Xep:UseCorrectAssertInTests:WARN",