[pgm] Add option --bare to clone command
Change-Id: I528491e3e20d3c9ebe37fe3cd2bf85b4644d8698 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
parent
563c1ad514
commit
15e8b4fb2e
|
@ -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.assertTrue;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -133,4 +134,23 @@ public void testCloneIntoCurrentDir() throws Exception {
|
||||||
List<Ref> branches = git2.branchList().call();
|
List<Ref> branches = git2.branchList().call();
|
||||||
assertEquals("expected 1 branch", 1, branches.size());
|
assertEquals("expected 1 branch", 1, branches.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testCloneBare() throws Exception {
|
||||||
|
createInitialCommit();
|
||||||
|
|
||||||
|
File gitDir = db.getDirectory();
|
||||||
|
String sourcePath = gitDir.getAbsolutePath();
|
||||||
|
String targetPath = (new File(sourcePath)).getParentFile()
|
||||||
|
.getParentFile().getAbsolutePath()
|
||||||
|
+ "/target.git";
|
||||||
|
StringBuilder cmd = new StringBuilder("git clone --bare ")
|
||||||
|
.append(sourcePath + " " + targetPath);
|
||||||
|
String[] result = execute(cmd.toString());
|
||||||
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,6 +67,9 @@ class Clone extends AbstractFetchCommand {
|
||||||
@Option(name = "--no-checkout", aliases = { "-n" }, usage = "usage_noCheckoutAfterClone")
|
@Option(name = "--no-checkout", aliases = { "-n" }, usage = "usage_noCheckoutAfterClone")
|
||||||
private boolean noCheckout;
|
private boolean noCheckout;
|
||||||
|
|
||||||
|
@Option(name = "--bare", usage = "usage_bareClone")
|
||||||
|
private boolean isBare;
|
||||||
|
|
||||||
@Argument(index = 0, required = true, metaVar = "metaVar_uriish")
|
@Argument(index = 0, required = true, metaVar = "metaVar_uriish")
|
||||||
private String sourceUri;
|
private String sourceUri;
|
||||||
|
|
||||||
|
@ -101,7 +104,7 @@ protected void run() throws Exception {
|
||||||
branch = Constants.HEAD;
|
branch = Constants.HEAD;
|
||||||
|
|
||||||
CloneCommand command = Git.cloneRepository();
|
CloneCommand command = Git.cloneRepository();
|
||||||
command.setURI(sourceUri).setRemote(remoteName)
|
command.setURI(sourceUri).setRemote(remoteName).setBare(isBare)
|
||||||
.setNoCheckout(noCheckout).setBranch(branch);
|
.setNoCheckout(noCheckout).setBranch(branch);
|
||||||
|
|
||||||
command.setGitDir(gitdir == null ? null : new File(gitdir));
|
command.setGitDir(gitdir == null ? null : new File(gitdir));
|
||||||
|
|
Loading…
Reference in New Issue