Add option --orphan for checkout
Change-Id: I546a93f3e147d8d6fc70094b22679c0d11cd8921 Signed-off-by: Rüdiger Herrmann <ruediger.herrmann@gmx.de>
This commit is contained in:
parent
3c2b4086b6
commit
fc801dd79f
|
@ -188,6 +188,18 @@ public void testCheckoutWithMissingWorkingTreeFile() throws Exception {
|
||||||
assertEquals("Hello world a", read(fileA));
|
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:
|
* Steps:
|
||||||
* <ol>
|
* <ol>
|
||||||
|
|
|
@ -345,3 +345,4 @@ usage_updateRemoteRefsFromAnotherRepository=Update remote refs from another repo
|
||||||
usage_useNameInsteadOfOriginToTrackUpstream=use <name> instead of 'origin' to track upstream
|
usage_useNameInsteadOfOriginToTrackUpstream=use <name> instead of 'origin' to track upstream
|
||||||
usage_checkoutBranchAfterClone=checkout named branch instead of remotes's HEAD
|
usage_checkoutBranchAfterClone=checkout named branch instead of remotes's HEAD
|
||||||
usage_viewCommitHistory=View commit history
|
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.
|
|
@ -71,6 +71,9 @@ class Checkout extends TextBuiltin {
|
||||||
@Option(name = "--force", aliases = { "-f" }, usage = "usage_forceCheckout")
|
@Option(name = "--force", aliases = { "-f" }, usage = "usage_forceCheckout")
|
||||||
private boolean force = false;
|
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")
|
@Argument(required = true, index = 0, metaVar = "metaVar_name", usage = "usage_checkout")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
@ -95,6 +98,7 @@ protected void run() throws Exception {
|
||||||
command.setCreateBranch(createBranch);
|
command.setCreateBranch(createBranch);
|
||||||
command.setName(name);
|
command.setName(name);
|
||||||
command.setForce(force);
|
command.setForce(force);
|
||||||
|
command.setOrphan(orphan);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
String oldBranch = db.getBranch();
|
String oldBranch = db.getBranch();
|
||||||
|
@ -107,10 +111,9 @@ protected void run() throws Exception {
|
||||||
name));
|
name));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (createBranch)
|
if (createBranch || orphan)
|
||||||
outw.println(MessageFormat.format(
|
outw.println(MessageFormat.format(
|
||||||
CLIText.get().switchedToNewBranch,
|
CLIText.get().switchedToNewBranch, name));
|
||||||
Repository.shortenRefName(ref.getName())));
|
|
||||||
else
|
else
|
||||||
outw.println(MessageFormat.format(
|
outw.println(MessageFormat.format(
|
||||||
CLIText.get().switchedToBranch,
|
CLIText.get().switchedToBranch,
|
||||||
|
|
Loading…
Reference in New Issue