* master:
Fix javadoc errors and unused imports introduced by ddd0fe25
RepoCommand: record manifest shallow recommendation in .gitmodules
RepoCommand: record manifest groups as submodule labels
Remove the deprecated TestRepository.getClock() method
Replace use of deprecated method Repository.getRef()
[findBugs] Prevent potential NPE in
FileLfsRepository.getOutputStream()
Better report on client side if push failed due to too large object
[findBugs] Prevent potential NPE in CloneCommand.init()
RepoCommand: remove --record-remote-branches
RepoCommandTest: Improve assertion message for remote branch recording
Change-Id: I4fbce4f84925a933fcc9a48058ed6793f5821b97
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
tags/v4.4.0.201606011500-rc2
String originalBranch = repo.getFullBranch(); | String originalBranch = repo.getFullBranch(); | ||||
boolean empty = repo.resolve(Constants.HEAD) == null; | boolean empty = repo.resolve(Constants.HEAD) == null; | ||||
if (!empty) { | if (!empty) { | ||||
if (repo.getRef(branch) == null) | |||||
if (repo.findRef(branch) == null) | |||||
git.branchCreate().setName(branch).call(); | git.branchCreate().setName(branch).call(); | ||||
git.checkout().setName(branch).call(); | git.checkout().setName(branch).call(); | ||||
} | } |
return new Date(mockSystemReader.getCurrentTime()); | 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. */ | /** @return timezone used for default identities. */ | ||||
public TimeZone getTimeZone() { | public TimeZone getTimeZone() { | ||||
return mockSystemReader.getTimeZone(); | return mockSystemReader.getTimeZone(); | ||||
*/ | */ | ||||
public CommitBuilder amendRef(String ref) throws Exception { | public CommitBuilder amendRef(String ref) throws Exception { | ||||
String name = normalizeRef(ref); | String name = normalizeRef(ref); | ||||
Ref r = db.getRef(name); | |||||
Ref r = db.exactRef(name); | |||||
if (r == null) | if (r == null) | ||||
throw new IOException("Not a ref: " + ref); | throw new IOException("Not a ref: " + ref); | ||||
return amend(pool.parseCommit(r.getObjectId()), branch(name).commit()); | return amend(pool.parseCommit(r.getObjectId()), branch(name).commit()); | ||||
RevCommit parent = commit.getParent(0); | RevCommit parent = commit.getParent(0); | ||||
pool.parseHeaders(parent); | pool.parseHeaders(parent); | ||||
Ref headRef = db.getRef(Constants.HEAD); | |||||
Ref headRef = db.exactRef(Constants.HEAD); | |||||
if (headRef == null) | if (headRef == null) | ||||
throw new IOException("Missing HEAD"); | throw new IOException("Missing HEAD"); | ||||
RevCommit head = pool.parseCommit(headRef.getObjectId()); | RevCommit head = pool.parseCommit(headRef.getObjectId()); | ||||
CommitBuilder(BranchBuilder b) throws Exception { | CommitBuilder(BranchBuilder b) throws Exception { | ||||
branch = b; | branch = b; | ||||
Ref ref = db.getRef(branch.ref); | |||||
Ref ref = db.exactRef(branch.ref); | |||||
if (ref != null && ref.getObjectId() != null) | if (ref != null && ref.getObjectId() != null) | ||||
parent(pool.parseCommit(ref.getObjectId())); | parent(pool.parseCommit(ref.getObjectId())); | ||||
} | } |
AtomicObjectOutputStream getOutputStream(AnyLongObjectId id) | AtomicObjectOutputStream getOutputStream(AnyLongObjectId id) | ||||
throws IOException { | throws IOException { | ||||
Path path = getPath(id); | Path path = getPath(id); | ||||
Files.createDirectories(path.getParent()); | |||||
Path parent = path.getParent(); | |||||
if (parent != null) { | |||||
Files.createDirectories(parent); | |||||
} | |||||
return new AtomicObjectOutputStream(path, id); | return new AtomicObjectOutputStream(path, id); | ||||
} | } | ||||
updating=Updating {0}..{1} | 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_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_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_Blame=Show what revision and author last modified each line | ||||
usage_CommandLineClientForamazonsS3Service=Command line client for Amazon's S3 service | usage_CommandLineClientForamazonsS3Service=Command line client for Amazon's S3 service | ||||
usage_CommitAll=commit all modified and deleted files | usage_CommitAll=commit all modified and deleted files |
if (rename) { | if (rename) { | ||||
String src, dst; | String src, dst; | ||||
if (otherBranch == null) { | if (otherBranch == null) { | ||||
final Ref head = db.getRef(Constants.HEAD); | |||||
final Ref head = db.exactRef(Constants.HEAD); | |||||
if (head != null && head.isSymbolic()) { | if (head != null && head.isSymbolic()) { | ||||
src = head.getLeaf().getName(); | src = head.getLeaf().getName(); | ||||
} else { | } else { | ||||
dst = branch; | dst = branch; | ||||
} else { | } else { | ||||
src = branch; | src = branch; | ||||
final Ref old = db.getRef(src); | |||||
final Ref old = db.findRef(src); | |||||
if (old == null) | if (old == null) | ||||
throw die(MessageFormat.format(CLIText.get().doesNotExist, src)); | throw die(MessageFormat.format(CLIText.get().doesNotExist, src)); | ||||
if (!old.getName().startsWith(Constants.R_HEADS)) | if (!old.getName().startsWith(Constants.R_HEADS)) | ||||
} else { | } else { | ||||
startBranch = Constants.HEAD; | startBranch = Constants.HEAD; | ||||
} | } | ||||
Ref startRef = db.getRef(startBranch); | |||||
Ref startRef = db.findRef(startBranch); | |||||
ObjectId startAt = db.resolve(startBranch + "^0"); //$NON-NLS-1$ | ObjectId startAt = db.resolve(startBranch + "^0"); //$NON-NLS-1$ | ||||
if (startRef != null) { | if (startRef != null) { | ||||
startBranch = startRef.getName(); | startBranch = startRef.getName(); | ||||
} | } | ||||
private void list() throws Exception { | private void list() throws Exception { | ||||
Ref head = db.getRef(Constants.HEAD); | |||||
Ref head = db.exactRef(Constants.HEAD); | |||||
// This can happen if HEAD is stillborn | // This can happen if HEAD is stillborn | ||||
if (head != null) { | if (head != null) { | ||||
String current = head.getLeaf().getName(); | String current = head.getLeaf().getName(); |
commitCmd.setOnly(p); | commitCmd.setOnly(p); | ||||
commitCmd.setAmend(amend); | commitCmd.setAmend(amend); | ||||
commitCmd.setAll(all); | commitCmd.setAll(all); | ||||
Ref head = db.getRef(Constants.HEAD); | |||||
Ref head = db.exactRef(Constants.HEAD); | |||||
if (head == null) { | if (head == null) { | ||||
throw die(CLIText.get().onBranchToBeBorn); | throw die(CLIText.get().onBranchToBeBorn); | ||||
} | } |
} | } | ||||
private void addNoteMap(String notesRef) throws IOException { | private void addNoteMap(String notesRef) throws IOException { | ||||
Ref notes = db.getRef(notesRef); | |||||
Ref notes = db.exactRef(notesRef); | |||||
if (notes == null) | if (notes == null) | ||||
return; | return; | ||||
RevCommit notesCommit = argWalk.parseCommit(notes.getObjectId()); | RevCommit notesCommit = argWalk.parseCommit(notes.getObjectId()); |
} | } | ||||
// determine the other revision we want to merge with HEAD | // 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$ | final ObjectId src = db.resolve(ref + "^{commit}"); //$NON-NLS-1$ | ||||
if (src == null) | if (src == null) | ||||
throw die(MessageFormat.format( | throw die(MessageFormat.format( | ||||
} | } | ||||
private Ref getOldHead() throws IOException { | private Ref getOldHead() throws IOException { | ||||
Ref oldHead = db.getRef(Constants.HEAD); | |||||
Ref oldHead = db.exactRef(Constants.HEAD); | |||||
if (oldHead == null) { | if (oldHead == null) { | ||||
throw die(CLIText.get().onBranchToBeBorn); | throw die(CLIText.get().onBranchToBeBorn); | ||||
} | } |
@Argument(required = true, metaVar = "metaVar_path", usage = "usage_pathToXml") | @Argument(required = true, metaVar = "metaVar_path", usage = "usage_pathToXml") | ||||
private String path; | private String path; | ||||
@Option(name = "--record-remote-branch", usage = "usage_branches") | |||||
private boolean branches; | |||||
@Override | @Override | ||||
protected void run() throws Exception { | protected void run() throws Exception { | ||||
new RepoCommand(db) | new RepoCommand(db) | ||||
.setURI(uri) | .setURI(uri) | ||||
.setPath(path) | .setPath(path) | ||||
.setGroups(groups) | .setGroups(groups) | ||||
.setRecordRemoteBranch(branches) | |||||
.call(); | .call(); | ||||
} | } | ||||
} | } |
private void printLongStatus(org.eclipse.jgit.api.Status status) | private void printLongStatus(org.eclipse.jgit.api.Status status) | ||||
throws IOException { | throws IOException { | ||||
// Print current branch name | // Print current branch name | ||||
final Ref head = db.getRef(Constants.HEAD); | |||||
final Ref head = db.exactRef(Constants.HEAD); | |||||
if (head != null && head.isSymbolic()) { | if (head != null && head.isSymbolic()) { | ||||
String branch = Repository.shortenRefName(head.getLeaf().getName()); | String branch = Repository.shortenRefName(head.getLeaf().getName()); | ||||
outw.println(CLIText.formatLine(MessageFormat.format( | outw.println(CLIText.formatLine(MessageFormat.format( |
* @throws IOException | * @throws IOException | ||||
*/ | */ | ||||
private void assertSameAsHead(Ref ref) 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.getName(), ref.getName()); | ||||
assertEquals(headRef.getObjectId(), ref.getObjectId()); | assertEquals(headRef.getObjectId(), ref.getObjectId()); | ||||
} | } |
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.assertFalse; | import static org.junit.Assert.assertFalse; | ||||
import static org.junit.Assert.assertNull; | |||||
import static org.junit.Assert.assertTrue; | import static org.junit.Assert.assertTrue; | ||||
import java.io.BufferedReader; | import java.io.BufferedReader; | ||||
FileBasedConfig c = new FileBasedConfig(gitmodules, | FileBasedConfig c = new FileBasedConfig(gitmodules, | ||||
FS.DETECTED); | FS.DETECTED); | ||||
c.load(); | c.load(); | ||||
assertEquals("standard branches work", "master", | |||||
assertEquals("Recording remote branches should work for short branch descriptions", "master", | |||||
c.getString("submodule", "with-branch", "branch")); | 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")); | c.getString("submodule", "with-long-branch", "branch")); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
@Test | |||||
public void testRecordSubmoduleLabels() throws Exception { | |||||
try ( | |||||
Repository remoteDb = createBareRepository(); | |||||
Repository tempDb = createWorkRepository()) { | |||||
StringBuilder xmlContent = new StringBuilder(); | |||||
xmlContent | |||||
.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") | |||||
.append("<manifest>") | |||||
.append("<remote name=\"remote1\" fetch=\".\" />") | |||||
.append("<default revision=\"master\" remote=\"remote1\" />") | |||||
.append("<project path=\"test\" ") | |||||
.append("revision=\"master\" ") | |||||
.append("name=\"").append(notDefaultUri).append("\" ") | |||||
.append("groups=\"a1,a2\" />") | |||||
.append("</manifest>"); | |||||
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 testRecordShallowRecommendation() throws Exception { | |||||
try ( | |||||
Repository remoteDb = createBareRepository(); | |||||
Repository tempDb = createWorkRepository()) { | |||||
StringBuilder xmlContent = new StringBuilder(); | |||||
xmlContent | |||||
.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") | |||||
.append("<manifest>") | |||||
.append("<remote name=\"remote1\" fetch=\".\" />") | |||||
.append("<default revision=\"master\" remote=\"remote1\" />") | |||||
.append("<project path=\"shallow-please\" ") | |||||
.append("name=\"").append(defaultUri).append("\" ") | |||||
.append("clone-depth=\"1\" />") | |||||
.append("<project path=\"non-shallow\" ") | |||||
.append("name=\"").append(defaultUri).append("\" />") | |||||
.append("</manifest>"); | |||||
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 | @Test | ||||
public void testRemoteRevision() throws Exception { | public void testRemoteRevision() throws Exception { | ||||
StringBuilder xmlContent = new StringBuilder(); | StringBuilder xmlContent = new StringBuilder(); |
indexSignatureIsInvalid=Index signature is invalid: {0} | indexSignatureIsInvalid=Index signature is invalid: {0} | ||||
indexWriteException=Modified index could not be written | 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 | 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 | 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 | inMemoryBufferLimitExceeded=In-memory buffer limit exceeded | ||||
inputDidntMatchLength=Input did not match supplied length. {0} bytes are missing. | inputDidntMatchLength=Input did not match supplied length. {0} bytes are missing. |
RevCommit notesCommit = null; | RevCommit notesCommit = null; | ||||
try (RevWalk walk = new RevWalk(repo); | try (RevWalk walk = new RevWalk(repo); | ||||
ObjectInserter inserter = repo.newObjectInserter()) { | ObjectInserter inserter = repo.newObjectInserter()) { | ||||
Ref ref = repo.getRef(notesRef); | |||||
Ref ref = repo.findRef(notesRef); | |||||
// if we have a notes ref, use it | // if we have a notes ref, use it | ||||
if (ref != null) { | if (ref != null) { | ||||
notesCommit = walk.parseCommit(ref.getObjectId()); | notesCommit = walk.parseCommit(ref.getObjectId()); |
} | } | ||||
} | } | ||||
Ref headRef = repo.getRef(Constants.HEAD); | |||||
Ref headRef = repo.exactRef(Constants.HEAD); | |||||
if (headRef == null) { | if (headRef == null) { | ||||
// TODO Git CLI supports checkout from unborn branch, we should | // TODO Git CLI supports checkout from unborn branch, we should | ||||
// also allow this | // also allow this | ||||
JGitText.get().checkoutUnexpectedResult, | JGitText.get().checkoutUnexpectedResult, | ||||
r.name())); | r.name())); | ||||
this.status = CheckoutResult.NOT_TRIED_RESULT; | this.status = CheckoutResult.NOT_TRIED_RESULT; | ||||
return repo.getRef(Constants.HEAD); | |||||
return repo.exactRef(Constants.HEAD); | |||||
} | } | ||||
branch = getStartPointObjectId(); | branch = getStartPointObjectId(); | ||||
} else { | } else { | ||||
} finally { | } finally { | ||||
dc.unlock(); | dc.unlock(); | ||||
} | } | ||||
Ref ref = repo.getRef(name); | |||||
Ref ref = repo.findRef(name); | |||||
if (ref != null && !ref.getName().startsWith(Constants.R_HEADS)) | if (ref != null && !ref.getName().startsWith(Constants.R_HEADS)) | ||||
ref = null; | ref = null; | ||||
String toName = Repository.shortenRefName(name); | String toName = Repository.shortenRefName(name); | ||||
updateResult = refUpdate.link(ref.getName()); | updateResult = refUpdate.link(ref.getName()); | ||||
else if (orphan) { | else if (orphan) { | ||||
updateResult = refUpdate.link(getBranchName()); | updateResult = refUpdate.link(getBranchName()); | ||||
ref = repo.getRef(Constants.HEAD); | |||||
ref = repo.exactRef(Constants.HEAD); | |||||
} else { | } else { | ||||
refUpdate.setNewObjectId(newCommit); | refUpdate.setNewObjectId(newCommit); | ||||
updateResult = refUpdate.forceUpdate(); | updateResult = refUpdate.forceUpdate(); | ||||
.get().branchNameInvalid, name == null ? "<null>" : name)); //$NON-NLS-1$ | .get().branchNameInvalid, name == null ? "<null>" : name)); //$NON-NLS-1$ | ||||
if (orphan) { | if (orphan) { | ||||
Ref refToCheck = repo.getRef(getBranchName()); | |||||
Ref refToCheck = repo.exactRef(getBranchName()); | |||||
if (refToCheck != null) | if (refToCheck != null) | ||||
throw new RefAlreadyExistsException(MessageFormat.format( | throw new RefAlreadyExistsException(MessageFormat.format( | ||||
JGitText.get().refAlreadyExists, name)); | JGitText.get().refAlreadyExists, name)); |
try (RevWalk revWalk = new RevWalk(repo)) { | try (RevWalk revWalk = new RevWalk(repo)) { | ||||
// get the head commit | // get the head commit | ||||
Ref headRef = repo.getRef(Constants.HEAD); | |||||
Ref headRef = repo.exactRef(Constants.HEAD); | |||||
if (headRef == null) | if (headRef == null) | ||||
throw new NoHeadException( | throw new NoHeadException( | ||||
JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported); | JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported); |
command.setBare(bare); | command.setBare(bare); | ||||
if (directory == null && gitDir == null) | if (directory == null && gitDir == null) | ||||
directory = new File(u.getHumanishName(), Constants.DOT_GIT); | directory = new File(u.getHumanishName(), Constants.DOT_GIT); | ||||
validateDirs(directory, gitDir, bare); | |||||
if (directory != null && directory.exists() | if (directory != null && directory.exists() | ||||
&& directory.listFiles().length != 0) | && directory.listFiles().length != 0) | ||||
throw new JGitInternalException(MessageFormat.format( | throw new JGitInternalException(MessageFormat.format( | ||||
private static void validateDirs(File directory, File gitDir, boolean bare) | private static void validateDirs(File directory, File gitDir, boolean bare) | ||||
throws IllegalStateException { | throws IllegalStateException { | ||||
if (directory != null) { | 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 (bare) { | ||||
if (gitDir != null && !gitDir.equals(directory)) | if (gitDir != null && !gitDir.equals(directory)) | ||||
throw new IllegalStateException(MessageFormat.format( | throw new IllegalStateException(MessageFormat.format( |
} | } | ||||
} | } | ||||
Ref head = repo.getRef(Constants.HEAD); | |||||
Ref head = repo.exactRef(Constants.HEAD); | |||||
if (head == null) | if (head == null) | ||||
throw new NoHeadException( | throw new NoHeadException( | ||||
JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported); | JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported); |
checkCallable(); | checkCallable(); | ||||
processOptions(); | processOptions(); | ||||
try (RevWalk revWalk = new RevWalk(repo)) { | try (RevWalk revWalk = new RevWalk(repo)) { | ||||
Ref refToCheck = repo.getRef(name); | |||||
Ref refToCheck = repo.findRef(name); | |||||
boolean exists = refToCheck != null | boolean exists = refToCheck != null | ||||
&& refToCheck.getName().startsWith(Constants.R_HEADS); | && refToCheck.getName().startsWith(Constants.R_HEADS); | ||||
if (!force && exists) | if (!force && exists) | ||||
ObjectId startAt = getStartPointObjectId(); | ObjectId startAt = getStartPointObjectId(); | ||||
String startPointFullName = null; | String startPointFullName = null; | ||||
if (startPoint != null) { | if (startPoint != null) { | ||||
Ref baseRef = repo.getRef(startPoint); | |||||
Ref baseRef = repo.findRef(startPoint); | |||||
if (baseRef != null) | if (baseRef != null) | ||||
startPointFullName = baseRef.getName(); | startPointFullName = baseRef.getName(); | ||||
} | } | ||||
.get().createBranchUnexpectedResult, updateResult | .get().createBranchUnexpectedResult, updateResult | ||||
.name())); | .name())); | ||||
Ref result = repo.getRef(name); | |||||
Ref result = repo.findRef(name); | |||||
if (result == null) | if (result == null) | ||||
throw new JGitInternalException( | throw new JGitInternalException( | ||||
JGitText.get().createBranchFailedUnknownReason); | JGitText.get().createBranchFailedUnknownReason); |
for (String branchName : branchNames) { | for (String branchName : branchNames) { | ||||
if (branchName == null) | if (branchName == null) | ||||
continue; | continue; | ||||
Ref currentRef = repo.getRef(branchName); | |||||
Ref currentRef = repo.findRef(branchName); | |||||
if (currentRef == null) | if (currentRef == null) | ||||
continue; | continue; | ||||
for (String branchName : branchNames) { | for (String branchName : branchNames) { | ||||
if (branchName == null) | if (branchName == null) | ||||
continue; | continue; | ||||
Ref currentRef = repo.getRef(branchName); | |||||
Ref currentRef = repo.findRef(branchName); | |||||
if (currentRef == null) | if (currentRef == null) | ||||
continue; | continue; | ||||
String fullName = currentRef.getName(); | String fullName = currentRef.getName(); |
for (String tagName : tags) { | for (String tagName : tags) { | ||||
if (tagName == null) | if (tagName == null) | ||||
continue; | continue; | ||||
Ref currentRef = repo.getRef(tagName); | |||||
Ref currentRef = repo.findRef(tagName); | |||||
if (currentRef == null) | if (currentRef == null) | ||||
continue; | continue; | ||||
String fullName = currentRef.getName(); | String fullName = currentRef.getName(); |
Collection<Ref> refs = new ArrayList<Ref>(); | Collection<Ref> refs = new ArrayList<Ref>(); | ||||
// Also return HEAD if it's detached | // 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)) | if (head != null && head.getLeaf().getName().equals(Constants.HEAD)) | ||||
refs.add(head); | refs.add(head); | ||||
List<Note> notes = new ArrayList<Note>(); | List<Note> notes = new ArrayList<Note>(); | ||||
NoteMap map = NoteMap.newEmptyMap(); | NoteMap map = NoteMap.newEmptyMap(); | ||||
try (RevWalk walk = new RevWalk(repo)) { | 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 we have a notes ref, use it | ||||
if (ref != null) { | if (ref != null) { | ||||
RevCommit notesCommit = walk.parseCommit(ref.getObjectId()); | RevCommit notesCommit = walk.parseCommit(ref.getObjectId()); |
RevWalk revWalk = null; | RevWalk revWalk = null; | ||||
DirCacheCheckout dco = null; | DirCacheCheckout dco = null; | ||||
try { | try { | ||||
Ref head = repo.getRef(Constants.HEAD); | |||||
Ref head = repo.exactRef(Constants.HEAD); | |||||
if (head == null) | if (head == null) | ||||
throw new NoHeadException( | throw new NoHeadException( | ||||
JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported); | JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported); |
import org.eclipse.jgit.api.errors.InvalidRemoteException; | import org.eclipse.jgit.api.errors.InvalidRemoteException; | ||||
import org.eclipse.jgit.api.errors.JGitInternalException; | import org.eclipse.jgit.api.errors.JGitInternalException; | ||||
import org.eclipse.jgit.errors.NotSupportedException; | import org.eclipse.jgit.errors.NotSupportedException; | ||||
import org.eclipse.jgit.errors.TooLargeObjectInPackException; | |||||
import org.eclipse.jgit.errors.TooLargePackException; | import org.eclipse.jgit.errors.TooLargePackException; | ||||
import org.eclipse.jgit.errors.TransportException; | import org.eclipse.jgit.errors.TransportException; | ||||
import org.eclipse.jgit.internal.JGitText; | import org.eclipse.jgit.internal.JGitText; | ||||
refSpecs.addAll(config.getPushRefSpecs()); | refSpecs.addAll(config.getPushRefSpecs()); | ||||
} | } | ||||
if (refSpecs.isEmpty()) { | if (refSpecs.isEmpty()) { | ||||
Ref head = repo.getRef(Constants.HEAD); | |||||
Ref head = repo.exactRef(Constants.HEAD); | |||||
if (head != null && head.isSymbolic()) | if (head != null && head.isSymbolic()) | ||||
refSpecs.add(new RefSpec(head.getLeaf().getName())); | refSpecs.add(new RefSpec(head.getLeaf().getName())); | ||||
} | } | ||||
} catch (TooLargePackException e) { | } catch (TooLargePackException e) { | ||||
throw new org.eclipse.jgit.api.errors.TooLargePackException( | throw new org.eclipse.jgit.api.errors.TooLargePackException( | ||||
e.getMessage(), e); | e.getMessage(), e); | ||||
} catch (TooLargeObjectInPackException e) { | |||||
throw new org.eclipse.jgit.api.errors.TooLargeObjectInPackException( | |||||
e.getMessage(), e); | |||||
} catch (TransportException e) { | } catch (TransportException e) { | ||||
throw new org.eclipse.jgit.api.errors.TransportException( | throw new org.eclipse.jgit.api.errors.TransportException( | ||||
e.getMessage(), e); | e.getMessage(), e); | ||||
} else { | } else { | ||||
Ref src; | Ref src; | ||||
try { | try { | ||||
src = repo.getRef(nameOrSpec); | |||||
src = repo.findRef(nameOrSpec); | |||||
} catch (IOException e) { | } catch (IOException e) { | ||||
throw new JGitInternalException( | throw new JGitInternalException( | ||||
JGitText.get().exceptionCaughtDuringExecutionOfPushCommand, | JGitText.get().exceptionCaughtDuringExecutionOfPushCommand, |
private void updateStashRef(ObjectId commitId, PersonIdent refLogIdent, | private void updateStashRef(ObjectId commitId, PersonIdent refLogIdent, | ||||
String refLogMessage) throws IOException { | 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 refUpdate = repo.updateRef(Constants.R_STASH); | ||||
refUpdate.setNewObjectId(commitId); | refUpdate.setNewObjectId(commitId); | ||||
refUpdate.setRefLogIdent(refLogIdent); | refUpdate.setRefLogIdent(refLogIdent); | ||||
private void resetSoftToParent() throws IOException, | private void resetSoftToParent() throws IOException, | ||||
GitAPIException, CheckoutConflictException { | GitAPIException, CheckoutConflictException { | ||||
Ref ref = repo.getRef(Constants.ORIG_HEAD); | |||||
Ref ref = repo.exactRef(Constants.ORIG_HEAD); | |||||
ObjectId orig_head = ref == null ? null : ref.getObjectId(); | ObjectId orig_head = ref == null ? null : ref.getObjectId(); | ||||
try { | try { | ||||
// we have already commited the cherry-picked commit. | // we have already commited the cherry-picked commit. | ||||
} | } | ||||
private Ref getHead() throws IOException, RefNotFoundException { | private Ref getHead() throws IOException, RefNotFoundException { | ||||
Ref head = repo.getRef(Constants.HEAD); | |||||
Ref head = repo.exactRef(Constants.HEAD); | |||||
if (head == null || head.getObjectId() == null) | if (head == null || head.getObjectId() == null) | ||||
throw new RefNotFoundException(MessageFormat.format( | throw new RefNotFoundException(MessageFormat.format( | ||||
JGitText.get().refNotResolved, Constants.HEAD)); | JGitText.get().refNotResolved, Constants.HEAD)); |
ObjectInserter inserter = repo.newObjectInserter()) { | ObjectInserter inserter = repo.newObjectInserter()) { | ||||
NoteMap map = NoteMap.newEmptyMap(); | NoteMap map = NoteMap.newEmptyMap(); | ||||
RevCommit notesCommit = null; | RevCommit notesCommit = null; | ||||
Ref ref = repo.getRef(notesRef); | |||||
Ref ref = repo.exactRef(notesRef); | |||||
// if we have a notes ref, use it | // if we have a notes ref, use it | ||||
if (ref != null) { | if (ref != null) { | ||||
notesCommit = walk.parseCommit(ref.getObjectId()); | notesCommit = walk.parseCommit(ref.getObjectId()); |
try { | try { | ||||
String fullOldName; | String fullOldName; | ||||
String fullNewName; | String fullNewName; | ||||
if (repo.getRef(newName) != null) | |||||
if (repo.findRef(newName) != null) | |||||
throw new RefAlreadyExistsException(MessageFormat.format( | throw new RefAlreadyExistsException(MessageFormat.format( | ||||
JGitText.get().refAlreadyExists1, newName)); | JGitText.get().refAlreadyExists1, newName)); | ||||
if (oldName != null) { | if (oldName != null) { | ||||
Ref ref = repo.getRef(oldName); | |||||
Ref ref = repo.findRef(oldName); | |||||
if (ref == null) | if (ref == null) | ||||
throw new RefNotFoundException(MessageFormat.format( | throw new RefNotFoundException(MessageFormat.format( | ||||
JGitText.get().refNotResolved, oldName)); | JGitText.get().refNotResolved, oldName)); | ||||
repoConfig.save(); | repoConfig.save(); | ||||
} | } | ||||
Ref resultRef = repo.getRef(newName); | |||||
Ref resultRef = repo.findRef(newName); | |||||
if (resultRef == null) | if (resultRef == null) | ||||
throw new JGitInternalException( | throw new JGitInternalException( | ||||
JGitText.get().renameBranchFailedUnknownReason); | JGitText.get().renameBranchFailedUnknownReason); |
// reset [commit] -- paths | // reset [commit] -- paths | ||||
resetIndexForPaths(commitTree); | resetIndexForPaths(commitTree); | ||||
setCallable(false); | setCallable(false); | ||||
return repo.getRef(Constants.HEAD); | |||||
return repo.exactRef(Constants.HEAD); | |||||
} | } | ||||
final Ref result; | final Ref result; |
try (RevWalk revWalk = new RevWalk(repo)) { | try (RevWalk revWalk = new RevWalk(repo)) { | ||||
// get the head commit | // get the head commit | ||||
Ref headRef = repo.getRef(Constants.HEAD); | |||||
Ref headRef = repo.exactRef(Constants.HEAD); | |||||
if (headRef == null) | if (headRef == null) | ||||
throw new NoHeadException( | throw new NoHeadException( | ||||
JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported); | JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported); |
NoteMap map = NoteMap.newEmptyMap(); | NoteMap map = NoteMap.newEmptyMap(); | ||||
RevCommit notesCommit = null; | RevCommit notesCommit = null; | ||||
try (RevWalk walk = new RevWalk(repo)) { | 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 we have a notes ref, use it | ||||
if (ref != null) { | if (ref != null) { | ||||
notesCommit = walk.parseCommit(ref.getObjectId()); | notesCommit = walk.parseCommit(ref.getObjectId()); |
String refLogMessage) throws IOException { | String refLogMessage) throws IOException { | ||||
if (ref == null) | if (ref == null) | ||||
return; | return; | ||||
Ref currentRef = repo.getRef(ref); | |||||
Ref currentRef = repo.findRef(ref); | |||||
RefUpdate refUpdate = repo.updateRef(ref); | RefUpdate refUpdate = repo.updateRef(ref); | ||||
refUpdate.setNewObjectId(commitId); | refUpdate.setNewObjectId(commitId); | ||||
refUpdate.setRefLogIdent(refLogIdent); | refUpdate.setRefLogIdent(refLogIdent); | ||||
private Ref getHead() throws GitAPIException { | private Ref getHead() throws GitAPIException { | ||||
try { | try { | ||||
Ref head = repo.getRef(Constants.HEAD); | |||||
Ref head = repo.exactRef(Constants.HEAD); | |||||
if (head == null || head.getObjectId() == null) | if (head == null || head.getObjectId() == null) | ||||
throw new NoHeadException(JGitText.get().headRequiredToStash); | throw new NoHeadException(JGitText.get().headRequiredToStash); | ||||
return head; | return head; |
private Ref getRef() throws GitAPIException { | private Ref getRef() throws GitAPIException { | ||||
try { | try { | ||||
return repo.getRef(R_STASH); | |||||
return repo.exactRef(R_STASH); | |||||
} catch (IOException e) { | } catch (IOException e) { | ||||
throw new InvalidRefNameException(MessageFormat.format( | throw new InvalidRefNameException(MessageFormat.format( | ||||
JGitText.get().cannotRead, R_STASH), e); | JGitText.get().cannotRead, R_STASH), e); | ||||
updateRef(stashRef, entryId); | updateRef(stashRef, entryId); | ||||
try { | try { | ||||
Ref newStashRef = repo.getRef(R_STASH); | |||||
Ref newStashRef = repo.exactRef(R_STASH); | |||||
return newStashRef != null ? newStashRef.getObjectId() : null; | return newStashRef != null ? newStashRef.getObjectId() : null; | ||||
} catch (IOException e) { | } catch (IOException e) { | ||||
throw new InvalidRefNameException(MessageFormat.format( | throw new InvalidRefNameException(MessageFormat.format( |
checkCallable(); | checkCallable(); | ||||
try { | try { | ||||
if (repo.getRef(Constants.R_STASH) == null) | |||||
if (repo.exactRef(Constants.R_STASH) == null) | |||||
return Collections.emptyList(); | return Collections.emptyList(); | ||||
} catch (IOException e) { | } catch (IOException e) { | ||||
throw new InvalidRefNameException(MessageFormat.format( | throw new InvalidRefNameException(MessageFormat.format( |
* @throws IOException | * @throws IOException | ||||
*/ | */ | ||||
protected String getHeadBranch(final Repository subRepo) 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()) | if (head != null && head.isSymbolic()) | ||||
return Repository.shortenRefName(head.getLeaf().getName()); | return Repository.shortenRefName(head.getLeaf().getName()); | ||||
else | else |
switch (updateResult) { | switch (updateResult) { | ||||
case NEW: | case NEW: | ||||
case FORCED: | case FORCED: | ||||
return repo.getRef(refName); | |||||
return repo.exactRef(refName); | |||||
case LOCK_FAILURE: | case LOCK_FAILURE: | ||||
throw new ConcurrentRefUpdateException( | throw new ConcurrentRefUpdateException( | ||||
JGitText.get().couldNotLockHEAD, tagRef.getRef(), | JGitText.get().couldNotLockHEAD, tagRef.getRef(), |
/* | |||||
* Copyright (C) 2016, Matthias Sohn <matthias.sohn@sap.com> 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); | |||||
} | |||||
} |
package org.eclipse.jgit.errors; | package org.eclipse.jgit.errors; | ||||
import java.io.IOException; | |||||
import java.text.MessageFormat; | import java.text.MessageFormat; | ||||
import org.eclipse.jgit.internal.JGitText; | import org.eclipse.jgit.internal.JGitText; | ||||
import org.eclipse.jgit.transport.URIish; | |||||
/** Thrown when PackParser finds an object larger than a predefined limit */ | /** 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; | private static final long serialVersionUID = 1L; | ||||
/** | /** | ||||
super(MessageFormat.format(JGitText.get().receivePackObjectTooLarge2, | super(MessageFormat.format(JGitText.get().receivePackObjectTooLarge2, | ||||
Long.valueOf(objectSize), Long.valueOf(maxObjectSizeLimit))); | 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$ | |||||
} | |||||
} | } |
attributes.getValue("revision"), //$NON-NLS-1$ | attributes.getValue("revision"), //$NON-NLS-1$ | ||||
attributes.getValue("remote"), //$NON-NLS-1$ | attributes.getValue("remote"), //$NON-NLS-1$ | ||||
attributes.getValue("groups")); //$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$ | } else if ("remote".equals(qName)) { //$NON-NLS-1$ | ||||
String alias = attributes.getValue("alias"); //$NON-NLS-1$ | String alias = attributes.getValue("alias"); //$NON-NLS-1$ | ||||
String fetch = attributes.getValue("fetch"); //$NON-NLS-1$ | String fetch = attributes.getValue("fetch"); //$NON-NLS-1$ |
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Map; | import java.util.Map; | ||||
import java.util.Set; | |||||
import org.eclipse.jgit.annotations.Nullable; | import org.eclipse.jgit.annotations.Nullable; | ||||
import org.eclipse.jgit.api.Git; | import org.eclipse.jgit.api.Git; | ||||
private String branch; | private String branch; | ||||
private String targetBranch = Constants.HEAD; | private String targetBranch = Constants.HEAD; | ||||
private boolean recordRemoteBranch = false; | private boolean recordRemoteBranch = false; | ||||
private boolean recordSubmoduleLabels = false; | |||||
private boolean recordShallowSubmodules = false; | |||||
private PersonIdent author; | private PersonIdent author; | ||||
private RemoteReader callback; | private RemoteReader callback; | ||||
private InputStream inputStream; | private InputStream inputStream; | ||||
return this; | return this; | ||||
} | } | ||||
/** | |||||
* Set whether the labels field should be recorded as a label in | |||||
* .gitattributes. | |||||
* <p> | |||||
* 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; | |||||
} | |||||
/** | |||||
* Set whether the clone-depth field should be recorded as a shallow | |||||
* recommendation in .gitmodules. | |||||
* <p> | |||||
* 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, | * The progress monitor associated with the clone operation. By default, | ||||
* this is set to <code>NullProgressMonitor</code> | * this is set to <code>NullProgressMonitor</code> | ||||
addSubmodule(proj.getUrl(), | addSubmodule(proj.getUrl(), | ||||
proj.getPath(), | proj.getPath(), | ||||
proj.getRevision(), | proj.getRevision(), | ||||
proj.getCopyFiles()); | |||||
proj.getCopyFiles(), | |||||
proj.getGroups(), | |||||
proj.getRecommendShallow()); | |||||
} | } | ||||
} catch (GitAPIException | IOException e) { | } catch (GitAPIException | IOException e) { | ||||
throw new ManifestErrorException(e); | throw new ManifestErrorException(e); | ||||
ObjectInserter inserter = repo.newObjectInserter(); | ObjectInserter inserter = repo.newObjectInserter(); | ||||
try (RevWalk rw = new RevWalk(repo)) { | try (RevWalk rw = new RevWalk(repo)) { | ||||
Config cfg = new Config(); | Config cfg = new Config(); | ||||
StringBuilder attributes = new StringBuilder(); | |||||
for (RepoProject proj : bareProjects) { | for (RepoProject proj : bareProjects) { | ||||
String name = proj.getPath(); | String name = proj.getPath(); | ||||
String nameUri = proj.getName(); | String nameUri = proj.getName(); | ||||
cfg.setString("submodule", name, "branch", //$NON-NLS-1$ //$NON-NLS-2$ | cfg.setString("submodule", name, "branch", //$NON-NLS-1$ //$NON-NLS-2$ | ||||
proj.getRevision()); | 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(); | |||||
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, "path", name); //$NON-NLS-1$ //$NON-NLS-2$ | ||||
cfg.setString("submodule", name, "url", nameUri); //$NON-NLS-1$ //$NON-NLS-2$ | cfg.setString("submodule", name, "url", nameUri); //$NON-NLS-1$ //$NON-NLS-2$ | ||||
dcEntry.setFileMode(FileMode.REGULAR_FILE); | dcEntry.setFileMode(FileMode.REGULAR_FILE); | ||||
builder.add(dcEntry); | 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(); | builder.finish(); | ||||
ObjectId treeId = index.writeTree(inserter); | ObjectId treeId = index.writeTree(inserter); | ||||
} | } | ||||
private void addSubmodule(String url, String name, String revision, | private void addSubmodule(String url, String name, String revision, | ||||
List<CopyFile> copyfiles) throws GitAPIException, IOException { | |||||
List<CopyFile> copyfiles, Set<String> groups, String recommendShallow) | |||||
throws GitAPIException, IOException { | |||||
if (repo.isBare()) { | if (repo.isBare()) { | ||||
RepoProject proj = new RepoProject(url, name, revision, null, null); | |||||
RepoProject proj = new RepoProject(url, name, revision, null, groups, recommendShallow); | |||||
proj.addCopyFiles(copyfiles); | proj.addCopyFiles(copyfiles); | ||||
bareProjects.add(proj); | bareProjects.add(proj); | ||||
} else { | } else { |
private final String remote; | private final String remote; | ||||
private final Set<String> groups; | private final Set<String> groups; | ||||
private final List<CopyFile> copyfiles; | private final List<CopyFile> copyfiles; | ||||
private String recommendShallow; | |||||
private String url; | private String url; | ||||
private String defaultRevision; | private String defaultRevision; | ||||
* @param remote | * @param remote | ||||
* name of the remote definition | * name of the remote definition | ||||
* @param groups | * @param groups | ||||
* comma separated group list | |||||
* set of groups | |||||
* @param recommendShallow | |||||
* recommendation for shallowness | |||||
* @since 4.4 | |||||
*/ | */ | ||||
public RepoProject(String name, String path, String revision, | public RepoProject(String name, String path, String revision, | ||||
String remote, String groups) { | |||||
String remote, Set<String> groups, | |||||
String recommendShallow) { | |||||
if (name == null) { | if (name == null) { | ||||
throw new NullPointerException(); | throw new NullPointerException(); | ||||
} | } | ||||
this.path = name; | this.path = name; | ||||
this.revision = revision; | this.revision = revision; | ||||
this.remote = remote; | this.remote = remote; | ||||
this.groups = new HashSet<String>(); | |||||
if (groups != null && groups.length() > 0) | |||||
this.groups.addAll(Arrays.asList(groups.split(","))); //$NON-NLS-1$ | |||||
this.groups = groups; | |||||
this.recommendShallow = recommendShallow; | |||||
copyfiles = new ArrayList<CopyFile>(); | copyfiles = new ArrayList<CopyFile>(); | ||||
} | } | ||||
/** | |||||
* @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<String>(), null); | |||||
if (groups != null && groups.length() > 0) | |||||
this.setGroups(groups); | |||||
} | |||||
/** | /** | ||||
* Set the url of the sub repo. | * Set the url of the sub repo. | ||||
* | * | ||||
return this; | return this; | ||||
} | } | ||||
/** | |||||
* Set the url of the sub repo. | |||||
* | |||||
* @param groups | |||||
* comma separated group list | |||||
* @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. | * Set the default revision for the sub repo. | ||||
* | * | ||||
return groups.contains(group); | return groups.contains(group); | ||||
} | } | ||||
/** | |||||
* Return the set of groups. | |||||
* | |||||
* @return a Set of groups. | |||||
* @since 4.4 | |||||
*/ | |||||
public Set<String> getGroups() { | |||||
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. | |||||
* | |||||
* @param recommendShallow | |||||
* recommendation for shallowness | |||||
* @since 4.4 | |||||
*/ | |||||
public void setRecommendShallow(String recommendShallow) { | |||||
this.recommendShallow = recommendShallow; | |||||
} | |||||
/** | /** | ||||
* Add a copy file configuration. | * Add a copy file configuration. | ||||
* | * |
/***/ public String indexSignatureIsInvalid; | /***/ public String indexSignatureIsInvalid; | ||||
/***/ public String indexWriteException; | /***/ public String indexWriteException; | ||||
/***/ public String initFailedBareRepoDifferentDirs; | /***/ public String initFailedBareRepoDifferentDirs; | ||||
/***/ public String initFailedDirIsNoDirectory; | |||||
/***/ public String initFailedGitDirIsNoDirectory; | |||||
/***/ public String initFailedNonBareRepoSameDirs; | /***/ public String initFailedNonBareRepoSameDirs; | ||||
/***/ public String inMemoryBufferLimitExceeded; | /***/ public String inMemoryBufferLimitExceeded; | ||||
/***/ public String inputDidntMatchLength; | /***/ public String inputDidntMatchLength; |
* @throws IOException the ref could not be accessed. | * @throws IOException the ref could not be accessed. | ||||
*/ | */ | ||||
public ReflogReader getReflogReader(String refName) throws IOException { | public ReflogReader getReflogReader(String refName) throws IOException { | ||||
Ref ref = getRef(refName); | |||||
Ref ref = findRef(refName); | |||||
if (ref != null) | if (ref != null) | ||||
return new ReflogReaderImpl(this, ref.getName()); | return new ReflogReaderImpl(this, ref.getName()); | ||||
return null; | return null; |
if (trackingBranch == null) | if (trackingBranch == null) | ||||
return null; | return null; | ||||
Ref tracking = repository.getRef(trackingBranch); | |||||
Ref tracking = repository.exactRef(trackingBranch); | |||||
if (tracking == null) | if (tracking == null) | ||||
return null; | return null; | ||||
Ref local = repository.getRef(fullBranchName); | |||||
Ref local = repository.exactRef(fullBranchName); | |||||
if (local == null) | if (local == null) | ||||
return null; | return null; | ||||
* This is essentially the same as doing: | * This is essentially the same as doing: | ||||
* | * | ||||
* <pre> | * <pre> | ||||
* return getRef(Constants.HEAD).getTarget().getName() | |||||
* return exactRef(Constants.HEAD).getTarget().getName() | |||||
* </pre> | * </pre> | ||||
* | * | ||||
* Except when HEAD is detached, in which case this method returns the | * Except when HEAD is detached, in which case this method returns the | ||||
*/ | */ | ||||
@Nullable | @Nullable | ||||
public String getFullBranch() throws IOException { | public String getFullBranch() throws IOException { | ||||
Ref head = getRef(Constants.HEAD); | |||||
Ref head = exactRef(Constants.HEAD); | |||||
if (head == null) { | if (head == null) { | ||||
return null; | return null; | ||||
} | } |
String remoteName = null; | String remoteName = null; | ||||
// Look up remote URL associated wit HEAD ref | // 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 != null) { | ||||
if (ref.isSymbolic()) | if (ref.isSymbolic()) | ||||
ref = ref.getLeaf(); | ref = ref.getLeaf(); | ||||
if (subRepo == null) | if (subRepo == null) | ||||
return null; | return null; | ||||
try { | try { | ||||
Ref head = subRepo.getRef(Constants.HEAD); | |||||
Ref head = subRepo.exactRef(Constants.HEAD); | |||||
return head != null ? head.getLeaf().getName() : null; | return head != null ? head.getLeaf().getName() : null; | ||||
} finally { | } finally { | ||||
subRepo.close(); | subRepo.close(); |
import org.eclipse.jgit.errors.NoRemoteRepositoryException; | import org.eclipse.jgit.errors.NoRemoteRepositoryException; | ||||
import org.eclipse.jgit.errors.NotSupportedException; | import org.eclipse.jgit.errors.NotSupportedException; | ||||
import org.eclipse.jgit.errors.PackProtocolException; | import org.eclipse.jgit.errors.PackProtocolException; | ||||
import org.eclipse.jgit.errors.TooLargeObjectInPackException; | |||||
import org.eclipse.jgit.errors.TooLargePackException; | import org.eclipse.jgit.errors.TooLargePackException; | ||||
import org.eclipse.jgit.errors.TransportException; | import org.eclipse.jgit.errors.TransportException; | ||||
import org.eclipse.jgit.internal.JGitText; | import org.eclipse.jgit.internal.JGitText; | ||||
if (!unpackLine.startsWith("unpack ")) //$NON-NLS-1$ | if (!unpackLine.startsWith("unpack ")) //$NON-NLS-1$ | ||||
throw new PackProtocolException(uri, MessageFormat.format(JGitText.get().unexpectedReportLine, unpackLine)); | throw new PackProtocolException(uri, MessageFormat.format(JGitText.get().unexpectedReportLine, unpackLine)); | ||||
final String unpackStatus = unpackLine.substring("unpack ".length()); //$NON-NLS-1$ | 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, | throw new TooLargePackException(uri, | ||||
unpackStatus.substring("error ".length())); //$NON-NLS-1$ | 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( | throw new TransportException(uri, MessageFormat.format( | ||||
JGitText.get().errorOccurredDuringUnpackingOnTheRemoteEnd, unpackStatus)); | JGitText.get().errorOccurredDuringUnpackingOnTheRemoteEnd, unpackStatus)); | ||||
} | |||||
String refLine; | String refLine; | ||||
while ((refLine = pckIn.readString()) != PacketLineIn.END) { | while ((refLine = pckIn.readString()) != PacketLineIn.END) { |
for (final RefSpec spec : procRefs) { | for (final RefSpec spec : procRefs) { | ||||
String srcSpec = spec.getSource(); | String srcSpec = spec.getSource(); | ||||
final Ref srcRef = db.getRef(srcSpec); | |||||
final Ref srcRef = db.findRef(srcSpec); | |||||
if (srcRef != null) | if (srcRef != null) | ||||
srcSpec = srcRef.getName(); | srcSpec = srcRef.getName(); | ||||