[pgm] Add --mirror option to clone command
Bug: 552173 Change-Id: Ic8a98b2e0f8f29afd599723f93e51b06b9f13314 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
parent
bceac7bd03
commit
c24eee4fa4
|
@ -44,6 +44,7 @@
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -54,7 +55,13 @@
|
||||||
import org.eclipse.jgit.junit.MockSystemReader;
|
import org.eclipse.jgit.junit.MockSystemReader;
|
||||||
import org.eclipse.jgit.lib.CLIRepositoryTestCase;
|
import org.eclipse.jgit.lib.CLIRepositoryTestCase;
|
||||||
import org.eclipse.jgit.lib.Constants;
|
import org.eclipse.jgit.lib.Constants;
|
||||||
|
import org.eclipse.jgit.lib.ObjectId;
|
||||||
import org.eclipse.jgit.lib.Ref;
|
import org.eclipse.jgit.lib.Ref;
|
||||||
|
import org.eclipse.jgit.lib.RefUpdate;
|
||||||
|
import org.eclipse.jgit.lib.StoredConfig;
|
||||||
|
import org.eclipse.jgit.revwalk.RevCommit;
|
||||||
|
import org.eclipse.jgit.transport.RefSpec;
|
||||||
|
import org.eclipse.jgit.transport.RemoteConfig;
|
||||||
import org.eclipse.jgit.transport.URIish;
|
import org.eclipse.jgit.transport.URIish;
|
||||||
import org.eclipse.jgit.util.SystemReader;
|
import org.eclipse.jgit.util.SystemReader;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -90,10 +97,10 @@ public void testClone() throws Exception {
|
||||||
assertEquals("expected 1 branch", 1, branches.size());
|
assertEquals("expected 1 branch", 1, branches.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createInitialCommit() throws Exception {
|
private RevCommit createInitialCommit() throws Exception {
|
||||||
JGitTestUtil.writeTrashFile(db, "hello.txt", "world");
|
JGitTestUtil.writeTrashFile(db, "hello.txt", "world");
|
||||||
git.add().addFilepattern("hello.txt").call();
|
git.add().addFilepattern("hello.txt").call();
|
||||||
git.commit().setMessage("Initial commit").call();
|
return git.commit().setMessage("Initial commit").call();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -154,4 +161,37 @@ public void testCloneBare() throws Exception {
|
||||||
assertEquals("expected 1 branch", 1, branches.size());
|
assertEquals("expected 1 branch", 1, branches.size());
|
||||||
assertTrue("expected bare repository", git2.getRepository().isBare());
|
assertTrue("expected bare repository", git2.getRepository().isBare());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCloneMirror() throws Exception {
|
||||||
|
ObjectId head = createInitialCommit();
|
||||||
|
// create a non-standard ref
|
||||||
|
RefUpdate ru = db.updateRef("refs/meta/foo/bar");
|
||||||
|
ru.setNewObjectId(head);
|
||||||
|
ru.update();
|
||||||
|
|
||||||
|
File gitDir = db.getDirectory();
|
||||||
|
String sourcePath = gitDir.getAbsolutePath();
|
||||||
|
String targetPath = (new File(sourcePath)).getParentFile()
|
||||||
|
.getParentFile().getAbsolutePath() + File.separator
|
||||||
|
+ "target.git";
|
||||||
|
String cmd = "git clone --mirror " + shellQuote(sourcePath) + " "
|
||||||
|
+ shellQuote(targetPath);
|
||||||
|
String[] result = execute(cmd);
|
||||||
|
assertArrayEquals(
|
||||||
|
new String[] { "Cloning into '" + targetPath + "'...", "", "" },
|
||||||
|
result);
|
||||||
|
Git git2 = Git.open(new File(targetPath));
|
||||||
|
List<Ref> branches = git2.branchList().call();
|
||||||
|
assertEquals("expected 1 branch", 1, branches.size());
|
||||||
|
assertTrue("expected bare repository", git2.getRepository().isBare());
|
||||||
|
StoredConfig config = git2.getRepository().getConfig();
|
||||||
|
RemoteConfig rc = new RemoteConfig(config, "origin");
|
||||||
|
assertTrue("expected mirror configuration", rc.isMirror());
|
||||||
|
RefSpec fetchRefSpec = rc.getFetchRefSpecs().get(0);
|
||||||
|
assertTrue("exected force udpate", fetchRefSpec.isForceUpdate());
|
||||||
|
assertEquals("refs/*", fetchRefSpec.getSource());
|
||||||
|
assertEquals("refs/*", fetchRefSpec.getDestination());
|
||||||
|
assertNotNull(git2.getRepository().exactRef("refs/meta/foo/bar"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -223,6 +223,9 @@ 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_AlwaysFallback=Show uniquely abbreviated commit object as fallback
|
usage_AlwaysFallback=Show uniquely abbreviated commit object as fallback
|
||||||
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_mirrorClone=Set up a mirror of the source repository. This implies --bare. Compared to --bare, --mirror not only maps \
|
||||||
|
local branches of the source to local branches of the target, it maps all refs (including remote-tracking branches, notes etc.) \
|
||||||
|
and sets up a refspec configuration such that all these refs are overwritten by a git remote update in the target repository.
|
||||||
usage_Blame=Show what revision and author last modified each line
|
usage_Blame=Show what revision and author last modified each line
|
||||||
usage_Clean=Remove untracked files from the working tree
|
usage_Clean=Remove untracked files from the working tree
|
||||||
usage_CommandLineClientForamazonsS3Service=Command line client for Amazon's S3 service
|
usage_CommandLineClientForamazonsS3Service=Command line client for Amazon's S3 service
|
||||||
|
|
|
@ -74,6 +74,9 @@ class Clone extends AbstractFetchCommand implements CloneCommand.Callback {
|
||||||
@Option(name = "--bare", usage = "usage_bareClone")
|
@Option(name = "--bare", usage = "usage_bareClone")
|
||||||
private boolean isBare;
|
private boolean isBare;
|
||||||
|
|
||||||
|
@Option(name = "--mirror", usage = "usage_mirrorClone")
|
||||||
|
private boolean isMirror;
|
||||||
|
|
||||||
@Option(name = "--quiet", usage = "usage_quiet")
|
@Option(name = "--quiet", usage = "usage_quiet")
|
||||||
private Boolean quiet;
|
private Boolean quiet;
|
||||||
|
|
||||||
|
@ -103,7 +106,7 @@ protected void run() throws Exception {
|
||||||
if (localName == null) {
|
if (localName == null) {
|
||||||
try {
|
try {
|
||||||
localName = uri.getHumanishName();
|
localName = uri.getHumanishName();
|
||||||
if (isBare) {
|
if (isBare || isMirror) {
|
||||||
localName = localName + Constants.DOT_GIT_EXT;
|
localName = localName + Constants.DOT_GIT_EXT;
|
||||||
}
|
}
|
||||||
localNameF = new File(SystemReader.getInstance().getProperty(
|
localNameF = new File(SystemReader.getInstance().getProperty(
|
||||||
|
@ -120,6 +123,7 @@ protected void run() throws Exception {
|
||||||
|
|
||||||
CloneCommand command = Git.cloneRepository();
|
CloneCommand command = Git.cloneRepository();
|
||||||
command.setURI(sourceUri).setRemote(remoteName).setBare(isBare)
|
command.setURI(sourceUri).setRemote(remoteName).setBare(isBare)
|
||||||
|
.setMirror(isMirror)
|
||||||
.setNoCheckout(noCheckout).setBranch(branch)
|
.setNoCheckout(noCheckout).setBranch(branch)
|
||||||
.setCloneSubmodules(cloneSubmodules);
|
.setCloneSubmodules(cloneSubmodules);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue