From cdd7c23446a0030e5b521d91cbb2d3a9c522ccc2 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Mon, 5 Oct 2015 16:01:11 -0700 Subject: RepoCommand: Add setRecordRemoteBranch option to record upstream branch On a server also running Gerrit that is using RepoCommand to convert from an XML manifest to a git submodule superproject periodically, it would be handy to be able to use Gerrit's submodule subscription feature[1] to update the superproject automatically between RepoCommand runs as changes are merged in each subprojects. This requires setting the 'branch' field for each submodule so that Gerrit knows what branch to watch. Add an option to do that. Setting the branch field also is useful for plain Git users, since it allows them to use "git submodule update --remote" to manually update all submodules between RepoCommand runs. [1] https://gerrit-review.googlesource.com/Documentation/user-submodules.html Change-Id: I1a10861bcd0df3b3673fc2d481c8129b2bdac5f9 Signed-off-by: Stefan Beller --- .../src/org/eclipse/jgit/gitrepo/RepoCommand.java | 33 ++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'org.eclipse.jgit') 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 790f4db672..d298331f54 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java @@ -106,6 +106,7 @@ public class RepoCommand extends GitCommand { private String groups; private String branch; private String targetBranch = Constants.HEAD; + private boolean recordRemoteBranch = false; private PersonIdent author; private RemoteReader callback; private InputStream inputStream; @@ -313,6 +314,30 @@ public class RepoCommand extends GitCommand { return this; } + /** + * Set whether the branch name should be recorded in .gitmodules + *

+ * Submodule entries in .gitmodules can include a "branch" field + * to indicate what remote branch each submodule tracks. + *

+ * That field is used by "git submodule update --remote" to update + * to the tip of the tracked branch when asked and by Gerrit to + * update the superproject when a change on that branch is merged. + *

+ * Subprojects that request a specific commit or tag will not have + * a branch name recorded. + *

+ * Not implemented for non-bare repositories. + * + * @param record Whether to record the branch name + * @return this command + * @since 4.2 + */ + public RepoCommand setRecordRemoteBranch(boolean update) { + this.recordRemoteBranch = update; + return this; + } + /** * The progress monitor associated with the clone operation. By default, * this is set to NullProgressMonitor @@ -429,10 +454,14 @@ public class RepoCommand extends GitCommand { // create gitlink DirCacheEntry dcEntry = new DirCacheEntry(name); ObjectId objectId; - if (ObjectId.isId(proj.getRevision())) + if (ObjectId.isId(proj.getRevision())) { objectId = ObjectId.fromString(proj.getRevision()); - else { + } else { objectId = callback.sha1(nameUri, proj.getRevision()); + if (recordRemoteBranch) + // can be branch or tag + cfg.setString("submodule", name, "branch", //$NON-NLS-1$ //$NON-NLS-2$ + proj.getRevision()); } if (objectId == null) throw new RemoteUnavailableException(nameUri); -- cgit v1.2.3