]> source.dussan.org Git - jgit.git/commitdiff
Add option --orphan for checkout 69/41069/1
authorRüdiger Herrmann <ruediger.herrmann@gmx.de>
Fri, 30 Jan 2015 23:09:27 +0000 (00:09 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Wed, 4 Feb 2015 12:35:32 +0000 (13:35 +0100)
Change-Id: I546a93f3e147d8d6fc70094b22679c0d11cd8921
Signed-off-by: Rüdiger Herrmann <ruediger.herrmann@gmx.de>
org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java
org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java

index 90284736cfaa754dae638bd97b652dba856e7b63..cef9b9e1a6cacf72c2841887c56eee86adbc0955 100644 (file)
@@ -188,6 +188,18 @@ public class CheckoutTest extends CLIRepositoryTestCase {
                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>
index 8a77bf928a408714ba69d8b30f4fe92128c20fc2..2806f91463af247ac00d9a5e73f8c9bc613b1797 100644 (file)
@@ -345,3 +345,4 @@ usage_updateRemoteRefsFromAnotherRepository=Update remote refs from another repo
 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
index 8f911fd9245df02a3469c7b71fe6ddc17ad6bc7d..56d4fcff029e254b4ce855fa207db1fa68679d7e 100644 (file)
@@ -71,6 +71,9 @@ class Checkout extends TextBuiltin {
        @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;
 
@@ -95,6 +98,7 @@ class Checkout extends TextBuiltin {
                        command.setCreateBranch(createBranch);
                        command.setName(name);
                        command.setForce(force);
+                       command.setOrphan(orphan);
                }
                try {
                        String oldBranch = db.getBranch();
@@ -107,10 +111,9 @@ class Checkout extends TextBuiltin {
                                                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,