aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit/api
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/api')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java14
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java5
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java57
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java30
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java114
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchAndPullCommandsRecurseSubmodulesTest.java3
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java7
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java1
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java1
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java773
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java34
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RevertCommandTest.java7
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java29
15 files changed, 990 insertions, 91 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java
index 867310b60c..584d149631 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java
@@ -32,6 +32,7 @@ import org.eclipse.jgit.diff.RawText;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.ConfigConstants;
+import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.IO;
import org.junit.Test;
@@ -402,7 +403,9 @@ public class ApplyCommandTest extends RepositoryTestCase {
public void testAddM1() throws Exception {
ApplyResult result = init("M1", false, true);
assertEquals(1, result.getUpdatedFiles().size());
- assertTrue(result.getUpdatedFiles().get(0).canExecute());
+ if (FS.DETECTED.supportsExecute()) {
+ assertTrue(FS.DETECTED.canExecute(result.getUpdatedFiles().get(0)));
+ }
checkFile(new File(db.getWorkTree(), "M1"),
b.getString(0, b.size(), false));
}
@@ -411,7 +414,9 @@ public class ApplyCommandTest extends RepositoryTestCase {
public void testModifyM2() throws Exception {
ApplyResult result = init("M2", true, true);
assertEquals(1, result.getUpdatedFiles().size());
- assertTrue(result.getUpdatedFiles().get(0).canExecute());
+ if (FS.DETECTED.supportsExecute()) {
+ assertTrue(FS.DETECTED.canExecute(result.getUpdatedFiles().get(0)));
+ }
checkFile(new File(db.getWorkTree(), "M2"),
b.getString(0, b.size(), false));
}
@@ -420,7 +425,10 @@ public class ApplyCommandTest extends RepositoryTestCase {
public void testModifyM3() throws Exception {
ApplyResult result = init("M3", true, true);
assertEquals(1, result.getUpdatedFiles().size());
- assertFalse(result.getUpdatedFiles().get(0).canExecute());
+ if (FS.DETECTED.supportsExecute()) {
+ assertFalse(
+ FS.DETECTED.canExecute(result.getUpdatedFiles().get(0)));
+ }
checkFile(new File(db.getWorkTree(), "M3"),
b.getString(0, b.size(), false));
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java
index e7ed102f13..87be813c85 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java
@@ -71,6 +71,7 @@ public class BranchCommandTest extends RepositoryTestCase {
private Git setUpRepoWithRemote() throws Exception {
Repository remoteRepository = createWorkRepository();
+ addRepoToClose(remoteRepository);
try (Git remoteGit = new Git(remoteRepository)) {
// commit something
writeTrashFile("Test.txt", "Hello world");
@@ -85,6 +86,7 @@ public class BranchCommandTest extends RepositoryTestCase {
rup.forceUpdate();
Repository localRepository = createWorkRepository();
+ addRepoToClose(localRepository);
Git localGit = new Git(localRepository);
StoredConfig config = localRepository.getConfig();
RemoteConfig rc = new RemoteConfig(config, "origin");
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java
index e520732513..ab0184bd4a 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java
@@ -292,6 +292,7 @@ public class CheckoutCommandTest extends RepositoryTestCase {
@Test
public void testCheckoutRemoteTrackingWithUpstream() throws Exception {
Repository db2 = createRepositoryWithRemote();
+ addRepoToClose(db2);
Git.wrap(db2).checkout().setCreateBranch(true).setName("test")
.setStartPoint("origin/test")
@@ -311,6 +312,7 @@ public class CheckoutCommandTest extends RepositoryTestCase {
@Test
public void testCheckoutRemoteTrackingWithoutLocalBranch() throws Exception {
Repository db2 = createRepositoryWithRemote();
+ addRepoToClose(db2);
// checkout remote tracking branch in second repository
// (no local branches exist yet in second repository)
@@ -868,7 +870,7 @@ public class CheckoutCommandTest extends RepositoryTestCase {
coCommand.setName(crudCommit.getName()).call();
CheckoutResult result = coCommand.getResult();
assertEquals(Status.NONDELETED, result.getStatus());
- assertEquals("[Test.txt, toBeDeleted.txt]",
+ assertEquals("[toBeDeleted.txt]",
result.getRemovedList().toString());
assertEquals("[toBeCreated.txt, toBeModified.txt]",
result.getModifiedList().toString());
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java
index f4f0ecd689..0d38197d9a 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java
@@ -175,7 +175,8 @@ public class CherryPickCommandTest extends RepositoryTestCase {
assertEquals(CherryPickStatus.CONFLICTING, result.getStatus());
assertTrue(new File(db.getDirectory(), Constants.MERGE_MSG).exists());
- assertEquals("side\n\nConflicts:\n\ta\n", db.readMergeCommitMsg());
+ assertEquals("side\n\n# Conflicts:\n#\ta\n",
+ db.readMergeCommitMsg());
assertTrue(new File(db.getDirectory(), Constants.CHERRY_PICK_HEAD)
.exists());
assertEquals(sideCommit.getId(), db.readCherryPickHead());
@@ -207,7 +208,7 @@ public class CherryPickCommandTest extends RepositoryTestCase {
String expected = "<<<<<<< master\na(master)\n=======\na(side)\n>>>>>>> 527460a side\n";
assertEquals(expected, read("a"));
assertTrue(new File(db.getDirectory(), Constants.MERGE_MSG).exists());
- assertEquals("side\n\nConflicts:\n\ta\n", db.readMergeCommitMsg());
+ assertEquals("side\n\n# Conflicts:\n#\ta\n", db.readMergeCommitMsg());
assertFalse(new File(db.getDirectory(), Constants.CHERRY_PICK_HEAD)
.exists());
assertEquals(RepositoryState.SAFE, db.getRepositoryState());
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java
index 8084505c10..35de73e204 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java
@@ -46,6 +46,7 @@ import org.eclipse.jgit.lib.RefUpdate.Result;
import org.eclipse.jgit.lib.ReflogEntry;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
+import org.eclipse.jgit.lib.CommitConfig.CleanupMode;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.submodule.SubmoduleWalk;
@@ -515,6 +516,62 @@ public class CommitCommandTest extends RepositoryTestCase {
}
@Test
+ public void commitMessageVerbatim() throws Exception {
+ try (Git git = new Git(db)) {
+ writeTrashFile("file1", "file1");
+ git.add().addFilepattern("file1").call();
+ RevCommit committed = git.commit().setMessage("#initial commit")
+ .call();
+
+ assertEquals("#initial commit", committed.getFullMessage());
+ }
+ }
+
+ @Test
+ public void commitMessageStrip() throws Exception {
+ try (Git git = new Git(db)) {
+ writeTrashFile("file1", "file1");
+ git.add().addFilepattern("file1").call();
+ RevCommit committed = git.commit().setMessage(
+ "#Comment\ninitial commit\t\n\n commit body \n \t#another comment")
+ .setCleanupMode(CleanupMode.STRIP).call();
+
+ assertEquals("initial commit\n\n commit body",
+ committed.getFullMessage());
+ }
+ }
+
+ @Test
+ public void commitMessageDefault() throws Exception {
+ try (Git git = new Git(db)) {
+ writeTrashFile("file1", "file1");
+ git.add().addFilepattern("file1").call();
+ RevCommit committed = git.commit().setMessage(
+ "#Comment\ninitial commit\t\n\n commit body \n\n\n \t#another comment ")
+ .setCleanupMode(CleanupMode.DEFAULT).call();
+
+ assertEquals("initial commit\n\n commit body",
+ committed.getFullMessage());
+ }
+ }
+
+ @Test
+ public void commitMessageDefaultWhitespace() throws Exception {
+ try (Git git = new Git(db)) {
+ writeTrashFile("file1", "file1");
+ git.add().addFilepattern("file1").call();
+ RevCommit committed = git.commit().setMessage(
+ "#Comment\ninitial commit\t\n\n commit body \n\n\n \t#another comment ")
+ .setCleanupMode(CleanupMode.DEFAULT).setDefaultClean(false)
+ .call();
+
+ assertEquals(
+ "#Comment\ninitial commit\n\n commit body\n\n \t#another comment",
+ committed.getFullMessage());
+ }
+ }
+
+ @Test
public void commitEmptyCommits() throws Exception {
try (Git git = new Git(db)) {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java
index b460e3f52e..ab87fa9662 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java
@@ -10,9 +10,10 @@
package org.eclipse.jgit.api;
import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.OBJECT_ID_ABBREV_STRING_LENGTH;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.BufferedWriter;
@@ -100,6 +101,12 @@ public class DescribeCommandTest extends RepositoryTestCase {
assertEquals("alice-t1-2-g3e563c5", describe(c4, "alice*"));
assertEquals("bob-t2-1-g3e563c5", describe(c4, "bob*"));
assertEquals("bob-t2-1-g3e563c5", describe(c4, "a*", "b*", "c*"));
+
+ assertEquals("bob-t2", describe(c4, false, true, 0));
+ assertEquals("bob-t2-1-g3e56", describe(c4, false, true, 1));
+ assertEquals("bob-t2-1-g3e56", describe(c4, false, true, -10));
+ assertEquals("bob-t2-1-g3e563c55927905f21e3bc7c00a3d83a31bf4ed3a",
+ describe(c4, false, true, 50));
} else {
assertEquals(null, describe(c2));
assertEquals(null, describe(c3));
@@ -108,6 +115,18 @@ public class DescribeCommandTest extends RepositoryTestCase {
assertEquals("3747db3", describe(c2, false, true));
assertEquals("44579eb", describe(c3, false, true));
assertEquals("3e563c5", describe(c4, false, true));
+
+ assertEquals("3747db3267", describe(c2, false, true, 10));
+ assertEquals("44579ebe7f", describe(c3, false, true, 10));
+ assertEquals("3e563c5592", describe(c4, false, true, 10));
+
+ assertEquals("3e56", describe(c4, false, true, -10));
+ assertEquals("3e56", describe(c4, false, true, 0));
+ assertEquals("3e56", describe(c4, false, true, 2));
+ assertEquals("3e563c55927905f21e3bc7c00a3d83a31bf4ed3a",
+ describe(c4, false, true, 40));
+ assertEquals("3e563c55927905f21e3bc7c00a3d83a31bf4ed3a",
+ describe(c4, false, true, 42));
}
// test default target
@@ -474,10 +493,15 @@ public class DescribeCommandTest extends RepositoryTestCase {
}
}
+ private String describe(ObjectId c1, boolean longDesc, boolean always,
+ int abbrev) throws GitAPIException, IOException {
+ return git.describe().setTarget(c1).setTags(describeUseAllTags)
+ .setLong(longDesc).setAlways(always).setAbbrev(abbrev).call();
+ }
+
private String describe(ObjectId c1, boolean longDesc, boolean always)
throws GitAPIException, IOException {
- return git.describe().setTarget(c1).setTags(describeUseAllTags)
- .setLong(longDesc).setAlways(always).call();
+ return describe(c1, longDesc, always, OBJECT_ID_ABBREV_STRING_LENGTH);
}
private String describe(ObjectId c1) throws GitAPIException, IOException {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java
index d0dfd1ab92..b937b1f6a9 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java
@@ -1,40 +1,11 @@
/*
- * Copyright (C) 2015, Ivan Motsch <ivan.motsch@bsiag.com>
+ * Copyright (C) 2015, 2022 Ivan Motsch <ivan.motsch@bsiag.com> and others
*
- * This program and the accompanying materials are made available
- * under the terms of the Eclipse Distribution License v1.0 which
- * accompanies this distribution, is reproduced below, and is
- * available at http://www.eclipse.org/org/documents/edl-v10.php
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Distribution License v. 1.0 which is available at
+ * https://www.eclipse.org/org/documents/edl-v10.php.
*
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the following
- * conditions are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- *
- * - Neither the name of the Eclipse Foundation, Inc. nor the
- * names of its contributors may be used to endorse or promote
- * products derived from this software without specific prior
- * written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * SPDX-License-Identifier: BSD-3-Clause
*/
package org.eclipse.jgit.api;
@@ -173,15 +144,22 @@ public class EolRepositoryTest extends RepositoryTestCase {
private DirCache dirCache;
+ private boolean isDefaultCrLf() {
+ String eol = mockSystemReader.getProperty("line.separator");
+ return "\r\n".equals(eol);
+ }
+
@Test
public void testDefaultSetup() throws Exception {
// for EOL to work, the text attribute must be set
setupGitAndDoHardReset(null, null, null, null, "* text=auto");
collectRepositoryState();
assertEquals("text=auto", entryCRLF.attrs);
- checkEntryContent(entryCRLF, CONTENT_LF, CONTENT_LF);
- checkEntryContent(entryLF, CONTENT_LF, CONTENT_LF);
- checkEntryContent(entryMixed, CONTENT_LF, CONTENT_LF);
+ // eol=native is the default!
+ String expected = isDefaultCrLf() ? CONTENT_CRLF : CONTENT_LF;
+ checkEntryContent(entryCRLF, expected, CONTENT_LF);
+ checkEntryContent(entryLF, expected, CONTENT_LF);
+ checkEntryContent(entryMixed, expected, CONTENT_LF);
}
public void checkEntryContent(ActualEntry entry, String fileContent,
@@ -199,9 +177,11 @@ public class EolRepositoryTest extends RepositoryTestCase {
setupGitAndDoHardReset(AutoCRLF.FALSE, null, null, null, "* text=auto");
collectRepositoryState();
assertEquals("text=auto", entryCRLF.attrs);
- checkEntryContent(entryCRLF, CONTENT_LF, CONTENT_LF);
- checkEntryContent(entryLF, CONTENT_LF, CONTENT_LF);
- checkEntryContent(entryMixed, CONTENT_LF, CONTENT_LF);
+ // eol=native is the default!
+ String expected = isDefaultCrLf() ? CONTENT_CRLF : CONTENT_LF;
+ checkEntryContent(entryCRLF, expected, CONTENT_LF);
+ checkEntryContent(entryLF, expected, CONTENT_LF);
+ checkEntryContent(entryMixed, expected, CONTENT_LF);
}
@Test
@@ -250,34 +230,24 @@ public class EolRepositoryTest extends RepositoryTestCase {
@Test
public void test_ConfigEOL_native_windows() throws Exception {
- String origLineSeparator = System.getProperty("line.separator", "\n");
- System.setProperty("line.separator", "\r\n");
- try {
- // for EOL to work, the text attribute must be set
- setupGitAndDoHardReset(null, EOL.NATIVE, "*.txt text", null, null);
- collectRepositoryState();
- assertEquals("text", entryCRLF.attrs);
- checkEntryContent(entryCRLF, CONTENT_LF, CONTENT_LF);
- checkEntryContent(entryLF, CONTENT_LF, CONTENT_LF);
- } finally {
- System.setProperty("line.separator", origLineSeparator);
- }
+ mockSystemReader.setWindows();
+ // for EOL to work, the text attribute must be set
+ setupGitAndDoHardReset(null, EOL.NATIVE, "*.txt text", null, null);
+ collectRepositoryState();
+ assertEquals("text", entryCRLF.attrs);
+ checkEntryContent(entryCRLF, CONTENT_CRLF, CONTENT_LF);
+ checkEntryContent(entryLF, CONTENT_CRLF, CONTENT_LF);
}
@Test
public void test_ConfigEOL_native_xnix() throws Exception {
- String origLineSeparator = System.getProperty("line.separator", "\n");
- System.setProperty("line.separator", "\n");
- try {
- // for EOL to work, the text attribute must be set
- setupGitAndDoHardReset(null, EOL.NATIVE, "*.txt text", null, null);
- collectRepositoryState();
- assertEquals("text", entryCRLF.attrs);
- checkEntryContent(entryCRLF, CONTENT_LF, CONTENT_LF);
- checkEntryContent(entryLF, CONTENT_LF, CONTENT_LF);
- } finally {
- System.setProperty("line.separator", origLineSeparator);
- }
+ mockSystemReader.setUnix();
+ // for EOL to work, the text attribute must be set
+ setupGitAndDoHardReset(null, EOL.NATIVE, "*.txt text", null, null);
+ collectRepositoryState();
+ assertEquals("text", entryCRLF.attrs);
+ checkEntryContent(entryCRLF, CONTENT_LF, CONTENT_LF);
+ checkEntryContent(entryLF, CONTENT_LF, CONTENT_LF);
}
@Test
@@ -297,9 +267,10 @@ public class EolRepositoryTest extends RepositoryTestCase {
setupGitAndDoHardReset(AutoCRLF.FALSE, EOL.NATIVE, "*.txt text", null, null);
collectRepositoryState();
assertEquals("text", entryCRLF.attrs);
- checkEntryContent(entryCRLF, CONTENT_LF, CONTENT_LF);
- checkEntryContent(entryLF, CONTENT_LF, CONTENT_LF);
- checkEntryContent(entryMixed, CONTENT_LF, CONTENT_LF);
+ String expected = isDefaultCrLf() ? CONTENT_CRLF : CONTENT_LF;
+ checkEntryContent(entryCRLF, expected, CONTENT_LF);
+ checkEntryContent(entryLF, expected, CONTENT_LF);
+ checkEntryContent(entryMixed, expected, CONTENT_LF);
}
@Test
@@ -524,9 +495,12 @@ public class EolRepositoryTest extends RepositoryTestCase {
// info overrides all
collectRepositoryState();
assertEquals("text", entryCRLF.attrs);
- checkEntryContent(entryCRLF, CONTENT_LF, CONTENT_LF);
- checkEntryContent(entryLF, CONTENT_LF, CONTENT_LF);
- checkEntryContent(entryMixed, CONTENT_LF, CONTENT_LF);
+ // !eol means unspecified, so use the default of core.eol, which is
+ // native.
+ String expected = isDefaultCrLf() ? CONTENT_CRLF : CONTENT_LF;
+ checkEntryContent(entryCRLF, expected, CONTENT_LF);
+ checkEntryContent(entryLF, expected, CONTENT_LF);
+ checkEntryContent(entryMixed, expected, CONTENT_LF);
}
@Test
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchAndPullCommandsRecurseSubmodulesTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchAndPullCommandsRecurseSubmodulesTest.java
index 36ba7ce5ac..9ea64efc64 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchAndPullCommandsRecurseSubmodulesTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchAndPullCommandsRecurseSubmodulesTest.java
@@ -259,7 +259,8 @@ public class FetchAndPullCommandsRecurseSubmodulesTest extends RepositoryTestCas
// the commit that was created
try (SubmoduleWalk w = SubmoduleWalk.forIndex(git.getRepository())) {
assertTrue(w.next());
- try (Git g = new Git(w.getRepository())) {
+ try (Repository repository = w.getRepository();
+ Git g = new Git(repository)) {
g.fetch().setRemote(REMOTE).setRefSpecs(REFSPEC).call();
g.reset().setMode(ResetType.HARD).setRef(commit1.name()).call();
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
index bc4e9405ea..64475f5d50 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
@@ -554,7 +554,7 @@ public class MergeCommandTest extends RepositoryTestCase {
git.merge().include(sideBranch)
.setStrategy(MergeStrategy.RESOLVE).call();
- assertEquals("Merge branch 'side'\n\nConflicts:\n\ta\n",
+ assertEquals("Merge branch 'side'\n\n# Conflicts:\n#\ta\n",
db.readMergeCommitMsg());
}
@@ -1787,7 +1787,7 @@ public class MergeCommandTest extends RepositoryTestCase {
+ dateFormatter.formatDate(third
.getAuthorIdent()) + "\n\n\tthird commit\n",
db.readSquashCommitMsg());
- assertEquals("\nConflicts:\n\tfile2\n", db.readMergeCommitMsg());
+ assertEquals("\n# Conflicts:\n#\tfile2\n", db.readMergeCommitMsg());
Status stat = git.status().call();
assertEquals(Sets.of("file2"), stat.getConflicting());
@@ -1881,6 +1881,7 @@ public class MergeCommandTest extends RepositoryTestCase {
@Test
public void testRecursiveMergeWithConflict() throws Exception {
try (TestRepository<Repository> db_t = new TestRepository<>(db)) {
+ db.incrementOpen();
BranchBuilder master = db_t.branch("master");
RevCommit m0 = master.commit()
.add("f", "1\n2\n3\n4\n5\n6\n7\n8\n9\n").message("m0")
@@ -2012,7 +2013,7 @@ public class MergeCommandTest extends RepositoryTestCase {
git.merge().include(sideBranch).setStrategy(MergeStrategy.RESOLVE)
.setMessage("user message").call();
- assertEquals("user message\n\nConflicts:\n\ta\n",
+ assertEquals("user message\n\n# Conflicts:\n#\ta\n",
db.readMergeCommitMsg());
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java
index 9af77aa3e8..6a84f0a38d 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java
@@ -567,6 +567,7 @@ public class PullCommandTest extends RepositoryTestCase {
public void setUp() throws Exception {
super.setUp();
dbTarget = createWorkRepository();
+ addRepoToClose(dbTarget);
source = new Git(db);
target = new Git(dbTarget);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java
index cce04f471b..e2d7923cee 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java
@@ -323,6 +323,7 @@ public class PullCommandWithRebaseTest extends RepositoryTestCase {
dbTarget = createWorkRepository();
source = new Git(db);
target = new Git(dbTarget);
+ addRepoToClose(dbTarget);
// put some file in the source repo
sourceFile = new File(db.getWorkTree(), "SomeFile.txt");
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java
index a786065561..6f7aa63edc 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java
@@ -10,7 +10,9 @@
package org.eclipse.jgit.api;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -19,10 +21,13 @@ import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Properties;
+import org.eclipse.jgit.api.errors.DetachedHeadException;
import org.eclipse.jgit.api.errors.GitAPIException;
+import org.eclipse.jgit.api.errors.InvalidRefNameException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.TransportException;
import org.eclipse.jgit.errors.MissingObjectException;
+import org.eclipse.jgit.errors.NoRemoteRepositoryException;
import org.eclipse.jgit.hooks.PrePushHook;
import org.eclipse.jgit.junit.JGitTestUtil;
import org.eclipse.jgit.junit.RepositoryTestCase;
@@ -32,6 +37,7 @@ import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.transport.PushConfig.PushDefault;
import org.eclipse.jgit.transport.PushResult;
import org.eclipse.jgit.transport.RefLeaseSpec;
import org.eclipse.jgit.transport.RefSpec;
@@ -50,6 +56,7 @@ public class PushCommandTest extends RepositoryTestCase {
// create other repository
Repository db2 = createWorkRepository();
+ addRepoToClose(db2);
final StoredConfig config2 = db2.getConfig();
// this tests that this config can be parsed properly
@@ -289,6 +296,770 @@ public class PushCommandTest extends RepositoryTestCase {
}
/**
+ * Check that pushing from a detached HEAD without refspec throws a
+ * DetachedHeadException.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testPushDefaultDetachedHead() throws Exception {
+ try (Git git = new Git(db);
+ 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();
+
+ writeTrashFile("f", "content of f");
+ git.add().addFilepattern("f").call();
+ RevCommit commit = git.commit().setMessage("adding f").call();
+
+ git.checkout().setName("not-pushed").setCreateBranch(true).call();
+ git.checkout().setName("branchtopush").setCreateBranch(true).call();
+ git.checkout().setName(commit.getName()).call();
+ String head = git.getRepository().getFullBranch();
+ assertTrue(ObjectId.isId(head));
+ assertEquals(commit.getName(), head);
+ assertThrows(DetachedHeadException.class,
+ () -> git.push().setRemote("test").call());
+ }
+ }
+
+ /**
+ * Check that push.default=nothing without refspec throws an
+ * InvalidRefNameException.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testPushDefaultNothing() throws Exception {
+ try (Git git = new Git(db);
+ 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();
+
+ writeTrashFile("f", "content of f");
+ git.add().addFilepattern("f").call();
+ 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"));
+ assertThrows(InvalidRefNameException.class,
+ () -> git.push().setRemote("test")
+ .setPushDefault(PushDefault.NOTHING).call());
+ }
+ }
+
+ /**
+ * Check that push.default=matching without refspec pushes all matching
+ * branches.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testPushDefaultMatching() throws Exception {
+ try (Git git = new Git(db);
+ 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();
+
+ writeTrashFile("f", "content of f");
+ git.add().addFilepattern("f").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"));
+ // push master and branchtopush
+ git.push().setRemote("test").setRefSpecs(
+ new RefSpec("refs/heads/master:refs/heads/master"),
+ new RefSpec(
+ "refs/heads/branchtopush:refs/heads/branchtopush"))
+ .call();
+ assertEquals(commit.getId(),
+ git2.getRepository().resolve("refs/heads/master"));
+ assertEquals(commit.getId(),
+ git2.getRepository().resolve("refs/heads/branchtopush"));
+ assertEquals(null,
+ git2.getRepository().resolve("refs/heads/not-pushed"));
+ // Create two different commits on these two branches
+ writeTrashFile("b", "on branchtopush");
+ git.add().addFilepattern("b").call();
+ RevCommit bCommit = git.commit().setMessage("on branchtopush")
+ .call();
+ git.checkout().setName("master").call();
+ writeTrashFile("m", "on master");
+ git.add().addFilepattern("m").call();
+ RevCommit mCommit = git.commit().setMessage("on master").call();
+ // Now push with mode "matching": should push both branches.
+ Iterable<PushResult> result = git.push().setRemote("test")
+ .setPushDefault(PushDefault.MATCHING)
+ .call();
+ int n = 0;
+ for (PushResult r : result) {
+ n++;
+ assertEquals(1, n);
+ assertEquals(2, r.getRemoteUpdates().size());
+ for (RemoteRefUpdate update : r.getRemoteUpdates()) {
+ assertFalse(update.isMatching());
+ assertTrue(update.getSrcRef()
+ .equals("refs/heads/branchtopush")
+ || update.getSrcRef().equals("refs/heads/master"));
+ assertEquals(RemoteRefUpdate.Status.OK, update.getStatus());
+ }
+ }
+ assertEquals(bCommit.getId(),
+ git2.getRepository().resolve("refs/heads/branchtopush"));
+ assertEquals(null,
+ git2.getRepository().resolve("refs/heads/not-pushed"));
+ assertEquals(mCommit.getId(),
+ git2.getRepository().resolve("refs/heads/master"));
+ assertEquals(bCommit.getId(), git.getRepository()
+ .resolve("refs/remotes/origin/branchtopush"));
+ assertEquals(null, git.getRepository()
+ .resolve("refs/remotes/origin/not-pushed"));
+ assertEquals(mCommit.getId(),
+ git.getRepository().resolve("refs/remotes/origin/master"));
+ }
+ }
+
+ /**
+ * Check that push.default=upstream without refspec pushes only the current
+ * branch to the configured upstream.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testPushDefaultUpstream() throws Exception {
+ try (Git git = new Git(db);
+ Git git2 = new Git(createBareRepository())) {
+ 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();
+
+ writeTrashFile("f", "content of f");
+ git.add().addFilepattern("f").call();
+ RevCommit commit = git.commit().setMessage("adding f").call();
+
+ git.checkout().setName("not-pushed").setCreateBranch(true).call();
+ git.checkout().setName("branchtopush").setCreateBranch(true).call();
+
+ config = git.getRepository().getConfig();
+ config.setString("branch", "branchtopush", "remote", "test");
+ config.setString("branch", "branchtopush", "merge",
+ "refs/heads/upstreambranch");
+ config.save();
+
+ assertEquals(null,
+ git2.getRepository().resolve("refs/heads/branchtopush"));
+ assertEquals(null,
+ git2.getRepository().resolve("refs/heads/upstreambranch"));
+ assertEquals(null,
+ git2.getRepository().resolve("refs/heads/not-pushed"));
+ assertEquals(null,
+ git2.getRepository().resolve("refs/heads/master"));
+ git.push().setRemote("test").setPushDefault(PushDefault.UPSTREAM)
+ .call();
+ assertEquals(null,
+ git2.getRepository().resolve("refs/heads/branchtopush"));
+ assertEquals(commit.getId(),
+ git2.getRepository().resolve("refs/heads/upstreambranch"));
+ assertEquals(null,
+ git2.getRepository().resolve("refs/heads/not-pushed"));
+ assertEquals(null,
+ git2.getRepository().resolve("refs/heads/master"));
+ assertEquals(commit.getId(), git.getRepository()
+ .resolve("refs/remotes/origin/upstreambranch"));
+ assertEquals(null, git.getRepository()
+ .resolve("refs/remotes/origin/branchtopush"));
+ }
+ }
+
+ /**
+ * Check that push.default=upstream without refspec throws an
+ * InvalidRefNameException if the current branch has no upstream.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testPushDefaultUpstreamNoTracking() throws Exception {
+ try (Git git = new Git(db);
+ Git git2 = new Git(createBareRepository())) {
+ 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();
+
+ writeTrashFile("f", "content of f");
+ git.add().addFilepattern("f").call();
+ git.commit().setMessage("adding f").call();
+
+ git.checkout().setName("not-pushed").setCreateBranch(true).call();
+ git.checkout().setName("branchtopush").setCreateBranch(true).call();
+
+ config = git.getRepository().getConfig();
+ config.setString("branch", "branchtopush", "remote", "test");
+ config.save();
+
+ assertThrows(InvalidRefNameException.class,
+ () -> git.push().setRemote("test")
+ .setPushDefault(PushDefault.UPSTREAM).call());
+ }
+ }
+
+ /**
+ * Check that push.default=upstream without refspec throws an
+ * InvalidRefNameException if the push remote is not the same as the fetch
+ * remote.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testPushDefaultUpstreamTriangular() throws Exception {
+ try (Git git = new Git(db);
+ Git git2 = new Git(createBareRepository())) {
+ 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();
+
+ writeTrashFile("f", "content of f");
+ git.add().addFilepattern("f").call();
+ git.commit().setMessage("adding f").call();
+
+ git.checkout().setName("not-pushed").setCreateBranch(true).call();
+ git.checkout().setName("branchtopush").setCreateBranch(true).call();
+
+ config = git.getRepository().getConfig();
+ // Don't configure a remote; it'll default to "origin".
+ config.setString("branch", "branchtopush", "merge",
+ "upstreambranch");
+ config.save();
+
+ assertThrows(InvalidRefNameException.class,
+ () -> git.push().setRemote("test")
+ .setPushDefault(PushDefault.UPSTREAM).call());
+ }
+ }
+
+ /**
+ * Check that push.default=simple without refspec pushes only the current
+ * branch to the configured upstream name.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testPushDefaultSimple() throws Exception {
+ try (Git git = new Git(db);
+ Git git2 = new Git(createBareRepository())) {
+ 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();
+
+ writeTrashFile("f", "content of f");
+ git.add().addFilepattern("f").call();
+ RevCommit commit = git.commit().setMessage("adding f").call();
+
+ git.checkout().setName("not-pushed").setCreateBranch(true).call();
+ git.checkout().setName("branchtopush").setCreateBranch(true).call();
+
+ config = git.getRepository().getConfig();
+ config.setString("branch", "branchtopush", "remote", "test");
+ config.setString("branch", "branchtopush", "merge",
+ "refs/heads/branchtopush");
+ config.save();
+
+ 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").setPushDefault(PushDefault.SIMPLE)
+ .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(commit.getId(), git.getRepository()
+ .resolve("refs/remotes/origin/branchtopush"));
+ }
+ }
+
+ /**
+ * Check that push.default=simple without refspec pushes only the current
+ * branch to a branch with the same name in a triangular workflow.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testPushDefaultSimpleTriangular() throws Exception {
+ try (Git git = new Git(db);
+ Git git2 = new Git(createBareRepository())) {
+ 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();
+
+ writeTrashFile("f", "content of f");
+ git.add().addFilepattern("f").call();
+ RevCommit commit = git.commit().setMessage("adding f").call();
+
+ git.checkout().setName("not-pushed").setCreateBranch(true).call();
+ git.checkout().setName("branchtopush").setCreateBranch(true).call();
+
+ config = git.getRepository().getConfig();
+ // Don't set remote, it'll default to "origin". Configure a
+ // different branch name; should be ignored.
+ config.setString("branch", "branchtopush", "merge",
+ "refs/heads/upstreambranch");
+ config.save();
+
+ assertEquals(null,
+ git2.getRepository().resolve("refs/heads/branchtopush"));
+ assertEquals(null,
+ git2.getRepository().resolve("refs/heads/upstreambranch"));
+ assertEquals(null,
+ git2.getRepository().resolve("refs/heads/not-pushed"));
+ assertEquals(null,
+ git2.getRepository().resolve("refs/heads/master"));
+ git.push().setRemote("test").setPushDefault(PushDefault.SIMPLE)
+ .call();
+ assertEquals(commit.getId(),
+ git2.getRepository().resolve("refs/heads/branchtopush"));
+ assertEquals(null,
+ git2.getRepository().resolve("refs/heads/upstreambranch"));
+ assertEquals(null,
+ git2.getRepository().resolve("refs/heads/not-pushed"));
+ assertEquals(null,
+ git2.getRepository().resolve("refs/heads/master"));
+ assertEquals(commit.getId(), git.getRepository()
+ .resolve("refs/remotes/origin/branchtopush"));
+ }
+ }
+
+ /**
+ * Check that push.default=simple without refspec throws an
+ * InvalidRefNameException if the current branch has no upstream.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testPushDefaultSimpleNoTracking() throws Exception {
+ try (Git git = new Git(db);
+ Git git2 = new Git(createBareRepository())) {
+ 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();
+
+ writeTrashFile("f", "content of f");
+ git.add().addFilepattern("f").call();
+ git.commit().setMessage("adding f").call();
+
+ git.checkout().setName("not-pushed").setCreateBranch(true).call();
+ git.checkout().setName("branchtopush").setCreateBranch(true).call();
+
+ config = git.getRepository().getConfig();
+ config.setString("branch", "branchtopush", "remote", "test");
+ config.save();
+
+ assertThrows(InvalidRefNameException.class,
+ () -> git.push().setRemote("test")
+ .setPushDefault(PushDefault.SIMPLE).call());
+ }
+ }
+
+ /**
+ * Check that push.default=simple without refspec throws an
+ * InvalidRefNameException if the current branch has an upstream with a
+ * different name.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testPushDefaultSimpleDifferentTracking() throws Exception {
+ try (Git git = new Git(db);
+ Git git2 = new Git(createBareRepository())) {
+ 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();
+
+ writeTrashFile("f", "content of f");
+ git.add().addFilepattern("f").call();
+ git.commit().setMessage("adding f").call();
+
+ git.checkout().setName("not-pushed").setCreateBranch(true).call();
+ git.checkout().setName("branchtopush").setCreateBranch(true).call();
+
+ config = git.getRepository().getConfig();
+ config.setString("branch", "branchtopush", "remote", "test");
+ config.setString("branch", "branchtopush", "merge",
+ "refs/heads/upstreambranch");
+ config.save();
+
+ assertThrows(InvalidRefNameException.class,
+ () -> git.push().setRemote("test")
+ .setPushDefault(PushDefault.SIMPLE).call());
+ }
+ }
+
+ /**
+ * Check that if no PushDefault is set, the value is read from the git
+ * config.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testPushDefaultFromConfig() throws Exception {
+ try (Git git = new Git(db);
+ Git git2 = new Git(createBareRepository())) {
+ 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.setString("push", null, "default", "upstream");
+ config.save();
+
+ writeTrashFile("f", "content of f");
+ git.add().addFilepattern("f").call();
+ RevCommit commit = git.commit().setMessage("adding f").call();
+
+ git.checkout().setName("not-pushed").setCreateBranch(true).call();
+ git.checkout().setName("branchtopush").setCreateBranch(true).call();
+
+ config = git.getRepository().getConfig();
+ config.setString("branch", "branchtopush", "remote", "test");
+ config.setString("branch", "branchtopush", "merge",
+ "refs/heads/upstreambranch");
+ config.save();
+
+ assertEquals(null,
+ git2.getRepository().resolve("refs/heads/branchtopush"));
+ assertEquals(null,
+ git2.getRepository().resolve("refs/heads/upstreambranch"));
+ assertEquals(null,
+ git2.getRepository().resolve("refs/heads/not-pushed"));
+ assertEquals(null,
+ git2.getRepository().resolve("refs/heads/master"));
+ PushCommand cmd = git.push();
+ cmd.setRemote("test").setPushDefault(null).call();
+ assertEquals(PushDefault.UPSTREAM, cmd.getPushDefault());
+ assertEquals(null,
+ git2.getRepository().resolve("refs/heads/branchtopush"));
+ assertEquals(commit.getId(),
+ git2.getRepository().resolve("refs/heads/upstreambranch"));
+ assertEquals(null,
+ git2.getRepository().resolve("refs/heads/not-pushed"));
+ assertEquals(null,
+ git2.getRepository().resolve("refs/heads/master"));
+ assertEquals(commit.getId(), git.getRepository()
+ .resolve("refs/remotes/origin/upstreambranch"));
+ assertEquals(null, git.getRepository()
+ .resolve("refs/remotes/origin/branchtopush"));
+ }
+ }
+
+ /**
+ * Check that if no PushDefault is set and none is set in the git config, it
+ * defaults to "simple".
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testPushDefaultFromConfigDefault() throws Exception {
+ try (Git git = new Git(db);
+ Git git2 = new Git(createBareRepository())) {
+ 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();
+
+ writeTrashFile("f", "content of f");
+ git.add().addFilepattern("f").call();
+ RevCommit commit = git.commit().setMessage("adding f").call();
+
+ git.checkout().setName("not-pushed").setCreateBranch(true).call();
+ git.checkout().setName("branchtopush").setCreateBranch(true).call();
+
+ config = git.getRepository().getConfig();
+ config.setString("branch", "branchtopush", "remote", "test");
+ config.setString("branch", "branchtopush", "merge",
+ "refs/heads/branchtopush");
+ config.save();
+
+ 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"));
+ PushCommand cmd = git.push();
+ cmd.setRemote("test").setPushDefault(null).call();
+ assertEquals(PushDefault.SIMPLE, cmd.getPushDefault());
+ 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(commit.getId(), git.getRepository()
+ .resolve("refs/remotes/origin/branchtopush"));
+ }
+ }
+
+ /**
+ * Check that branch.<name>.pushRemote overrides anything else.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testBranchPushRemote() throws Exception {
+ try (Git git = new Git(db);
+ Git git2 = new Git(createBareRepository())) {
+ 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.setString("remote", null, "pushDefault", "test");
+ config.save();
+
+ writeTrashFile("f", "content of f");
+ git.add().addFilepattern("f").call();
+ git.commit().setMessage("adding f").call();
+
+ git.checkout().setName("not-pushed").setCreateBranch(true).call();
+ git.checkout().setName("branchtopush").setCreateBranch(true).call();
+
+ config = git.getRepository().getConfig();
+ config.setString("branch", "branchtopush", "remote", "test");
+ config.setString("branch", "branchtopush", "pushremote", "origin");
+ config.setString("branch", "branchtopush", "merge",
+ "refs/heads/branchtopush");
+ config.save();
+
+ assertThrows(InvalidRefNameException.class, () -> git.push()
+ .setPushDefault(PushDefault.UPSTREAM).call());
+ }
+ }
+
+ /**
+ * Check that remote.pushDefault overrides branch.<name>.remote
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testRemotePushDefault() throws Exception {
+ try (Git git = new Git(db);
+ Git git2 = new Git(createBareRepository())) {
+ 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.setString("remote", null, "pushDefault", "origin");
+ config.save();
+
+ writeTrashFile("f", "content of f");
+ git.add().addFilepattern("f").call();
+ git.commit().setMessage("adding f").call();
+
+ git.checkout().setName("not-pushed").setCreateBranch(true).call();
+ git.checkout().setName("branchtopush").setCreateBranch(true).call();
+
+ config = git.getRepository().getConfig();
+ config.setString("branch", "branchtopush", "remote", "test");
+ config.setString("branch", "branchtopush", "merge",
+ "refs/heads/branchtopush");
+ config.save();
+
+ assertThrows(InvalidRefNameException.class, () -> git.push()
+ .setPushDefault(PushDefault.UPSTREAM).call());
+ }
+ }
+
+ /**
+ * Check that ultimately we fall back to "origin".
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testDefaultRemote() throws Exception {
+ try (Git git = new Git(db);
+ Git git2 = new Git(createBareRepository())) {
+ 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();
+
+ writeTrashFile("f", "content of f");
+ git.add().addFilepattern("f").call();
+ git.commit().setMessage("adding f").call();
+
+ git.checkout().setName("not-pushed").setCreateBranch(true).call();
+ git.checkout().setName("branchtopush").setCreateBranch(true).call();
+
+ config = git.getRepository().getConfig();
+ config.setString("branch", "branchtopush", "merge",
+ "refs/heads/branchtopush");
+ config.save();
+
+ PushCommand cmd = git.push().setPushDefault(PushDefault.UPSTREAM);
+ TransportException e = assertThrows(TransportException.class,
+ () -> cmd.call());
+ assertEquals(NoRemoteRepositoryException.class,
+ e.getCause().getClass());
+ assertEquals("origin", cmd.getRemote());
+ }
+ }
+
+ /**
+ * Check that a push without specifying a remote or mode or anything can
+ * succeed if the git config is correct.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testDefaultPush() throws Exception {
+ try (Git git = new Git(db);
+ Git git2 = new Git(createBareRepository())) {
+ 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();
+
+ writeTrashFile("f", "content of f");
+ git.add().addFilepattern("f").call();
+ RevCommit commit = git.commit().setMessage("adding f").call();
+
+ git.checkout().setName("not-pushed").setCreateBranch(true).call();
+ git.checkout().setName("branchtopush").setCreateBranch(true).call();
+
+ config = git.getRepository().getConfig();
+ config.setString("branch", "branchtopush", "remote", "test");
+ config.save();
+
+ 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"));
+ // Should use remote "test", push.default=current
+ PushCommand cmd = git.push();
+ cmd.call();
+ assertEquals("test", cmd.getRemote());
+ assertEquals(PushDefault.CURRENT, cmd.getPushDefault());
+ 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(commit.getId(), git.getRepository()
+ .resolve("refs/remotes/origin/branchtopush"));
+ }
+ }
+
+ /**
* Check that missing refs don't cause errors during push
*
* @throws Exception
@@ -297,6 +1068,7 @@ public class PushCommandTest extends RepositoryTestCase {
public void testPushAfterGC() throws Exception {
// create other repository
Repository db2 = createWorkRepository();
+ addRepoToClose(db2);
// setup the first repository
final StoredConfig config = db.getConfig();
@@ -360,6 +1132,7 @@ public class PushCommandTest extends RepositoryTestCase {
// create other repository
Repository db2 = createWorkRepository();
+ addRepoToClose(db2);
// setup the first repository
final StoredConfig config = db.getConfig();
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
index 86239023dc..c64ff0b1c3 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
@@ -2927,8 +2927,8 @@ public class RebaseCommandTest extends RepositoryTestCase {
}
}
- @Test
- public void testRebaseInteractiveFixupWithBlankLines() throws Exception {
+ private void simpleFixup(String firstMessage, String secondMessage)
+ throws Exception {
// create file1 on master
writeTrashFile(FILE1, FILE1);
git.add().addFilepattern(FILE1).call();
@@ -2938,13 +2938,13 @@ public class RebaseCommandTest extends RepositoryTestCase {
// create file2 on master
writeTrashFile("file2", "file2");
git.add().addFilepattern("file2").call();
- git.commit().setMessage("Add file2").call();
+ git.commit().setMessage(firstMessage).call();
assertTrue(new File(db.getWorkTree(), "file2").exists());
// update FILE1 on master
writeTrashFile(FILE1, "blah");
git.add().addFilepattern(FILE1).call();
- git.commit().setMessage("updated file1 on master\n\nsome text").call();
+ git.commit().setMessage(secondMessage).call();
git.rebase().setUpstream("HEAD~2")
.runInteractively(new InteractiveHandler() {
@@ -2968,9 +2968,31 @@ public class RebaseCommandTest extends RepositoryTestCase {
try (RevWalk walk = new RevWalk(db)) {
ObjectId headId = db.resolve(Constants.HEAD);
RevCommit headCommit = walk.parseCommit(headId);
- assertEquals("Add file2",
- headCommit.getFullMessage());
+ assertEquals(firstMessage, headCommit.getFullMessage());
}
+
+ }
+
+ @Test
+ public void testRebaseInteractiveFixupWithBlankLines() throws Exception {
+ simpleFixup("Add file2", "updated file1 on master\n\nsome text");
+ }
+
+ @Test
+ public void testRebaseInteractiveFixupWithBlankLines2() throws Exception {
+ simpleFixup("Add file2\n\nBody\n",
+ "updated file1 on master\n\nsome text");
+ }
+
+ @Test
+ public void testRebaseInteractiveFixupWithHash() throws Exception {
+ simpleFixup("#Add file2", "updated file1 on master");
+ }
+
+ @Test
+ public void testRebaseInteractiveFixupWithHash2() throws Exception {
+ simpleFixup("#Add file2\n\nHeader has hash\n",
+ "#updated file1 on master");
}
@Test(expected = InvalidRebaseStepException.class)
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RevertCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RevertCommandTest.java
index cfa8486ac5..1c7b8d13a8 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RevertCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RevertCommandTest.java
@@ -9,6 +9,7 @@
*/
package org.eclipse.jgit.api;
+import static org.eclipse.jgit.lib.Constants.OBJECT_ID_ABBREV_STRING_LENGTH;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -166,7 +167,9 @@ public class RevertCommandTest extends RepositoryTestCase {
checkFile(new File(db.getWorkTree(), "a"), "first\n"
+ "<<<<<<< master\n" + "second\n" + "third\n" + "=======\n"
- + ">>>>>>> " + secondCommit.getId().abbreviate(7).name()
+ + ">>>>>>> "
+ + secondCommit.getId()
+ .abbreviate(OBJECT_ID_ABBREV_STRING_LENGTH).name()
+ " add second\n");
Iterator<RevCommit> history = git.log().call().iterator();
RevCommit revertCommit = history.next();
@@ -232,7 +235,7 @@ public class RevertCommandTest extends RepositoryTestCase {
assertTrue(new File(db.getDirectory(), Constants.MERGE_MSG).exists());
assertEquals("Revert \"" + sideCommit.getShortMessage()
+ "\"\n\nThis reverts commit " + sideCommit.getId().getName()
- + ".\n\nConflicts:\n\ta\n",
+ + ".\n\n# Conflicts:\n#\ta\n",
db.readMergeCommitMsg());
assertTrue(new File(db.getDirectory(), Constants.REVERT_HEAD)
.exists());
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java
index 5311edb0eb..19281f6c99 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java
@@ -21,8 +21,10 @@ import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.NoFilepatternException;
import org.eclipse.jgit.errors.NoWorkTreeException;
import org.eclipse.jgit.junit.RepositoryTestCase;
+import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.Sets;
import org.eclipse.jgit.storage.file.FileBasedConfig;
+import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.eclipse.jgit.util.FS;
import org.junit.Test;
@@ -181,4 +183,31 @@ public class StatusCommandTest extends RepositoryTestCase {
}
}
+ @Test
+ public void testNestedCommittedGitRepoAndPathFilter() throws Exception {
+ commitFile("file.txt", "file", "master");
+ try (Repository inner = new FileRepositoryBuilder()
+ .setWorkTree(new File(db.getWorkTree(), "subgit")).build()) {
+ inner.create();
+ writeTrashFile("subgit/sub.txt", "sub");
+ try (Git outerGit = new Git(db); Git innerGit = new Git(inner)) {
+ innerGit.add().addFilepattern("sub.txt").call();
+ innerGit.commit().setMessage("Inner commit").call();
+ outerGit.add().addFilepattern("subgit").call();
+ outerGit.commit().setMessage("Outer commit").call();
+ assertTrue(innerGit.status().call().isClean());
+ assertTrue(outerGit.status().call().isClean());
+ writeTrashFile("subgit/sub.txt", "sub2");
+ assertFalse(innerGit.status().call().isClean());
+ assertFalse(outerGit.status().call().isClean());
+ assertTrue(
+ outerGit.status().addPath("file.txt").call().isClean());
+ assertTrue(outerGit.status().addPath("doesntexist").call()
+ .isClean());
+ assertFalse(
+ outerGit.status().addPath("subgit").call().isClean());
+ }
+ }
+ }
+
}