From 53a64a0b8c7d841c8d677962947a4c90765274b5 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Tue, 3 May 2016 11:27:13 -0700 Subject: [PATCH 01/10] RepoCommandTest: Improve assertion message for remote branch recording Change-Id: Ic14e9f9c4bf007b464e463f5047ec5a8d0b9236c Signed-off-by: Stefan Beller --- .../tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java index 2cec34ba8..6e6f4ed57 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java @@ -743,9 +743,9 @@ public class RepoCommandTest extends RepositoryTestCase { FileBasedConfig c = new FileBasedConfig(gitmodules, FS.DETECTED); c.load(); - assertEquals("standard branches work", "master", + assertEquals("Recording remote branches should work for short branch descriptions", "master", c.getString("submodule", "with-branch", "branch")); - assertEquals("long branches work", "refs/heads/master", + assertEquals("Recording remote branches should work for full ref specs", "refs/heads/master", c.getString("submodule", "with-long-branch", "branch")); } } From 063548b9afb516010cc114e33d5df7a09ea042fb Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 28 Apr 2016 17:27:57 -0700 Subject: [PATCH 02/10] RepoCommand: remove --record-remote-branches This function only works in bare mode, and the command line works in non-bare mode, so there's no point in pretending to support it here. Change-Id: Ia017aded93d072bdb9947ec08c424256c3abe438 Signed-off-by: Stefan Beller --- .../org/eclipse/jgit/pgm/internal/CLIText.properties | 1 - org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Repo.java | 4 ---- 2 files changed, 5 deletions(-) diff --git a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties index fc412ba56..abe04b888 100644 --- a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties +++ b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties @@ -211,7 +211,6 @@ untrackedFiles=Untracked files: updating=Updating {0}..{1} usage_Aggressive=This option will cause gc to more aggressively optimize the repository at the expense of taking much more time usage_bareClone=Make a bare Git repository. That is, instead of creating [DIRECTORY] and placing the administrative files in [DIRECTORY]/.git, make the [DIRECTORY] itself the $GIT_DIR. -usage_branches=Set branch field in .gitmodules usage_Blame=Show what revision and author last modified each line usage_CommandLineClientForamazonsS3Service=Command line client for Amazon's S3 service usage_CommitAll=commit all modified and deleted files diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Repo.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Repo.java index ea59527fe..bec5003a1 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Repo.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Repo.java @@ -58,16 +58,12 @@ class Repo extends TextBuiltin { @Argument(required = true, metaVar = "metaVar_path", usage = "usage_pathToXml") private String path; - @Option(name = "--record-remote-branch", usage = "usage_branches") - private boolean branches; - @Override protected void run() throws Exception { new RepoCommand(db) .setURI(uri) .setPath(path) .setGroups(groups) - .setRecordRemoteBranch(branches) .call(); } } From 6569a876a3ce8031d1ff89e8a80a4727f89036cf Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Thu, 19 May 2016 15:25:02 +0200 Subject: [PATCH 03/10] [findBugs] Prevent potential NPE in CloneCommand.init() File.listFiles() returns null if the File is not a directory, improve validation of directory and gitDir to fix this. Change-Id: I763d08835faf96a0beb8e706992df0908526bd2c Signed-off-by: Matthias Sohn --- .../org/eclipse/jgit/internal/JGitText.properties | 2 ++ .../src/org/eclipse/jgit/api/CloneCommand.java | 10 ++++++++++ .../src/org/eclipse/jgit/internal/JGitText.java | 2 ++ 3 files changed, 14 insertions(+) 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 f7d9374bd..b71e48b52 100644 --- a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties +++ b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties @@ -314,6 +314,8 @@ indexFileIsTooLargeForJgit=Index file is too large for jgit indexSignatureIsInvalid=Index signature is invalid: {0} indexWriteException=Modified index could not be written initFailedBareRepoDifferentDirs=When initializing a bare repo with directory {0} and separate git-dir {1} specified both folders must point to the same location +initFailedDirIsNoDirectory=Cannot set directory to ''{0}'' which is not a directory +initFailedGitDirIsNoDirectory=Cannot set git-dir to ''{0}'' which is not a directory initFailedNonBareRepoSameDirs=When initializing a non-bare repo with directory {0} and separate git-dir {1} specified both folders should not point to the same location inMemoryBufferLimitExceeded=In-memory buffer limit exceeded inputDidntMatchLength=Input did not match supplied length. {0} bytes are missing. 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 2ac872950..ff15fd00c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java @@ -155,6 +155,7 @@ public class CloneCommand extends TransportCommand { command.setBare(bare); if (directory == null && gitDir == null) directory = new File(u.getHumanishName(), Constants.DOT_GIT); + validateDirs(directory, gitDir, bare); if (directory != null && directory.exists() && directory.listFiles().length != 0) throw new JGitInternalException(MessageFormat.format( @@ -511,6 +512,15 @@ public class CloneCommand extends TransportCommand { private static void validateDirs(File directory, File gitDir, boolean bare) throws IllegalStateException { if (directory != null) { + if (directory.exists() && !directory.isDirectory()) { + throw new IllegalStateException(MessageFormat.format( + JGitText.get().initFailedDirIsNoDirectory, directory)); + } + if (gitDir != null && gitDir.exists() && !gitDir.isDirectory()) { + throw new IllegalStateException(MessageFormat.format( + JGitText.get().initFailedGitDirIsNoDirectory, + gitDir)); + } if (bare) { if (gitDir != null && !gitDir.equals(directory)) throw new IllegalStateException(MessageFormat.format( 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 d07c001b6..7c101780a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java @@ -373,6 +373,8 @@ public class JGitText extends TranslationBundle { /***/ public String indexSignatureIsInvalid; /***/ public String indexWriteException; /***/ public String initFailedBareRepoDifferentDirs; + /***/ public String initFailedDirIsNoDirectory; + /***/ public String initFailedGitDirIsNoDirectory; /***/ public String initFailedNonBareRepoSameDirs; /***/ public String inMemoryBufferLimitExceeded; /***/ public String inputDidntMatchLength; From 5b104a72759c25623c9d4e6206cddd4eafe603d3 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Tue, 24 May 2016 01:12:20 +0200 Subject: [PATCH 04/10] Better report on client side if push failed due to too large object JGits PushCommand and BasePackPushConnection were throwing a generic exception when the pushed pack-file was rejected by the server since it contained too large objects. Teach JGit to better analyze the server's response to detect this situation and throw a more specific exception. Detect this situation by parsing the status line sent by the server. This change only recognizes the response sent by a JGit based server. All other servers which report such problems in a different way still lead to a generic TransportExceptions. Also see https://git.eclipse.org/r/#/c/46348/ Change-Id: I8d6d65e4585ebb3846f7207e7d1a2f82fa9cbd86 Signed-off-by: Matthias Sohn --- .../src/org/eclipse/jgit/api/PushCommand.java | 4 ++ .../errors/TooLargeObjectInPackException.java | 65 +++++++++++++++++++ .../errors/TooLargeObjectInPackException.java | 17 ++++- .../transport/BasePackPushConnection.java | 9 ++- 4 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 org.eclipse.jgit/src/org/eclipse/jgit/api/errors/TooLargeObjectInPackException.java diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java index f5b82bdd7..367b50931 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java @@ -55,6 +55,7 @@ import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.InvalidRemoteException; import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.errors.NotSupportedException; +import org.eclipse.jgit.errors.TooLargeObjectInPackException; import org.eclipse.jgit.errors.TooLargePackException; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.internal.JGitText; @@ -160,6 +161,9 @@ public class PushCommand extends } catch (TooLargePackException e) { throw new org.eclipse.jgit.api.errors.TooLargePackException( e.getMessage(), e); + } catch (TooLargeObjectInPackException e) { + throw new org.eclipse.jgit.api.errors.TooLargeObjectInPackException( + e.getMessage(), e); } catch (TransportException e) { throw new org.eclipse.jgit.api.errors.TransportException( e.getMessage(), e); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/errors/TooLargeObjectInPackException.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/errors/TooLargeObjectInPackException.java new file mode 100644 index 000000000..08c25c28e --- /dev/null +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/errors/TooLargeObjectInPackException.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2016, Matthias Sohn and + * other copyright owners as documented in the project's IP log. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v1.0 which accompanies this + * distribution, is reproduced below, and is available at + * http://www.eclipse.org/org/documents/edl-v10.php + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * - Neither the name of the Eclipse Foundation, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package org.eclipse.jgit.api.errors; + +/** + * Exception thrown when the server rejected a too large pack + * + * @since 4.4 + */ +public class TooLargeObjectInPackException extends TransportException { + private static final long serialVersionUID = 1L; + + /** + * @param msg + * message describing the transport failure. + */ + public TooLargeObjectInPackException(String msg) { + super(msg); + } + + /** + * @param msg + * message describing the transport exception. + * @param cause + * why the transport failed. + */ + public TooLargeObjectInPackException(String msg, Throwable cause) { + super(msg, cause); + } +} diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/TooLargeObjectInPackException.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/TooLargeObjectInPackException.java index 79515fcd7..b5b1af542 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/errors/TooLargeObjectInPackException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/TooLargeObjectInPackException.java @@ -43,13 +43,13 @@ package org.eclipse.jgit.errors; -import java.io.IOException; import java.text.MessageFormat; import org.eclipse.jgit.internal.JGitText; +import org.eclipse.jgit.transport.URIish; /** Thrown when PackParser finds an object larger than a predefined limit */ -public class TooLargeObjectInPackException extends IOException { +public class TooLargeObjectInPackException extends TransportException { private static final long serialVersionUID = 1L; /** @@ -79,4 +79,17 @@ public class TooLargeObjectInPackException extends IOException { super(MessageFormat.format(JGitText.get().receivePackObjectTooLarge2, Long.valueOf(objectSize), Long.valueOf(maxObjectSizeLimit))); } + + /** + * Construct a too large object in pack exception. + * + * @param uri + * URI used for transport + * @param s + * message + * @since 4.4 + */ + public TooLargeObjectInPackException(URIish uri, String s) { + super(uri.setPass(null) + ": " + s); //$NON-NLS-1$ + } } \ No newline at end of file diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackPushConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackPushConnection.java index 963de35d4..9b8ba8098 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackPushConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackPushConnection.java @@ -57,6 +57,7 @@ import java.util.Set; import org.eclipse.jgit.errors.NoRemoteRepositoryException; import org.eclipse.jgit.errors.NotSupportedException; import org.eclipse.jgit.errors.PackProtocolException; +import org.eclipse.jgit.errors.TooLargeObjectInPackException; import org.eclipse.jgit.errors.TooLargePackException; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.internal.JGitText; @@ -328,12 +329,16 @@ public abstract class BasePackPushConnection extends BasePackConnection implemen if (!unpackLine.startsWith("unpack ")) //$NON-NLS-1$ throw new PackProtocolException(uri, MessageFormat.format(JGitText.get().unexpectedReportLine, unpackLine)); final String unpackStatus = unpackLine.substring("unpack ".length()); //$NON-NLS-1$ - if (unpackStatus.startsWith("error Pack exceeds the limit of")) //$NON-NLS-1$ + if (unpackStatus.startsWith("error Pack exceeds the limit of")) {//$NON-NLS-1$ throw new TooLargePackException(uri, unpackStatus.substring("error ".length())); //$NON-NLS-1$ - if (!unpackStatus.equals("ok")) //$NON-NLS-1$ + } else if (unpackStatus.startsWith("error Object too large")) {//$NON-NLS-1$ + throw new TooLargeObjectInPackException(uri, + unpackStatus.substring("error ".length())); //$NON-NLS-1$ + } else if (!unpackStatus.equals("ok")) { //$NON-NLS-1$ throw new TransportException(uri, MessageFormat.format( JGitText.get().errorOccurredDuringUnpackingOnTheRemoteEnd, unpackStatus)); + } String refLine; while ((refLine = pckIn.readString()) != PacketLineIn.END) { From bfebe6ae4bf50250eca20b7c6bea0d06e771a817 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Thu, 19 May 2016 15:31:51 +0200 Subject: [PATCH 05/10] [findBugs] Prevent potential NPE in FileLfsRepository.getOutputStream() Change-Id: I6f91997e8a976e5f4ace91c082d8b9adf1451adc Signed-off-by: Matthias Sohn --- .../org/eclipse/jgit/lfs/server/fs/FileLfsRepository.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/FileLfsRepository.java b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/FileLfsRepository.java index 2e71c0407..dd70a364e 100644 --- a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/FileLfsRepository.java +++ b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/FileLfsRepository.java @@ -147,7 +147,10 @@ public class FileLfsRepository implements LargeFileRepository { AtomicObjectOutputStream getOutputStream(AnyLongObjectId id) throws IOException { Path path = getPath(id); - Files.createDirectories(path.getParent()); + Path parent = path.getParent(); + if (parent != null) { + Files.createDirectories(parent); + } return new AtomicObjectOutputStream(path, id); } From 4c236ff4bbf664fd177a33f42517b0eef52510c8 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Fri, 20 May 2016 11:28:21 +0200 Subject: [PATCH 06/10] Replace use of deprecated method Repository.getRef() Change-Id: Iecf2b8deafc4991cc3333702fb9fa0638be7b914 Signed-off-by: Matthias Sohn --- .../src/org/eclipse/jgit/junit/RepositoryTestCase.java | 2 +- .../src/org/eclipse/jgit/junit/TestRepository.java | 6 +++--- .../src/org/eclipse/jgit/pgm/Branch.java | 8 ++++---- .../src/org/eclipse/jgit/pgm/Commit.java | 2 +- org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java | 2 +- .../src/org/eclipse/jgit/pgm/Merge.java | 4 ++-- .../src/org/eclipse/jgit/pgm/Status.java | 2 +- .../tst/org/eclipse/jgit/api/ResetCommandTest.java | 2 +- .../src/org/eclipse/jgit/api/AddNoteCommand.java | 2 +- .../src/org/eclipse/jgit/api/CheckoutCommand.java | 10 +++++----- .../src/org/eclipse/jgit/api/CherryPickCommand.java | 2 +- .../src/org/eclipse/jgit/api/CommitCommand.java | 2 +- .../src/org/eclipse/jgit/api/CreateBranchCommand.java | 6 +++--- .../src/org/eclipse/jgit/api/DeleteBranchCommand.java | 4 ++-- .../src/org/eclipse/jgit/api/DeleteTagCommand.java | 2 +- .../src/org/eclipse/jgit/api/ListBranchCommand.java | 2 +- .../src/org/eclipse/jgit/api/ListNotesCommand.java | 2 +- .../src/org/eclipse/jgit/api/MergeCommand.java | 2 +- .../src/org/eclipse/jgit/api/PushCommand.java | 4 ++-- .../src/org/eclipse/jgit/api/RebaseCommand.java | 6 +++--- .../src/org/eclipse/jgit/api/RemoveNoteCommand.java | 2 +- .../src/org/eclipse/jgit/api/RenameBranchCommand.java | 6 +++--- .../src/org/eclipse/jgit/api/ResetCommand.java | 2 +- .../src/org/eclipse/jgit/api/RevertCommand.java | 2 +- .../src/org/eclipse/jgit/api/ShowNoteCommand.java | 2 +- .../src/org/eclipse/jgit/api/StashCreateCommand.java | 4 ++-- .../src/org/eclipse/jgit/api/StashDropCommand.java | 4 ++-- .../src/org/eclipse/jgit/api/StashListCommand.java | 2 +- .../src/org/eclipse/jgit/api/SubmoduleSyncCommand.java | 2 +- .../src/org/eclipse/jgit/api/TagCommand.java | 2 +- .../jgit/internal/storage/file/FileRepository.java | 2 +- .../src/org/eclipse/jgit/lib/BranchTrackingStatus.java | 4 ++-- .../src/org/eclipse/jgit/lib/Repository.java | 4 ++-- .../src/org/eclipse/jgit/submodule/SubmoduleWalk.java | 4 ++-- .../src/org/eclipse/jgit/transport/Transport.java | 2 +- 35 files changed, 58 insertions(+), 58 deletions(-) diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java index 86b87b407..c282df03b 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java @@ -406,7 +406,7 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase { String originalBranch = repo.getFullBranch(); boolean empty = repo.resolve(Constants.HEAD) == null; if (!empty) { - if (repo.getRef(branch) == null) + if (repo.findRef(branch) == null) git.branchCreate().setName(branch).call(); git.checkout().setName(branch).call(); } diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java index 07df56d3f..25e313cee 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java @@ -501,7 +501,7 @@ public class TestRepository { */ public CommitBuilder amendRef(String ref) throws Exception { String name = normalizeRef(ref); - Ref r = db.getRef(name); + Ref r = db.exactRef(name); if (r == null) throw new IOException("Not a ref: " + ref); return amend(pool.parseCommit(r.getObjectId()), branch(name).commit()); @@ -703,7 +703,7 @@ public class TestRepository { RevCommit parent = commit.getParent(0); pool.parseHeaders(parent); - Ref headRef = db.getRef(Constants.HEAD); + Ref headRef = db.exactRef(Constants.HEAD); if (headRef == null) throw new IOException("Missing HEAD"); RevCommit head = pool.parseCommit(headRef.getObjectId()); @@ -1025,7 +1025,7 @@ public class TestRepository { CommitBuilder(BranchBuilder b) throws Exception { branch = b; - Ref ref = db.getRef(branch.ref); + Ref ref = db.exactRef(branch.ref); if (ref != null && ref.getObjectId() != null) parent(pool.parseCommit(ref.getObjectId())); } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java index bf6ee3a94..5f3740cbb 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java @@ -169,7 +169,7 @@ class Branch extends TextBuiltin { if (rename) { String src, dst; if (otherBranch == null) { - final Ref head = db.getRef(Constants.HEAD); + final Ref head = db.exactRef(Constants.HEAD); if (head != null && head.isSymbolic()) { src = head.getLeaf().getName(); } else { @@ -178,7 +178,7 @@ class Branch extends TextBuiltin { dst = branch; } else { src = branch; - final Ref old = db.getRef(src); + final Ref old = db.findRef(src); if (old == null) throw die(MessageFormat.format(CLIText.get().doesNotExist, src)); if (!old.getName().startsWith(Constants.R_HEADS)) @@ -204,7 +204,7 @@ class Branch extends TextBuiltin { } else { startBranch = Constants.HEAD; } - Ref startRef = db.getRef(startBranch); + Ref startRef = db.findRef(startBranch); ObjectId startAt = db.resolve(startBranch + "^0"); //$NON-NLS-1$ if (startRef != null) { startBranch = startRef.getName(); @@ -243,7 +243,7 @@ class Branch extends TextBuiltin { } private void list() throws Exception { - Ref head = db.getRef(Constants.HEAD); + Ref head = db.exactRef(Constants.HEAD); // This can happen if HEAD is stillborn if (head != null) { String current = head.getLeaf().getName(); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Commit.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Commit.java index 38d8d70ce..2cfbd86fa 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Commit.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Commit.java @@ -95,7 +95,7 @@ class Commit extends TextBuiltin { commitCmd.setOnly(p); commitCmd.setAmend(amend); commitCmd.setAll(all); - Ref head = db.getRef(Constants.HEAD); + Ref head = db.exactRef(Constants.HEAD); if (head == null) { throw die(CLIText.get().onBranchToBeBorn); } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java index 6947cdd10..62e77285b 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java @@ -228,7 +228,7 @@ class Log extends RevWalkTextBuiltin { } private void addNoteMap(String notesRef) throws IOException { - Ref notes = db.getRef(notesRef); + Ref notes = db.exactRef(notesRef); if (notes == null) return; RevCommit notesCommit = argWalk.parseCommit(notes.getObjectId()); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java index e739b58ae..485efc542 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java @@ -114,7 +114,7 @@ class Merge extends TextBuiltin { } // determine the other revision we want to merge with HEAD - final Ref srcRef = db.getRef(ref); + final Ref srcRef = db.findRef(ref); final ObjectId src = db.resolve(ref + "^{commit}"); //$NON-NLS-1$ if (src == null) throw die(MessageFormat.format( @@ -209,7 +209,7 @@ class Merge extends TextBuiltin { } private Ref getOldHead() throws IOException { - Ref oldHead = db.getRef(Constants.HEAD); + Ref oldHead = db.exactRef(Constants.HEAD); if (oldHead == null) { throw die(CLIText.get().onBranchToBeBorn); } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Status.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Status.java index 6a6322131..de3df806d 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Status.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Status.java @@ -204,7 +204,7 @@ class Status extends TextBuiltin { private void printLongStatus(org.eclipse.jgit.api.Status status) throws IOException { // Print current branch name - final Ref head = db.getRef(Constants.HEAD); + final Ref head = db.exactRef(Constants.HEAD); if (head != null && head.isSymbolic()) { String branch = Repository.shortenRefName(head.getLeaf().getName()); outw.println(CLIText.formatLine(MessageFormat.format( diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java index 725ebc0d2..a4a699ef2 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java @@ -596,7 +596,7 @@ public class ResetCommandTest extends RepositoryTestCase { * @throws IOException */ private void assertSameAsHead(Ref ref) throws IOException { - Ref headRef = db.getRef(Constants.HEAD); + Ref headRef = db.exactRef(Constants.HEAD); assertEquals(headRef.getName(), ref.getName()); assertEquals(headRef.getObjectId(), ref.getObjectId()); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/AddNoteCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/AddNoteCommand.java index 9cf888195..4235e3786 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/AddNoteCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/AddNoteCommand.java @@ -87,7 +87,7 @@ public class AddNoteCommand extends GitCommand { RevCommit notesCommit = null; try (RevWalk walk = new RevWalk(repo); ObjectInserter inserter = repo.newObjectInserter()) { - Ref ref = repo.getRef(notesRef); + Ref ref = repo.findRef(notesRef); // if we have a notes ref, use it if (ref != null) { notesCommit = walk.parseCommit(ref.getObjectId()); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java index 6c8028945..65508eff4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java @@ -223,7 +223,7 @@ public class CheckoutCommand extends GitCommand { } } - Ref headRef = repo.getRef(Constants.HEAD); + Ref headRef = repo.exactRef(Constants.HEAD); if (headRef == null) { // TODO Git CLI supports checkout from unborn branch, we should // also allow this @@ -242,7 +242,7 @@ public class CheckoutCommand extends GitCommand { JGitText.get().checkoutUnexpectedResult, r.name())); this.status = CheckoutResult.NOT_TRIED_RESULT; - return repo.getRef(Constants.HEAD); + return repo.exactRef(Constants.HEAD); } branch = getStartPointObjectId(); } else { @@ -277,7 +277,7 @@ public class CheckoutCommand extends GitCommand { } finally { dc.unlock(); } - Ref ref = repo.getRef(name); + Ref ref = repo.findRef(name); if (ref != null && !ref.getName().startsWith(Constants.R_HEADS)) ref = null; String toName = Repository.shortenRefName(name); @@ -289,7 +289,7 @@ public class CheckoutCommand extends GitCommand { updateResult = refUpdate.link(ref.getName()); else if (orphan) { updateResult = refUpdate.link(getBranchName()); - ref = repo.getRef(Constants.HEAD); + ref = repo.exactRef(Constants.HEAD); } else { refUpdate.setNewObjectId(newCommit); updateResult = refUpdate.forceUpdate(); @@ -519,7 +519,7 @@ public class CheckoutCommand extends GitCommand { .get().branchNameInvalid, name == null ? "" : name)); //$NON-NLS-1$ if (orphan) { - Ref refToCheck = repo.getRef(getBranchName()); + Ref refToCheck = repo.exactRef(getBranchName()); if (refToCheck != null) throw new RefAlreadyExistsException(MessageFormat.format( JGitText.get().refAlreadyExists, name)); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java index d6e930ada..e82a69798 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java @@ -126,7 +126,7 @@ public class CherryPickCommand extends GitCommand { try (RevWalk revWalk = new RevWalk(repo)) { // get the head commit - Ref headRef = repo.getRef(Constants.HEAD); + Ref headRef = repo.exactRef(Constants.HEAD); if (headRef == null) throw new NoHeadException( JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported); 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 e54169ade..561319c44 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java @@ -195,7 +195,7 @@ public class CommitCommand extends GitCommand { } } - Ref head = repo.getRef(Constants.HEAD); + Ref head = repo.exactRef(Constants.HEAD); if (head == null) throw new NoHeadException( JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CreateBranchCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CreateBranchCommand.java index a6646602e..69d82bcc6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CreateBranchCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CreateBranchCommand.java @@ -125,7 +125,7 @@ public class CreateBranchCommand extends GitCommand { checkCallable(); processOptions(); try (RevWalk revWalk = new RevWalk(repo)) { - Ref refToCheck = repo.getRef(name); + Ref refToCheck = repo.findRef(name); boolean exists = refToCheck != null && refToCheck.getName().startsWith(Constants.R_HEADS); if (!force && exists) @@ -135,7 +135,7 @@ public class CreateBranchCommand extends GitCommand { ObjectId startAt = getStartPointObjectId(); String startPointFullName = null; if (startPoint != null) { - Ref baseRef = repo.getRef(startPoint); + Ref baseRef = repo.findRef(startPoint); if (baseRef != null) startPointFullName = baseRef.getName(); } @@ -207,7 +207,7 @@ public class CreateBranchCommand extends GitCommand { .get().createBranchUnexpectedResult, updateResult .name())); - Ref result = repo.getRef(name); + Ref result = repo.findRef(name); if (result == null) throw new JGitInternalException( JGitText.get().createBranchFailedUnknownReason); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/DeleteBranchCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/DeleteBranchCommand.java index 61beb2f0d..ecc1ce5a7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/DeleteBranchCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/DeleteBranchCommand.java @@ -114,7 +114,7 @@ public class DeleteBranchCommand extends GitCommand> { for (String branchName : branchNames) { if (branchName == null) continue; - Ref currentRef = repo.getRef(branchName); + Ref currentRef = repo.findRef(branchName); if (currentRef == null) continue; @@ -130,7 +130,7 @@ public class DeleteBranchCommand extends GitCommand> { for (String branchName : branchNames) { if (branchName == null) continue; - Ref currentRef = repo.getRef(branchName); + Ref currentRef = repo.findRef(branchName); if (currentRef == null) continue; String fullName = currentRef.getName(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/DeleteTagCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/DeleteTagCommand.java index ae511c6df..3aeec48d9 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/DeleteTagCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/DeleteTagCommand.java @@ -90,7 +90,7 @@ public class DeleteTagCommand extends GitCommand> { for (String tagName : tags) { if (tagName == null) continue; - Ref currentRef = repo.getRef(tagName); + Ref currentRef = repo.findRef(tagName); if (currentRef == null) continue; String fullName = currentRef.getName(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/ListBranchCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/ListBranchCommand.java index 904c74f6d..efcfd1682 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/ListBranchCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/ListBranchCommand.java @@ -108,7 +108,7 @@ public class ListBranchCommand extends GitCommand> { Collection refs = new ArrayList(); // Also return HEAD if it's detached - Ref head = repo.getRef(Constants.HEAD); + Ref head = repo.exactRef(Constants.HEAD); if (head != null && head.getLeaf().getName().equals(Constants.HEAD)) refs.add(head); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/ListNotesCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/ListNotesCommand.java index 796ac798f..ff963ede8 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/ListNotesCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/ListNotesCommand.java @@ -82,7 +82,7 @@ public class ListNotesCommand extends GitCommand> { List notes = new ArrayList(); NoteMap map = NoteMap.newEmptyMap(); try (RevWalk walk = new RevWalk(repo)) { - Ref ref = repo.getRef(notesRef); + Ref ref = repo.findRef(notesRef); // if we have a notes ref, use it if (ref != null) { RevCommit notesCommit = walk.parseCommit(ref.getObjectId()); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java index bfe90a3a4..38b10971f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java @@ -231,7 +231,7 @@ public class MergeCommand extends GitCommand { RevWalk revWalk = null; DirCacheCheckout dco = null; try { - Ref head = repo.getRef(Constants.HEAD); + Ref head = repo.exactRef(Constants.HEAD); if (head == null) throw new NoHeadException( JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java index 367b50931..0a49f7806 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java @@ -131,7 +131,7 @@ public class PushCommand extends refSpecs.addAll(config.getPushRefSpecs()); } if (refSpecs.isEmpty()) { - Ref head = repo.getRef(Constants.HEAD); + Ref head = repo.exactRef(Constants.HEAD); if (head != null && head.isSymbolic()) refSpecs.add(new RefSpec(head.getLeaf().getName())); } @@ -348,7 +348,7 @@ public class PushCommand extends } else { Ref src; try { - src = repo.getRef(nameOrSpec); + src = repo.findRef(nameOrSpec); } catch (IOException e) { throw new JGitInternalException( JGitText.get().exceptionCaughtDuringExecutionOfPushCommand, diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java index 643ec7a51..2d6a76b39 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java @@ -419,7 +419,7 @@ public class RebaseCommand extends GitCommand { private void updateStashRef(ObjectId commitId, PersonIdent refLogIdent, String refLogMessage) throws IOException { - Ref currentRef = repo.getRef(Constants.R_STASH); + Ref currentRef = repo.exactRef(Constants.R_STASH); RefUpdate refUpdate = repo.updateRef(Constants.R_STASH); refUpdate.setNewObjectId(commitId); refUpdate.setRefLogIdent(refLogIdent); @@ -750,7 +750,7 @@ public class RebaseCommand extends GitCommand { private void resetSoftToParent() throws IOException, GitAPIException, CheckoutConflictException { - Ref ref = repo.getRef(Constants.ORIG_HEAD); + Ref ref = repo.exactRef(Constants.ORIG_HEAD); ObjectId orig_head = ref == null ? null : ref.getObjectId(); try { // we have already commited the cherry-picked commit. @@ -1207,7 +1207,7 @@ public class RebaseCommand extends GitCommand { } private Ref getHead() throws IOException, RefNotFoundException { - Ref head = repo.getRef(Constants.HEAD); + Ref head = repo.exactRef(Constants.HEAD); if (head == null || head.getObjectId() == null) throw new RefNotFoundException(MessageFormat.format( JGitText.get().refNotResolved, Constants.HEAD)); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RemoveNoteCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RemoveNoteCommand.java index a526c2753..1c4880c1e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RemoveNoteCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RemoveNoteCommand.java @@ -85,7 +85,7 @@ public class RemoveNoteCommand extends GitCommand { ObjectInserter inserter = repo.newObjectInserter()) { NoteMap map = NoteMap.newEmptyMap(); RevCommit notesCommit = null; - Ref ref = repo.getRef(notesRef); + Ref ref = repo.exactRef(notesRef); // if we have a notes ref, use it if (ref != null) { notesCommit = walk.parseCommit(ref.getObjectId()); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RenameBranchCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RenameBranchCommand.java index 0731dd45e..044a48611 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RenameBranchCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RenameBranchCommand.java @@ -107,11 +107,11 @@ public class RenameBranchCommand extends GitCommand { try { String fullOldName; String fullNewName; - if (repo.getRef(newName) != null) + if (repo.findRef(newName) != null) throw new RefAlreadyExistsException(MessageFormat.format( JGitText.get().refAlreadyExists1, newName)); if (oldName != null) { - Ref ref = repo.getRef(oldName); + Ref ref = repo.findRef(oldName); if (ref == null) throw new RefNotFoundException(MessageFormat.format( JGitText.get().refNotResolved, oldName)); @@ -186,7 +186,7 @@ public class RenameBranchCommand extends GitCommand { repoConfig.save(); } - Ref resultRef = repo.getRef(newName); + Ref resultRef = repo.findRef(newName); if (resultRef == null) throw new JGitInternalException( JGitText.get().renameBranchFailedUnknownReason); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java index 4c91e6c17..e385a5d17 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java @@ -171,7 +171,7 @@ public class ResetCommand extends GitCommand { // reset [commit] -- paths resetIndexForPaths(commitTree); setCallable(false); - return repo.getRef(Constants.HEAD); + return repo.exactRef(Constants.HEAD); } final Ref result; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RevertCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RevertCommand.java index 801577362..9d79ed029 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RevertCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RevertCommand.java @@ -129,7 +129,7 @@ public class RevertCommand extends GitCommand { try (RevWalk revWalk = new RevWalk(repo)) { // get the head commit - Ref headRef = repo.getRef(Constants.HEAD); + Ref headRef = repo.exactRef(Constants.HEAD); if (headRef == null) throw new NoHeadException( JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/ShowNoteCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/ShowNoteCommand.java index 82db88190..168ea51e7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/ShowNoteCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/ShowNoteCommand.java @@ -79,7 +79,7 @@ public class ShowNoteCommand extends GitCommand { NoteMap map = NoteMap.newEmptyMap(); RevCommit notesCommit = null; try (RevWalk walk = new RevWalk(repo)) { - Ref ref = repo.getRef(notesRef); + Ref ref = repo.exactRef(notesRef); // if we have a notes ref, use it if (ref != null) { notesCommit = walk.parseCommit(ref.getObjectId()); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java index ef32ac929..ee9b7fcf7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java @@ -206,7 +206,7 @@ public class StashCreateCommand extends GitCommand { String refLogMessage) throws IOException { if (ref == null) return; - Ref currentRef = repo.getRef(ref); + Ref currentRef = repo.findRef(ref); RefUpdate refUpdate = repo.updateRef(ref); refUpdate.setNewObjectId(commitId); refUpdate.setRefLogIdent(refLogIdent); @@ -220,7 +220,7 @@ public class StashCreateCommand extends GitCommand { private Ref getHead() throws GitAPIException { try { - Ref head = repo.getRef(Constants.HEAD); + Ref head = repo.exactRef(Constants.HEAD); if (head == null || head.getObjectId() == null) throw new NoHeadException(JGitText.get().headRequiredToStash); return head; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/StashDropCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashDropCommand.java index f6903be05..6e1d0f270 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/StashDropCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashDropCommand.java @@ -118,7 +118,7 @@ public class StashDropCommand extends GitCommand { private Ref getRef() throws GitAPIException { try { - return repo.getRef(R_STASH); + return repo.exactRef(R_STASH); } catch (IOException e) { throw new InvalidRefNameException(MessageFormat.format( JGitText.get().cannotRead, R_STASH), e); @@ -236,7 +236,7 @@ public class StashDropCommand extends GitCommand { updateRef(stashRef, entryId); try { - Ref newStashRef = repo.getRef(R_STASH); + Ref newStashRef = repo.exactRef(R_STASH); return newStashRef != null ? newStashRef.getObjectId() : null; } catch (IOException e) { throw new InvalidRefNameException(MessageFormat.format( diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/StashListCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashListCommand.java index 59a83aae3..aedc9a6e1 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/StashListCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashListCommand.java @@ -81,7 +81,7 @@ public class StashListCommand extends GitCommand> { checkCallable(); try { - if (repo.getRef(Constants.R_STASH) == null) + if (repo.exactRef(Constants.R_STASH) == null) return Collections.emptyList(); } catch (IOException e) { throw new InvalidRefNameException(MessageFormat.format( diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleSyncCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleSyncCommand.java index e7fe71a89..024f0bebd 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleSyncCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleSyncCommand.java @@ -101,7 +101,7 @@ public class SubmoduleSyncCommand extends GitCommand> { * @throws IOException */ protected String getHeadBranch(final Repository subRepo) throws IOException { - Ref head = subRepo.getRef(Constants.HEAD); + Ref head = subRepo.exactRef(Constants.HEAD); if (head != null && head.isSymbolic()) return Repository.shortenRefName(head.getLeaf().getName()); else diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/TagCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/TagCommand.java index ca98cedfd..39dd42cc5 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/TagCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/TagCommand.java @@ -184,7 +184,7 @@ public class TagCommand extends GitCommand { switch (updateResult) { case NEW: case FORCED: - return repo.getRef(refName); + return repo.exactRef(refName); case LOCK_FAILURE: throw new ConcurrentRefUpdateException( JGitText.get().couldNotLockHEAD, tagRef.getRef(), diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java index b02efedea..53fd37e53 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java @@ -491,7 +491,7 @@ public class FileRepository extends Repository { * @throws IOException the ref could not be accessed. */ public ReflogReader getReflogReader(String refName) throws IOException { - Ref ref = getRef(refName); + Ref ref = findRef(refName); if (ref != null) return new ReflogReaderImpl(this, ref.getName()); return null; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BranchTrackingStatus.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BranchTrackingStatus.java index 1525e5b18..d4fccf907 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BranchTrackingStatus.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BranchTrackingStatus.java @@ -79,11 +79,11 @@ public class BranchTrackingStatus { if (trackingBranch == null) return null; - Ref tracking = repository.getRef(trackingBranch); + Ref tracking = repository.exactRef(trackingBranch); if (tracking == null) return null; - Ref local = repository.getRef(fullBranchName); + Ref local = repository.exactRef(fullBranchName); if (local == null) return null; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java index ba0dea39f..5703dddf1 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java @@ -898,7 +898,7 @@ public abstract class Repository implements AutoCloseable { * This is essentially the same as doing: * *
-	 * return getRef(Constants.HEAD).getTarget().getName()
+	 * return exactRef(Constants.HEAD).getTarget().getName()
 	 * 
* * Except when HEAD is detached, in which case this method returns the @@ -912,7 +912,7 @@ public abstract class Repository implements AutoCloseable { */ @Nullable public String getFullBranch() throws IOException { - Ref head = getRef(Constants.HEAD); + Ref head = exactRef(Constants.HEAD); if (head == null) { return null; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java index 6263d4b74..5b9e8d902 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java @@ -264,7 +264,7 @@ public class SubmoduleWalk implements AutoCloseable { String remoteName = null; // Look up remote URL associated wit HEAD ref - Ref ref = parent.getRef(Constants.HEAD); + Ref ref = parent.exactRef(Constants.HEAD); if (ref != null) { if (ref.isSymbolic()) ref = ref.getLeaf(); @@ -704,7 +704,7 @@ public class SubmoduleWalk implements AutoCloseable { if (subRepo == null) return null; try { - Ref head = subRepo.getRef(Constants.HEAD); + Ref head = subRepo.exactRef(Constants.HEAD); return head != null ? head.getLeaf().getName() : null; } finally { subRepo.close(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java index 9e6d1f68f..862b3bdeb 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java @@ -629,7 +629,7 @@ public abstract class Transport implements AutoCloseable { for (final RefSpec spec : procRefs) { String srcSpec = spec.getSource(); - final Ref srcRef = db.getRef(srcSpec); + final Ref srcRef = db.findRef(srcSpec); if (srcRef != null) srcSpec = srcRef.getName(); From bd63a56da2562ad0f80137aa1cb3ffa0f2296c51 Mon Sep 17 00:00:00 2001 From: Terry Parker Date: Tue, 31 May 2016 10:14:55 -0700 Subject: [PATCH 07/10] Remove the deprecated TestRepository.getClock() method Gitles was the holdout and TestRepository.getClock() was removed via: https://gerrit.googlesource.com/gitiles/+/f10481d8384d1695e6981b805c4e5e462e4b71ea Change-Id: I90c0fc17be4891545b097a49763b0f0c202cc004 Signed-off-by: Terry Parker --- .../src/org/eclipse/jgit/junit/TestRepository.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java index 25e313cee..0a2345f08 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java @@ -211,17 +211,6 @@ public class TestRepository { return new Date(mockSystemReader.getCurrentTime()); } - /** - * @return current date. - * - * @deprecated Use {@link #getDate()} instead. - */ - @Deprecated - public Date getClock() { - // Remove once Gitiles and Gerrit are using the updated JGit. - return getDate(); - } - /** @return timezone used for default identities. */ public TimeZone getTimeZone() { return mockSystemReader.getTimeZone(); From ddd0fe257bc78dc9646407e7121769d0c03e0d94 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Tue, 31 May 2016 15:18:20 -0700 Subject: [PATCH 08/10] RepoCommand: record manifest groups as submodule labels Git core learned about attributes in pathspecs: pathspec: allow querying for attributes The pathspec mechanism is extended via the new ":(attr:eol=input)pattern/to/match" syntax to filter paths so that it requires paths to not just match the given pattern but also have the specified attrs attached for them to be chosen. (177161a5f7, 2016-05-20) We intend to use these pathspec attribute patterns for submodule grouping, similar to the grouping in repo. So the RepoCommand which translates repo manifest files into submodules should propagate this information along. This requires writing information to the .gitattributes file instead of the .gitmodules file. For now we just overwrite any existing .gitattributes file and do not care about prior attributes set. If this becomes an issue we need to figure out how to correctly amend the grouping information to an existing .gitattributes file. Change-Id: I0f55b45786b6b8fc3d5be62d7f6aab9ac00ed60e Signed-off-by: Stefan Beller --- .../eclipse/jgit/gitrepo/RepoCommandTest.java | 49 ++++++++++++++++++ .../org/eclipse/jgit/gitrepo/RepoCommand.java | 48 +++++++++++++++-- .../org/eclipse/jgit/gitrepo/RepoProject.java | 51 +++++++++++++++++-- 3 files changed, 140 insertions(+), 8 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java index 6e6f4ed57..d12e5fc0e 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java @@ -49,6 +49,9 @@ import static org.junit.Assert.assertTrue; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.junit.JGitTestUtil; @@ -751,6 +754,52 @@ public class RepoCommandTest extends RepositoryTestCase { } } + + @Test + public void testRecordSubmoduleLabels() throws Exception { + try ( + Repository remoteDb = createBareRepository(); + Repository tempDb = createWorkRepository()) { + StringBuilder xmlContent = new StringBuilder(); + xmlContent + .append("\n") + .append("") + .append("") + .append("") + .append("") + .append(""); + JGitTestUtil.writeTrashFile(tempDb, "manifest.xml", + xmlContent.toString()); + + RepoCommand command = new RepoCommand(remoteDb); + command.setPath(tempDb.getWorkTree().getAbsolutePath() + "/manifest.xml") + .setURI(rootUri) + .setRecordSubmoduleLabels(true) + .call(); + // Clone it + File directory = createTempDirectory("testBareRepo"); + try (Repository localDb = Git.cloneRepository() + .setDirectory(directory) + .setURI(remoteDb.getDirectory().toURI().toString()).call() + .getRepository();) { + // The .gitattributes file should exist + File gitattributes = new File(localDb.getWorkTree(), + ".gitattributes"); + assertTrue("The .gitattributes file should exist", + gitattributes.exists()); + try (BufferedReader reader = new BufferedReader( + new FileReader(gitattributes));) { + String content = reader.readLine(); + assertEquals(".gitattributes content should be as expected", + "/test a1 a2", content); + } + } + } + } + @Test public void testRemoteRevision() throws Exception { StringBuilder xmlContent = new StringBuilder(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java index ee937f585..6f682ee98 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java @@ -51,8 +51,10 @@ import java.io.IOException; import java.io.InputStream; import java.text.MessageFormat; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.Set; import org.eclipse.jgit.annotations.Nullable; import org.eclipse.jgit.api.Git; @@ -110,6 +112,7 @@ public class RepoCommand extends GitCommand { private String branch; private String targetBranch = Constants.HEAD; private boolean recordRemoteBranch = false; + private boolean recordSubmoduleLabels = false; private PersonIdent author; private RemoteReader callback; private InputStream inputStream; @@ -344,6 +347,21 @@ public class RepoCommand extends GitCommand { return this; } + /** + * Set whether the labels field should be recorded as a label in + * .gitattributes. + *

+ * Not implemented for non-bare repositories. + * + * @param enable Whether to record the labels in the .gitattributes + * @return this command + * @since 4.4 + */ + public RepoCommand setRecordSubmoduleLabels(boolean enable) { + this.recordSubmoduleLabels = enable; + return this; + } + /** * The progress monitor associated with the clone operation. By default, * this is set to NullProgressMonitor @@ -452,7 +470,8 @@ public class RepoCommand extends GitCommand { addSubmodule(proj.getUrl(), proj.getPath(), proj.getRevision(), - proj.getCopyFiles()); + proj.getCopyFiles(), + proj.getGroups()); } } catch (GitAPIException | IOException e) { throw new ManifestErrorException(e); @@ -472,6 +491,7 @@ public class RepoCommand extends GitCommand { ObjectInserter inserter = repo.newObjectInserter(); try (RevWalk rw = new RevWalk(repo)) { Config cfg = new Config(); + StringBuilder attributes = new StringBuilder(); for (RepoProject proj : bareProjects) { String name = proj.getPath(); String nameUri = proj.getName(); @@ -493,6 +513,17 @@ public class RepoCommand extends GitCommand { proj.getRevision()); } } + if (recordSubmoduleLabels) { + StringBuilder rec = new StringBuilder(); + rec.append("/"); //$NON-NLS-1$ + rec.append(name); + for (String group : proj.getGroups()) { + rec.append(" "); //$NON-NLS-1$ + rec.append(group); + } + rec.append("\n"); //$NON-NLS-1$ + attributes.append(rec.toString()); + } cfg.setString("submodule", name, "path", name); //$NON-NLS-1$ //$NON-NLS-2$ cfg.setString("submodule", name, "url", nameUri); //$NON-NLS-1$ //$NON-NLS-2$ @@ -522,6 +553,16 @@ public class RepoCommand extends GitCommand { dcEntry.setFileMode(FileMode.REGULAR_FILE); builder.add(dcEntry); + if (recordSubmoduleLabels) { + // create a new DirCacheEntry for .gitattributes file. + final DirCacheEntry dcEntryAttr = new DirCacheEntry(Constants.DOT_GIT_ATTRIBUTES); + ObjectId attrId = inserter.insert(Constants.OBJ_BLOB, + attributes.toString().getBytes(Constants.CHARACTER_ENCODING)); + dcEntryAttr.setObjectId(attrId); + dcEntryAttr.setFileMode(FileMode.REGULAR_FILE); + builder.add(dcEntryAttr); + } + builder.finish(); ObjectId treeId = index.writeTree(inserter); @@ -575,9 +616,10 @@ public class RepoCommand extends GitCommand { } private void addSubmodule(String url, String name, String revision, - List copyfiles) throws GitAPIException, IOException { + List copyfiles, Set groups) + throws GitAPIException, IOException { if (repo.isBare()) { - RepoProject proj = new RepoProject(url, name, revision, null, null); + RepoProject proj = new RepoProject(url, name, revision, null, groups); proj.addCopyFiles(copyfiles); bareProjects.add(proj); } else { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java index f6d1209cb..1b251368d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java @@ -134,10 +134,11 @@ public class RepoProject implements Comparable { * @param remote * name of the remote definition * @param groups - * comma separated group list + * set of groups + * @since 4.4 */ public RepoProject(String name, String path, String revision, - String remote, String groups) { + String remote, Set groups) { if (name == null) { throw new NullPointerException(); } @@ -148,12 +149,29 @@ public class RepoProject implements Comparable { this.path = name; this.revision = revision; this.remote = remote; - this.groups = new HashSet(); - if (groups != null && groups.length() > 0) - this.groups.addAll(Arrays.asList(groups.split(","))); //$NON-NLS-1$ + this.groups = groups; copyfiles = new ArrayList(); } + /** + * @param name + * the relative path to the {@code remote} + * @param path + * the relative path to the super project + * @param revision + * a SHA-1 or branch name or tag name + * @param remote + * name of the remote definition + * @param groups + * comma separated group list + */ + public RepoProject(String name, String path, String revision, + String remote, String groups) { + this(name, path, revision, remote, new HashSet()); + if (groups != null && groups.length() > 0) + this.setGroups(groups); + } + /** * Set the url of the sub repo. * @@ -165,6 +183,19 @@ public class RepoProject implements Comparable { return this; } + /** + * Set the url of the sub repo. + * + * @param url + * @return this for chaining. + * @since 4.4 + */ + public RepoProject setGroups(String groups) { + this.groups.clear(); + this.groups.addAll(Arrays.asList(groups.split(","))); //$NON-NLS-1$ + return this; + } + /** * Set the default revision for the sub repo. * @@ -240,6 +271,16 @@ public class RepoProject implements Comparable { return groups.contains(group); } + /** + * Return the set of groups. + * + * @return a Set of groups. + * @since 4.4 + */ + public Set getGroups() { + return groups; + } + /** * Add a copy file configuration. * From 6ae4ed0f7da996bde2ba5cdc26daff979c9f6866 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Tue, 31 May 2016 15:19:52 -0700 Subject: [PATCH 09/10] RepoCommand: record manifest shallow recommendation in .gitmodules Git core learned about the submodule..shallow option in .gitmodules files, which is a recommendation to clone a submodule shallow. A repo manifest may record a clone depth recommendation as an optional field, which contains more information than a binary shallow/nonshallow recommendation, so any attempted conversion may be lossy. In practice the clone depth recommendation is either '1' or doesn't exist, which is the binary behavior we have in Git core. Change-Id: I51aa9cb6d1d9660dae6ab6d21ad7bae9bc5325e6 Signed-off-by: Stefan Beller --- .../eclipse/jgit/gitrepo/RepoCommandTest.java | 48 +++++++++++++++++++ .../eclipse/jgit/gitrepo/ManifestParser.java | 2 + .../org/eclipse/jgit/gitrepo/RepoCommand.java | 33 +++++++++++-- .../org/eclipse/jgit/gitrepo/RepoProject.java | 26 +++++++++- 4 files changed, 104 insertions(+), 5 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java index d12e5fc0e..80a0250de 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java @@ -44,6 +44,7 @@ package org.eclipse.jgit.gitrepo; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.io.BufferedReader; @@ -800,6 +801,53 @@ public class RepoCommandTest extends RepositoryTestCase { } } + @Test + public void testRecordShallowRecommendation() throws Exception { + try ( + Repository remoteDb = createBareRepository(); + Repository tempDb = createWorkRepository()) { + StringBuilder xmlContent = new StringBuilder(); + xmlContent + .append("\n") + .append("") + .append("") + .append("") + .append("") + .append("") + .append(""); + JGitTestUtil.writeTrashFile(tempDb, "manifest.xml", + xmlContent.toString()); + + RepoCommand command = new RepoCommand(remoteDb); + command.setPath(tempDb.getWorkTree().getAbsolutePath() + "/manifest.xml") + .setURI(rootUri) + .setRecommendShallow(true) + .call(); + // Clone it + File directory = createTempDirectory("testBareRepo"); + try (Repository localDb = Git.cloneRepository() + .setDirectory(directory) + .setURI(remoteDb.getDirectory().toURI().toString()).call() + .getRepository();) { + // The .gitmodules file should exist + File gitmodules = new File(localDb.getWorkTree(), + ".gitmodules"); + assertTrue("The .gitmodules file should exist", + gitmodules.exists()); + FileBasedConfig c = new FileBasedConfig(gitmodules, + FS.DETECTED); + c.load(); + assertEquals("Recording shallow configuration should work", "true", + c.getString("submodule", "shallow-please", "shallow")); + assertNull("Recording non shallow configuration should work", + c.getString("submodule", "non-shallow", "shallow")); + } + } + } + @Test public void testRemoteRevision() throws Exception { StringBuilder xmlContent = new StringBuilder(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java index 796b422bb..2370ae14c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java @@ -192,6 +192,8 @@ public class ManifestParser extends DefaultHandler { attributes.getValue("revision"), //$NON-NLS-1$ attributes.getValue("remote"), //$NON-NLS-1$ attributes.getValue("groups")); //$NON-NLS-1$ + currentProject.setRecommendShallow( + attributes.getValue("clone-depth")); //$NON-NLS-1$ } else if ("remote".equals(qName)) { //$NON-NLS-1$ String alias = attributes.getValue("alias"); //$NON-NLS-1$ String fetch = attributes.getValue("fetch"); //$NON-NLS-1$ diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java index 6f682ee98..ef634f3d6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java @@ -113,6 +113,7 @@ public class RepoCommand extends GitCommand { private String targetBranch = Constants.HEAD; private boolean recordRemoteBranch = false; private boolean recordSubmoduleLabels = false; + private boolean recordShallowSubmodules = false; private PersonIdent author; private RemoteReader callback; private InputStream inputStream; @@ -362,6 +363,21 @@ public class RepoCommand extends GitCommand { return this; } + /** + * Set whether the clone-depth field should be recorded as a shallow + * recommendation in .gitmodules. + *

+ * Not implemented for non-bare repositories. + * + * @param enable Whether to record the shallow recommendation. + * @return this command + * @since 4.4 + */ + public RepoCommand setRecommendShallow(boolean enable) { + this.recordShallowSubmodules = enable; + return this; + } + /** * The progress monitor associated with the clone operation. By default, * this is set to NullProgressMonitor @@ -471,7 +487,8 @@ public class RepoCommand extends GitCommand { proj.getPath(), proj.getRevision(), proj.getCopyFiles(), - proj.getGroups()); + proj.getGroups(), + proj.getRecommendShallow()); } } catch (GitAPIException | IOException e) { throw new ManifestErrorException(e); @@ -512,6 +529,16 @@ public class RepoCommand extends GitCommand { cfg.setString("submodule", name, "branch", //$NON-NLS-1$ //$NON-NLS-2$ proj.getRevision()); } + + if (recordShallowSubmodules && proj.getRecommendShallow() != null) { + // The shallow recommendation is losing information. + // As the repo manifests stores the recommended + // depth in the 'clone-depth' field, while + // git core only uses a binary 'shallow = true/false' + // hint, we'll map any depth to 'shallow = true' + cfg.setBoolean("submodule", name, "shallow", //$NON-NLS-1$ //$NON-NLS-2$ + true); + } } if (recordSubmoduleLabels) { StringBuilder rec = new StringBuilder(); @@ -616,10 +643,10 @@ public class RepoCommand extends GitCommand { } private void addSubmodule(String url, String name, String revision, - List copyfiles, Set groups) + List copyfiles, Set groups, String recommendShallow) throws GitAPIException, IOException { if (repo.isBare()) { - RepoProject proj = new RepoProject(url, name, revision, null, groups); + RepoProject proj = new RepoProject(url, name, revision, null, groups, recommendShallow); proj.addCopyFiles(copyfiles); bareProjects.add(proj); } else { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java index 1b251368d..bcc7ffc21 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java @@ -70,6 +70,7 @@ public class RepoProject implements Comparable { private final String remote; private final Set groups; private final List copyfiles; + private String recommendShallow; private String url; private String defaultRevision; @@ -138,7 +139,8 @@ public class RepoProject implements Comparable { * @since 4.4 */ public RepoProject(String name, String path, String revision, - String remote, Set groups) { + String remote, Set groups, + String recommendShallow) { if (name == null) { throw new NullPointerException(); } @@ -150,6 +152,7 @@ public class RepoProject implements Comparable { this.revision = revision; this.remote = remote; this.groups = groups; + this.recommendShallow = recommendShallow; copyfiles = new ArrayList(); } @@ -167,7 +170,7 @@ public class RepoProject implements Comparable { */ public RepoProject(String name, String path, String revision, String remote, String groups) { - this(name, path, revision, remote, new HashSet()); + this(name, path, revision, remote, new HashSet(), null); if (groups != null && groups.length() > 0) this.setGroups(groups); } @@ -281,6 +284,25 @@ public class RepoProject implements Comparable { return groups; } + /** + * Return the recommendation for shallowness. + * + * @return the String of "clone-depth" + * @since 4.4 + */ + public String getRecommendShallow() { + return recommendShallow; + } + + /** + * Sets the recommendation for shallowness. + * + * @since 4.4 + */ + public void setRecommendShallow(String recommendShallow) { + this.recommendShallow = recommendShallow; + } + /** * Add a copy file configuration. * From 525baa1213097aa8635d846ce024635b1f33931a Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Wed, 1 Jun 2016 10:16:00 +0200 Subject: [PATCH 10/10] Fix javadoc errors and unused imports introduced by ddd0fe25 Change-Id: I2d17115843e453c71febd4a58527effe658b48fd Signed-off-by: Matthias Sohn --- .../tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java | 3 --- .../src/org/eclipse/jgit/gitrepo/RepoCommand.java | 1 - .../src/org/eclipse/jgit/gitrepo/RepoProject.java | 7 ++++++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java index 80a0250de..ccd15d038 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java @@ -50,9 +50,6 @@ import static org.junit.Assert.assertTrue; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.junit.JGitTestUtil; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java index ef634f3d6..ca976a1a3 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java @@ -51,7 +51,6 @@ import java.io.IOException; import java.io.InputStream; import java.text.MessageFormat; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Set; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java index bcc7ffc21..d29f6c01e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java @@ -136,6 +136,8 @@ public class RepoProject implements Comparable { * name of the remote definition * @param groups * set of groups + * @param recommendShallow + * recommendation for shallowness * @since 4.4 */ public RepoProject(String name, String path, String revision, @@ -189,7 +191,8 @@ public class RepoProject implements Comparable { /** * Set the url of the sub repo. * - * @param url + * @param groups + * comma separated group list * @return this for chaining. * @since 4.4 */ @@ -297,6 +300,8 @@ public class RepoProject implements Comparable { /** * Sets the recommendation for shallowness. * + * @param recommendShallow + * recommendation for shallowness * @since 4.4 */ public void setRecommendShallow(String recommendShallow) {