]> source.dussan.org Git - jgit.git/commitdiff
CommitCommand: Don't allow amending on initial commit 76/8076/2
authorRobin Stocker <robin@nibor.org>
Sun, 7 Oct 2012 15:13:18 +0000 (17:13 +0200)
committerRobin Stocker <robin@nibor.org>
Sun, 7 Oct 2012 22:31:26 +0000 (00:31 +0200)
Change-Id: I27b13510eb6756da21d0d359d76031da4a875e28

org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java
org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java

index 44f1a48c31dedecf47372204b45e9c954af44458..3729387f32ed289535f39886527923bdc81a9827 100644 (file)
@@ -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();
+       }
 }
index 8a288cd07005afdf02111fe88105a287d8b3064f..2e974d6252b5565bb2089dde3d09efcf1a62f950 100644 (file)
@@ -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}
index ae6d62963ed4a48c16d37c59a7359d807b7c41f5..87c282d11047cc426f182a8953177a009e442944 100644 (file)
@@ -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)
index d70481450c27562e99cab79046e6769150f73e54..0c0ece7d1032876d92c6f60b413f7d9323503883 100644 (file)
@@ -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;