summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorRobin Stocker2012-10-07 11:13:18 (EDT)
committer Robin Stocker2012-10-07 18:31:26 (EDT)
commitc96b40d5921d68edb96afad38b9c171388af4e05 (patch)
tree2d5e915466da59425d8d1ca3856d00f0005dc596
parent6da9473fe363c6419d35f5d0af49fef98ad1a0bc (diff)
downloadjgit-c96b40d5921d68edb96afad38b9c171388af4e05.zip
jgit-c96b40d5921d68edb96afad38b9c171388af4e05.tar.gz
jgit-c96b40d5921d68edb96afad38b9c171388af4e05.tar.bz2
CommitCommand: Don't allow amending on initial commitrefs/changes/76/8076/2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java7
-rw-r--r--org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties1
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java1
4 files changed, 13 insertions, 0 deletions
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 44f1a48..3729387 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
@@ -50,6 +50,7 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import java.util.List;
+import org.eclipse.jgit.api.errors.WrongRepositoryStateException;
import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.lib.ConfigConstants;
@@ -420,4 +421,10 @@ public class CommitCommandTest extends RepositoryTestCase {
assertEquals("commit: Squashed commit of the following:", db
.getReflogReader(db.getBranch()).getLastEntry().getComment());
}
+
+ @Test(expected = WrongRepositoryStateException.class)
+ public void commitAmendOnInitialShouldFail() throws Exception {
+ Git git = new Git(db);
+ git.commit().setAmend(true).setMessage("initial commit").call();
+ }
}
diff --git a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
index 8a288cd..2e974d6 100644
--- a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
+++ b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
@@ -86,6 +86,7 @@ commandWasCalledInTheWrongState=Command {0} was called in the wrong state
commitAlreadyExists=exists {0}
commitMessageNotSpecified=commit message not specified
commitOnRepoWithoutHEADCurrentlyNotSupported=Commit on repo without HEAD currently not supported
+commitAmendOnInitialNotPossible=Amending is not possible on initial commit.
compressingObjects=Compressing objects
connectionFailed=connection failed
connectionTimeOut=Connection time out: {0}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java
index ae6d629..87c282d 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java
@@ -176,6 +176,10 @@ public class CommitCommand extends GitCommand<RevCommit> {
// determine the current HEAD and the commit it is referring to
ObjectId headId = repo.resolve(Constants.HEAD + "^{commit}");
+ if (headId == null && amend)
+ throw new WrongRepositoryStateException(
+ JGitText.get().commitAmendOnInitialNotPossible);
+
if (headId != null)
if (amend) {
RevCommit previousCommit = new RevWalk(repo)
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
index d704814..0c0ece7 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
@@ -146,6 +146,7 @@ public class JGitText extends TranslationBundle {
/***/ public String commitAlreadyExists;
/***/ public String commitMessageNotSpecified;
/***/ public String commitOnRepoWithoutHEADCurrentlyNotSupported;
+ /***/ public String commitAmendOnInitialNotPossible;
/***/ public String compressingObjects;
/***/ public String connectionFailed;
/***/ public String connectionTimeOut;