]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Support --nobranch when not currently on a branch
authorEdward Speyer <edward@fb.com>
Fri, 19 Oct 2012 19:12:57 +0000 (12:12 -0700)
committerEdward Speyer <edward@fb.com>
Fri, 19 Oct 2012 19:12:57 +0000 (12:12 -0700)
Summary:
This is horrible and git specific, but fixes a case where people are using "arc
patch --nobranch ..." when they're not currently on a branch.

The old code assumed you were on a branch and used getBranchName() to record
this, in order to return to that branch later and cherry-pick the patch.

When not on a branch, and using arc patch --nobranch, this was trying to return
to the branch '(no branch)'.

Now, I detect that we're not on a branch and just record what HEAD is instead.

Test Plan:
Checkout the SHA of master (so I'm on master, but not on a branch) then try to
patch it with a feature diff:

  € git checkout e7a3ec68159d6847372cab5ad913f2f15aa7c249
  Warning: you are leaving 1 commit behind, not connected to
  any of your branches:

    ac1ad39 Updating a-file

  If you want to keep them by creating a new branch, this may be a good time
  to do so with:

   git branch new_branch_name ac1ad392350a51edd10343f12b9713f5e5b3707c

  HEAD is now at e7a3ec6... Fix arcconfig

  € arc patch --nobranch D7
  Created and checked out branch arcpatch-D7.
   OKAY  Successfully committed patch.

  € git branch
  * (no branch)
    feature
    haddock
    master

  € git log --oneline | head -2
  38c0235 Updating a-file
  e7a3ec6 Fix arcconfig

Reviewers: vrana, epriestley

Reviewed By: epriestley

CC: aran, Korvin
Differential Revision: https://secure.phabricator.com/D3743

src/repository/api/ArcanistGitAPI.php
src/workflow/ArcanistPatchWorkflow.php

index 38865f8eb1bdb4c3abc47492e7186e102f911f8b..34113f45548ed4f56ea298769c2e7ea869d64a3b 100644 (file)
@@ -338,8 +338,10 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI {
     // But that may fail if you're not on a branch.
     list($stdout) = $this->execxLocal('branch --no-color');
 
+    // Assume that any branch beginning with '(' means 'no branch', or whatever
+    // 'no branch' is in the current locale.
     $matches = null;
-    if (preg_match('/^\* (.+)$/m', $stdout, $matches)) {
+    if (preg_match('/^\* ([^\(].*)$/m', $stdout, $matches)) {
       return $matches[1];
     }
     return null;
index 6d2e2dfd1e03d81b5d0b0614aa80d27c776dcf4c..c0896250275a29c5d2c00ccea24ab656e3767e00 100644 (file)
@@ -471,8 +471,16 @@ EOTEXT
     $repository_api = $this->getRepositoryAPI();
 
     $has_base_revision = $this->hasBaseRevision($bundle);
-    if ($this->canBranch() && ($this->shouldBranch() || $has_base_revision)) {
+    if ($this->shouldCommit() &&
+        $this->canBranch() &&
+        ($this->shouldBranch() || $has_base_revision)) {
+
       $original_branch = $repository_api->getBranchName();
+      // If we weren't on a branch, then record the ref we'll return to
+      // instead.
+      if ($original_branch === null) {
+        $original_branch = $repository_api->getCanonicalRevisionName('HEAD');
+      }
       $new_branch = $this->createBranch($bundle, $has_base_revision);
     }
 
@@ -724,7 +732,8 @@ EOTEXT
         $verb = 'applied';
       }
 
-      if ($this->canBranch() && !$this->shouldBranch() && $has_base_revision) {
+      if ($this->shouldCommit() && $this->canBranch() &&
+          !$this->shouldBranch() && $has_base_revision) {
         $repository_api->execxLocal('checkout %s', $original_branch);
         $ex = null;
         try {