diff --git a/src/repository/api/ArcanistGitAPI.php b/src/repository/api/ArcanistGitAPI.php index 38865f8e..34113f45 100644 --- a/src/repository/api/ArcanistGitAPI.php +++ b/src/repository/api/ArcanistGitAPI.php @@ -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; diff --git a/src/workflow/ArcanistPatchWorkflow.php b/src/workflow/ArcanistPatchWorkflow.php index 6d2e2dfd..c0896250 100644 --- a/src/workflow/ArcanistPatchWorkflow.php +++ b/src/workflow/ArcanistPatchWorkflow.php @@ -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 {