CommitCommand: Don't allow amending on initial commit
Change-Id: I27b13510eb6756da21d0d359d76031da4a875e28
This commit is contained in:
parent
6da9473fe3
commit
c96b40d592
|
@ -50,6 +50,7 @@
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.jgit.api.errors.WrongRepositoryStateException;
|
||||||
import org.eclipse.jgit.diff.DiffEntry;
|
import org.eclipse.jgit.diff.DiffEntry;
|
||||||
import org.eclipse.jgit.dircache.DirCache;
|
import org.eclipse.jgit.dircache.DirCache;
|
||||||
import org.eclipse.jgit.lib.ConfigConstants;
|
import org.eclipse.jgit.lib.ConfigConstants;
|
||||||
|
@ -420,4 +421,10 @@ public void commitAfterSquashMerge() throws Exception {
|
||||||
assertEquals("commit: Squashed commit of the following:", db
|
assertEquals("commit: Squashed commit of the following:", db
|
||||||
.getReflogReader(db.getBranch()).getLastEntry().getComment());
|
.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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,6 +86,7 @@ commandWasCalledInTheWrongState=Command {0} was called in the wrong state
|
||||||
commitAlreadyExists=exists {0}
|
commitAlreadyExists=exists {0}
|
||||||
commitMessageNotSpecified=commit message not specified
|
commitMessageNotSpecified=commit message not specified
|
||||||
commitOnRepoWithoutHEADCurrentlyNotSupported=Commit on repo without HEAD currently not supported
|
commitOnRepoWithoutHEADCurrentlyNotSupported=Commit on repo without HEAD currently not supported
|
||||||
|
commitAmendOnInitialNotPossible=Amending is not possible on initial commit.
|
||||||
compressingObjects=Compressing objects
|
compressingObjects=Compressing objects
|
||||||
connectionFailed=connection failed
|
connectionFailed=connection failed
|
||||||
connectionTimeOut=Connection time out: {0}
|
connectionTimeOut=Connection time out: {0}
|
||||||
|
|
|
@ -176,6 +176,10 @@ public RevCommit call() throws GitAPIException, NoHeadException,
|
||||||
|
|
||||||
// determine the current HEAD and the commit it is referring to
|
// determine the current HEAD and the commit it is referring to
|
||||||
ObjectId headId = repo.resolve(Constants.HEAD + "^{commit}");
|
ObjectId headId = repo.resolve(Constants.HEAD + "^{commit}");
|
||||||
|
if (headId == null && amend)
|
||||||
|
throw new WrongRepositoryStateException(
|
||||||
|
JGitText.get().commitAmendOnInitialNotPossible);
|
||||||
|
|
||||||
if (headId != null)
|
if (headId != null)
|
||||||
if (amend) {
|
if (amend) {
|
||||||
RevCommit previousCommit = new RevWalk(repo)
|
RevCommit previousCommit = new RevWalk(repo)
|
||||||
|
|
|
@ -146,6 +146,7 @@ public static JGitText get() {
|
||||||
/***/ public String commitAlreadyExists;
|
/***/ public String commitAlreadyExists;
|
||||||
/***/ public String commitMessageNotSpecified;
|
/***/ public String commitMessageNotSpecified;
|
||||||
/***/ public String commitOnRepoWithoutHEADCurrentlyNotSupported;
|
/***/ public String commitOnRepoWithoutHEADCurrentlyNotSupported;
|
||||||
|
/***/ public String commitAmendOnInitialNotPossible;
|
||||||
/***/ public String compressingObjects;
|
/***/ public String compressingObjects;
|
||||||
/***/ public String connectionFailed;
|
/***/ public String connectionFailed;
|
||||||
/***/ public String connectionTimeOut;
|
/***/ public String connectionTimeOut;
|
||||||
|
|
Loading…
Reference in New Issue