diff options
15 files changed, 71 insertions, 40 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java index 73530efca1..de430294fb 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java @@ -69,6 +69,7 @@ import org.eclipse.jgit.storage.file.FileRepository; import org.eclipse.jgit.transport.FetchResult; import org.eclipse.jgit.transport.RefSpec; import org.eclipse.jgit.transport.RemoteConfig; +import org.eclipse.jgit.transport.TagOpt; import org.eclipse.jgit.transport.Transport; import org.eclipse.jgit.transport.URIish; import org.kohsuke.args4j.Argument; @@ -143,6 +144,7 @@ class Clone extends AbstractFetchCommand { final Transport tn = Transport.open(db, remoteName); final FetchResult r; try { + tn.setTagOpt(TagOpt.FETCH_TAGS); r = tn.fetch(new TextProgressMonitor(), null); } finally { tn.close(); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java index 98f086d460..e1e38e5bc8 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java @@ -69,7 +69,8 @@ class Init extends TextBuiltin { protected void run() throws Exception { InitCommand command = Git.init(); command.setBare(bare); - command.setDirectory(new File(gitdir)); + if (gitdir != null) + command.setDirectory(new File(gitdir)); Repository repository = command.call().getRepository(); out.println(MessageFormat.format( CLIText.get().initializedEmptyGitRepositoryIn, repository diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java index eb671a2899..51ae054da3 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java @@ -49,17 +49,25 @@ import static org.junit.Assert.fail; import java.io.File; import java.io.IOException; +import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.RefUpdate; +import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.RepositoryTestCase; +import org.eclipse.jgit.revwalk.RevBlob; import org.junit.Test; public class CloneCommandTest extends RepositoryTestCase { private Git git; + private TestRepository<Repository> tr; + public void setUp() throws Exception { super.setUp(); + tr = new TestRepository<Repository>(db); + git = new Git(db); // commit something writeTrashFile("Test.txt", "Hello world"); @@ -75,6 +83,8 @@ public class CloneCommandTest extends RepositoryTestCase { writeTrashFile("Test.txt", "Some change"); git.add().addFilepattern("Test.txt").call(); git.commit().setMessage("Second commit").call(); + RevBlob blob = tr.blob("blob-not-in-master-branch"); + git.tag().setName("tag-for-blob").setObjectId(blob).call(); } @Test @@ -87,6 +97,8 @@ public class CloneCommandTest extends RepositoryTestCase { + git.getRepository().getWorkTree().getPath()); Git git2 = command.call(); assertNotNull(git2); + ObjectId id = git2.getRepository().resolve("tag-for-blob"); + assertNotNull(id); } catch (Exception e) { fail(e.getMessage()); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java index 3d79357bd8..d863f45d53 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java @@ -68,6 +68,7 @@ import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevWalk; +import org.eclipse.jgit.storage.file.ReflogReader; import org.eclipse.jgit.treewalk.TreeWalk; import org.eclipse.jgit.util.FileUtils; import org.junit.Test; @@ -150,8 +151,8 @@ public class CommitAndLogCommandTests extends RepositoryTestCase { @Test public void testSomeCommits() throws NoHeadException, NoMessageException, - UnmergedPathException, ConcurrentRefUpdateException, - JGitInternalException, WrongRepositoryStateException { + ConcurrentRefUpdateException, JGitInternalException, + WrongRepositoryStateException, IOException { // do 4 commits Git git = new Git(db); @@ -180,6 +181,8 @@ public class CommitAndLogCommandTests extends RepositoryTestCase { l--; } assertEquals(l, -1); + ReflogReader reader = db.getReflogReader(Constants.HEAD); + assertTrue(reader.getLastEntry().getComment().startsWith("commit:")); } // try to do a commit without specifying a message. Should fail! @@ -319,8 +322,8 @@ public class CommitAndLogCommandTests extends RepositoryTestCase { @Test public void testCommitAmend() throws NoHeadException, NoMessageException, - UnmergedPathException, ConcurrentRefUpdateException, - JGitInternalException, WrongRepositoryStateException { + ConcurrentRefUpdateException, JGitInternalException, + WrongRepositoryStateException, IOException { Git git = new Git(db); git.commit().setMessage("first comit").call(); // typo git.commit().setAmend(true).setMessage("first commit").call(); @@ -332,6 +335,9 @@ public class CommitAndLogCommandTests extends RepositoryTestCase { c++; } assertEquals(1, c); + ReflogReader reader = db.getReflogReader(Constants.HEAD); + assertTrue(reader.getLastEntry().getComment() + .startsWith("commit (amend):")); } @Test diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackWriterTest.java index 7a829dee00..fb78ec02c7 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackWriterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackWriterTest.java @@ -58,7 +58,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -125,14 +124,16 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { /** * Test constructor for exceptions, default settings, initialization. + * + * @throws IOException */ @Test - public void testContructor() { + public void testContructor() throws IOException { writer = new PackWriter(config, db.newObjectReader()); assertEquals(false, writer.isDeltaBaseAsOffset()); assertEquals(true, config.isReuseDeltas()); assertEquals(true, config.isReuseObjects()); - assertEquals(0, writer.getObjectsNumber()); + assertEquals(0, writer.getObjectCount()); } /** @@ -163,7 +164,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { public void testWriteEmptyPack1() throws IOException { createVerifyOpenPack(EMPTY_LIST_OBJECT, EMPTY_LIST_OBJECT, false, false); - assertEquals(0, writer.getObjectsNumber()); + assertEquals(0, writer.getObjectCount()); assertEquals(0, pack.getObjectCount()); assertEquals("da39a3ee5e6b4b0d3255bfef95601890afd80709", writer .computeName().name()); @@ -177,9 +178,9 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { */ @Test public void testWriteEmptyPack2() throws IOException { - createVerifyOpenPack(EMPTY_LIST_REVS.iterator()); + createVerifyOpenPack(EMPTY_LIST_REVS); - assertEquals(0, writer.getObjectsNumber()); + assertEquals(0, writer.getObjectCount()); assertEquals(0, pack.getObjectCount()); } @@ -320,9 +321,9 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { for (int i = 0; i < forcedOrder.length; i++) forcedOrderRevs[i] = parser.parseAny(forcedOrder[i]); - createVerifyOpenPack(Arrays.asList(forcedOrderRevs).iterator()); + createVerifyOpenPack(Arrays.asList(forcedOrderRevs)); - assertEquals(forcedOrder.length, writer.getObjectsNumber()); + assertEquals(forcedOrder.length, writer.getObjectCount()); verifyObjectsOrder(forcedOrder); assertEquals("ed3f96b8327c7c66b0f8f70056129f0769323d86", writer .computeName().name()); @@ -465,7 +466,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { ObjectId.fromString("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259"), ObjectId.fromString("6ff87c4664981e4397625791c8ea3bbb5f2279a3") }; - assertEquals(expectedOrder.length, writer.getObjectsNumber()); + assertEquals(expectedOrder.length, writer.getObjectCount()); verifyObjectsOrder(expectedOrder); assertEquals("34be9032ac282b11fa9babdc2b2a93ca996c9c2f", writer .computeName().name()); @@ -494,7 +495,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { expectedOrder[4] = expectedOrder[5]; expectedOrder[5] = temp; } - assertEquals(expectedOrder.length, writer.getObjectsNumber()); + assertEquals(expectedOrder.length, writer.getObjectCount()); verifyObjectsOrder(expectedOrder); assertEquals("ed3f96b8327c7c66b0f8f70056129f0769323d86", writer .computeName().name()); @@ -513,7 +514,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { ObjectId.fromString("82c6b885ff600be425b4ea96dee75dca255b69e7"), ObjectId.fromString("aabf2ffaec9b497f0950352b3e582d73035c2035"), ObjectId.fromString("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259") }; - assertEquals(writtenObjects.length, writer.getObjectsNumber()); + assertEquals(writtenObjects.length, writer.getObjectCount()); ObjectId expectedObjects[]; if (thin) { expectedObjects = new ObjectId[4]; @@ -544,11 +545,12 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { verifyOpenPack(thin); } - private void createVerifyOpenPack(final Iterator<RevObject> objectSource) + private void createVerifyOpenPack(final List<RevObject> objectSource) throws MissingObjectException, IOException { NullProgressMonitor m = NullProgressMonitor.INSTANCE; writer = new PackWriter(config, db.newObjectReader()); - writer.preparePack(objectSource); + writer.preparePack(objectSource.iterator()); + assertEquals(objectSource.size(), writer.getObjectCount()); writer.writePack(m, m, os); writer.release(); verifyOpenPack(false); diff --git a/org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties b/org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties index 9fe17fef00..61291f67d0 100644 --- a/org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties +++ b/org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties @@ -180,8 +180,8 @@ exceptionCaughtDuringExecutionOfResetCommand=Exception caught during execution o exceptionCaughtDuringExecutionOfRevertCommand=Exception caught during execution of revert command. {0} exceptionCaughtDuringExecutionOfRmCommand=Exception caught during execution of rm command exceptionCaughtDuringExecutionOfTagCommand=Exception caught during execution of tag command -exceptionOccuredDuringAddingOfOptionToALogCommand=Exception occured during adding of {0} as option to a Log command -exceptionOccuredDuringReadingOfGIT_DIR=Exception occured during reading of $GIT_DIR/{0}. {1} +exceptionOccurredDuringAddingOfOptionToALogCommand=Exception occurred during adding of {0} as option to a Log command +exceptionOccurredDuringReadingOfGIT_DIR=Exception occurred during reading of $GIT_DIR/{0}. {1} expectedACKNAKFoundEOF=Expected ACK/NAK, found EOF expectedACKNAKGot=Expected ACK/NAK, got: {0} expectedBooleanStringValue=Expected boolean string value diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java b/org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java index e07a4252ee..1ce088461f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java @@ -240,8 +240,8 @@ public class JGitText extends TranslationBundle { /***/ public String exceptionCaughtDuringExecutionOfRevertCommand; /***/ public String exceptionCaughtDuringExecutionOfRmCommand; /***/ public String exceptionCaughtDuringExecutionOfTagCommand; - /***/ public String exceptionOccuredDuringAddingOfOptionToALogCommand; - /***/ public String exceptionOccuredDuringReadingOfGIT_DIR; + /***/ public String exceptionOccurredDuringAddingOfOptionToALogCommand; + /***/ public String exceptionOccurredDuringReadingOfGIT_DIR; /***/ public String expectedACKNAKFoundEOF; /***/ public String expectedACKNAKGot; /***/ public String expectedBooleanStringValue; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java index 54457e523d..0257f3264f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java @@ -66,6 +66,7 @@ import org.eclipse.jgit.transport.CredentialsProvider; import org.eclipse.jgit.transport.FetchResult; import org.eclipse.jgit.transport.RefSpec; import org.eclipse.jgit.transport.RemoteConfig; +import org.eclipse.jgit.transport.TagOpt; import org.eclipse.jgit.transport.URIish; /** @@ -149,6 +150,7 @@ public class CloneCommand implements Callable<Git> { FetchCommand command = new FetchCommand(repo); command.setRemote(remote); command.setProgressMonitor(monitor); + command.setTagOpt(TagOpt.FETCH_TAGS); if (credentialsProvider != null) command.setCredentialsProvider(credentialsProvider); return command.call(); 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 8d9ce98187..472b778c87 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java @@ -211,8 +211,9 @@ public class CommitCommand extends GitCommand<RevCommit> { RevCommit revCommit = revWalk.parseCommit(commitId); RefUpdate ru = repo.updateRef(Constants.HEAD); ru.setNewObjectId(commitId); - ru.setRefLogMessage("commit : " - + revCommit.getShortMessage(), false); + String prefix = amend ? "commit (amend): " : "commit: "; + ru.setRefLogMessage( + prefix + revCommit.getShortMessage(), false); ru.setExpectedOldObjectId(headId); Result rc = ru.forceUpdate(); @@ -440,7 +441,7 @@ public class CommitCommand extends GitCommand<RevCommit> { parents = repo.readMergeHeads(); } catch (IOException e) { throw new JGitInternalException(MessageFormat.format( - JGitText.get().exceptionOccuredDuringReadingOfGIT_DIR, + JGitText.get().exceptionOccurredDuringReadingOfGIT_DIR, Constants.MERGE_HEAD, e), e); } if (message == null) { @@ -448,7 +449,7 @@ public class CommitCommand extends GitCommand<RevCommit> { message = repo.readMergeCommitMsg(); } catch (IOException e) { throw new JGitInternalException(MessageFormat.format( - JGitText.get().exceptionOccuredDuringReadingOfGIT_DIR, + JGitText.get().exceptionOccurredDuringReadingOfGIT_DIR, Constants.MERGE_MSG, e), e); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/InitCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/InitCommand.java index fdadf9690d..d68f4e27f2 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/InitCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/InitCommand.java @@ -83,7 +83,7 @@ public class InitCommand implements Callable<Git> { } else if (builder.getGitDir() == null) { File d = new File("."); if (!bare) - d = new File(d, Constants.DOT_GIT); + d = new File(d, Constants.DOT_GIT).getCanonicalFile(); builder.setGitDir(d); } Repository repository = builder.build(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java index aa1cdea7d4..6d60f5d74f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java @@ -219,7 +219,7 @@ public class LogCommand extends GitCommand<Iterable<RevCommit>> { throw e; } catch (IOException e) { throw new JGitInternalException(MessageFormat.format( - JGitText.get().exceptionOccuredDuringAddingOfOptionToALogCommand + JGitText.get().exceptionOccurredDuringAddingOfOptionToALogCommand , start), e); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeResult.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeResult.java index 045fecd219..ceef6e69a2 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeResult.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeResult.java @@ -311,7 +311,7 @@ public class MergeResult { * } * }</pre> * - * @return the conflicts or <code>null</code> if no conflict occured + * @return the conflicts or <code>null</code> if no conflict occurred */ public Map<String, int[][]> getConflicts() { return conflicts; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java index e5861ec58c..525e4b352a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java @@ -351,7 +351,7 @@ public class ResolveMerger extends ThreeWayMerger { * the file in the working tree * @return <code>false</code> if the merge will fail because the index entry * didn't match ours or the working-dir file was dirty and a - * conflict occured + * conflict occurred * @throws MissingObjectException * @throws IncorrectObjectTypeException * @throws CorruptObjectException @@ -507,7 +507,7 @@ public class ResolveMerger extends ThreeWayMerger { } if (result.containsConflicts()) { - // a conflict occured, the file will contain conflict markers + // a conflict occurred, the file will contain conflict markers // the index will be populated with the three stages and only the // workdir (if used) contains the halfways merged content add(tw.getRawPath(), base, DirCacheEntry.STAGE_1); @@ -516,7 +516,7 @@ public class ResolveMerger extends ThreeWayMerger { mergeResults.put(tw.getPathString(), result); return false; } else { - // no conflict occured, the file will contain fully merged content. + // no conflict occurred, the file will contain fully merged content. // the index will be populated with the new merged version DirCacheEntry dce = new DirCacheEntry(tw.getPathString()); dce.setFileMode(tw.getFileMode(0)); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java index 2eb2700dda..eaa866348e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java @@ -402,8 +402,18 @@ public class PackWriter { * Returns objects number in a pack file that was created by this writer. * * @return number of objects in pack. + * @throws IOException + * a cached pack cannot supply its object count. */ - public long getObjectsNumber() { + public long getObjectCount() throws IOException { + if (stats.totalObjects == 0) { + long objCnt = 0; + for (List<ObjectToPack> list : objectsLists) + objCnt += list.size(); + for (CachedPack pack : cachedPacks) + objCnt += pack.getObjectCount(); + return objCnt; + } return stats.totalObjects; } @@ -635,13 +645,8 @@ public class PackWriter { final PackOutputStream out = new PackOutputStream(writeMonitor, packStream, this); - long objCnt = 0; - for (List<ObjectToPack> list : objectsLists) - objCnt += list.size(); - for (CachedPack pack : cachedPacks) - objCnt += pack.getObjectCount(); + long objCnt = getObjectCount(); stats.totalObjects = objCnt; - writeMonitor.beginTask(JGitText.get().writingObjects, (int) objCnt); long writeStart = System.currentTimeMillis(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkPushConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkPushConnection.java index 9ce0ec1b3c..1d1e67402f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkPushConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkPushConnection.java @@ -230,7 +230,7 @@ class WalkPushConnection extends BaseConnection implements PushConnection { // be an empty pack, as the remote has all objects it // needs to complete this change. // - if (writer.getObjectsNumber() == 0) + if (writer.getObjectCount() == 0) return; packNames = new LinkedHashMap<String, String>(); |