assertEquals("Hello world a", read(fileA));
}
+ @Test
+ public void testCheckoutOrphan() throws Exception {
+ Git git = new Git(db);
+ git.commit().setMessage("initial commit").call();
+
+ assertEquals("Switched to a new branch 'new_branch'",
+ execute("git checkout --orphan new_branch"));
+ assertEquals("refs/heads/new_branch", db.getRef("HEAD").getTarget().getName());
+ RevCommit commit = git.commit().setMessage("orphan commit").call();
+ assertEquals(0, commit.getParentCount());
+ }
+
/**
* Steps:
* <ol>
usage_useNameInsteadOfOriginToTrackUpstream=use <name> instead of 'origin' to track upstream
usage_checkoutBranchAfterClone=checkout named branch instead of remotes's HEAD
usage_viewCommitHistory=View commit history
+usage_orphan=Create a new orphan branch. The first commit made on this new branch will have no parents amd it will be the root of a new history totally disconnected from other branches and commits.
\ No newline at end of file
@Option(name = "--force", aliases = { "-f" }, usage = "usage_forceCheckout")
private boolean force = false;
+ @Option(name = "--orphan", usage = "usage_orphan")
+ private boolean orphan = false;
+
@Argument(required = true, index = 0, metaVar = "metaVar_name", usage = "usage_checkout")
private String name;
command.setCreateBranch(createBranch);
command.setName(name);
command.setForce(force);
+ command.setOrphan(orphan);
}
try {
String oldBranch = db.getBranch();
name));
return;
}
- if (createBranch)
+ if (createBranch || orphan)
outw.println(MessageFormat.format(
- CLIText.get().switchedToNewBranch,
- Repository.shortenRefName(ref.getName())));
+ CLIText.get().switchedToNewBranch, name));
else
outw.println(MessageFormat.format(
CLIText.get().switchedToBranch,