summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java51
-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.java14
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameGenerator.java10
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java1
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java3
6 files changed, 73 insertions, 7 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 44f1a48c31..3e73c7598e 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
@@ -48,14 +48,18 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
+import java.util.Date;
import java.util.List;
+import java.util.TimeZone;
+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;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.RefUpdate.Result;
import org.eclipse.jgit.lib.Repository;
@@ -420,4 +424,51 @@ 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();
+ }
+
+ @Test
+ public void commitAmendWithoutAuthorShouldSetOriginalAuthorAndAuthorTime()
+ throws Exception {
+ Git git = new Git(db);
+
+ writeTrashFile("file1", "file1");
+ git.add().addFilepattern("file1").call();
+
+ final String authorName = "First Author";
+ final String authorEmail = "author@example.org";
+ final Date authorDate = new Date(1349621117000L);
+ PersonIdent firstAuthor = new PersonIdent(authorName, authorEmail,
+ authorDate, TimeZone.getTimeZone("UTC"));
+ git.commit().setMessage("initial commit").setAuthor(firstAuthor).call();
+
+ RevCommit amended = git.commit().setAmend(true)
+ .setMessage("amend commit").call();
+
+ PersonIdent amendedAuthor = amended.getAuthorIdent();
+ assertEquals(authorName, amendedAuthor.getName());
+ assertEquals(authorEmail, amendedAuthor.getEmailAddress());
+ assertEquals(authorDate.getTime(), amendedAuthor.getWhen().getTime());
+ }
+
+ @Test
+ public void commitAmendWithAuthorShouldUseIt() throws Exception {
+ Git git = new Git(db);
+
+ writeTrashFile("file1", "file1");
+ git.add().addFilepattern("file1").call();
+ git.commit().setMessage("initial commit").call();
+
+ RevCommit amended = git.commit().setAmend(true)
+ .setAuthor("New Author", "newauthor@example.org")
+ .setMessage("amend commit").call();
+
+ PersonIdent amendedAuthor = amended.getAuthorIdent();
+ assertEquals("New Author", amendedAuthor.getName());
+ assertEquals("newauthor@example.org", amendedAuthor.getEmailAddress());
+ }
}
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 8a288cd070..2e974d6252 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 ae6d62963e..a166790a40 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)
@@ -183,6 +187,8 @@ public class CommitCommand extends GitCommand<RevCommit> {
RevCommit[] p = previousCommit.getParents();
for (int i = 0; i < p.length; i++)
parents.add(0, p[i].getId());
+ if (author == null)
+ author = previousCommit.getAuthorIdent();
} else {
parents.add(0, headId);
}
@@ -467,7 +473,7 @@ public class CommitCommand extends GitCommand<RevCommit> {
private void processOptions(RepositoryState state) throws NoMessageException {
if (committer == null)
committer = new PersonIdent(repo);
- if (author == null)
+ if (author == null && !amend)
author = committer;
// when doing a merge commit parse MERGE_HEAD and MERGE_MSG files
@@ -570,7 +576,8 @@ public class CommitCommand extends GitCommand<RevCommit> {
/**
* Sets the author for this {@code commit}. If no author is explicitly
* specified because this method is never called or called with {@code null}
- * value then the author will be set to the committer.
+ * value then the author will be set to the committer or to the original
+ * author when amending.
*
* @param author
* the author used for the {@code commit}
@@ -585,7 +592,8 @@ public class CommitCommand extends GitCommand<RevCommit> {
/**
* Sets the author for this {@code commit}. If no author is explicitly
* specified because this method is never called or called with {@code null}
- * value then the author will be set to the committer.
+ * value then the author will be set to the committer or to the original
+ * author when amending.
*
* @param name
* the name of the author used for the {@code commit}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameGenerator.java b/org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameGenerator.java
index ebb5897179..cea719ad70 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameGenerator.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameGenerator.java
@@ -76,7 +76,7 @@ import org.eclipse.jgit.treewalk.filter.PathFilter;
import org.eclipse.jgit.treewalk.filter.TreeFilter;
/**
- * Generate author information for lines based on introduction to the file.
+ * Generate author information for lines based on a provided file.
* <p>
* Applications that want a simple one-shot computation of blame for a file
* should use {@link #computeBlameResult()} to prepare the entire result in one
@@ -144,12 +144,14 @@ public class BlameGenerator {
private Candidate currentSource;
/**
- * Create a blame generator for the repository and path
- *
+ * Create a blame generator for the repository and path (relative to
+ * repository)
+ *
* @param repository
* repository to access revision data from.
* @param path
- * initial path of the file to start scanning.
+ * initial path of the file to start scanning (relative to the
+ * repository).
*/
public BlameGenerator(Repository repository, String path) {
this.repository = repository;
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 d70481450c..0c0ece7d10 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;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java
index 0ef40d96e4..93428f9851 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java
@@ -620,6 +620,9 @@ public class RevWalk implements Iterable<RevCommit> {
* <p>
* The commit may or may not exist in the repository. It is impossible to
* tell from this method's return value.
+ * <p>
+ * See {@link #parseHeaders(RevObject)} and {@link #parseBody(RevObject)}
+ * for loading contents.
*
* @param id
* name of the commit object.