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 ae4db0b7d..509adc2cb 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 @@ -46,6 +46,8 @@ import org.eclipse.jgit.storage.file.FileBasedConfig; import org.eclipse.jgit.treewalk.TreeWalk; import org.eclipse.jgit.util.FS; +import org.eclipse.jgit.util.IO; +import org.eclipse.jgit.util.RawParseUtils; import org.junit.Test; public class RepoCommandTest extends RepositoryTestCase { @@ -749,9 +751,55 @@ public void testRevisionBare() throws Exception { String gitlink = localDb.resolve(Constants.HEAD + ":foo").name(); assertEquals("The gitlink is same as remote head", oldCommitId.name(), gitlink); + + File dotmodules = new File(localDb.getWorkTree(), + Constants.DOT_GIT_MODULES); + assertTrue(dotmodules.exists()); + // The .gitmodules file should have "branch" lines + String gitModulesContents = RawParseUtils + .decode(IO.readFully(dotmodules)); + assertTrue(gitModulesContents.contains("branch = branch")); } } + @Test + public void testRevisionBare_ignoreTags() throws Exception { + 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).call(); + // Clone it + File directory = createTempDirectory("testReplaceManifestBare"); + File dotmodules; + try (Repository localDb = Git.cloneRepository().setDirectory(directory) + .setURI(remoteDb.getDirectory().toURI().toString()).call() + .getRepository()) { + dotmodules = new File(localDb.getWorkTree(), + Constants.DOT_GIT_MODULES); + assertTrue(dotmodules.exists()); + } + + // The .gitmodules file should not have "branch" lines + String gitModulesContents = RawParseUtils + .decode(IO.readFully(dotmodules)); + assertFalse(gitModulesContents.contains("branch")); + assertTrue(gitModulesContents.contains("ref = refs/tags/" + TAG)); + } + @Test public void testCopyFileBare() throws Exception { Repository remoteDb = createBareRepository(); 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 c039aaffa..5bf95def9 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java @@ -12,6 +12,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.eclipse.jgit.lib.Constants.DEFAULT_REMOTE_NAME; import static org.eclipse.jgit.lib.Constants.R_REMOTES; +import static org.eclipse.jgit.lib.Constants.R_TAGS; import java.io.File; import java.io.FileInputStream; @@ -587,8 +588,11 @@ public RevCommit call() throws GitAPIException { throw new RemoteUnavailableException(url); } if (recordRemoteBranch) { - // can be branch or tag - cfg.setString("submodule", name, "branch", //$NON-NLS-1$ //$NON-NLS-2$ + // "branch" field is only for non-tag references. + // Keep tags in "ref" field as hint for other tools. + String field = proj.getRevision().startsWith( + R_TAGS) ? "ref" : "branch"; //$NON-NLS-1$ //$NON-NLS-2$ + cfg.setString("submodule", name, field, //$NON-NLS-1$ proj.getRevision()); }