Merge "Topic: do not use '(detached' when detached"
This commit is contained in:
commit
af50581629
@ -126,7 +126,7 @@ def run_command_status(*argv, **env):
|
||||
argv = shlex.split(argv[0].encode('utf-8'))
|
||||
else:
|
||||
argv = shlex.split(str(argv[0]))
|
||||
newenv = os.environ
|
||||
newenv = os.environ.copy()
|
||||
newenv.update(env)
|
||||
p = subprocess.Popen(argv, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT, env=newenv)
|
||||
@ -643,15 +643,15 @@ def get_branch_name(target_branch):
|
||||
if _branch_name is not None:
|
||||
return _branch_name
|
||||
_branch_name = None
|
||||
cmd = "git branch"
|
||||
has_color = check_color_support()
|
||||
if has_color:
|
||||
color_never = "--color=never"
|
||||
else:
|
||||
color_never = ""
|
||||
for branch in run_command("git branch %s" % color_never).split("\n"):
|
||||
cmd += " --color=never"
|
||||
for branch in run_command(cmd, LANG='C').split("\n"):
|
||||
if branch.startswith('*'):
|
||||
_branch_name = branch.split()[1].strip()
|
||||
if _branch_name == "(no":
|
||||
break
|
||||
if _branch_name == "(no" or _branch_name == "(detached":
|
||||
_branch_name = target_branch
|
||||
return _branch_name
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
# -*- coding: utf8 -*-
|
||||
|
||||
# Copyright (c) 2013 Mirantis Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -13,6 +15,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from git_review import tests
|
||||
@ -168,6 +171,24 @@ class GitReviewTestCase(tests.BaseGitReviewTestCase):
|
||||
self.assertIn('rebase', review_res)
|
||||
self.assertEqual(self._run_git('rev-parse', 'HEAD^1'), head)
|
||||
|
||||
def test_detached_head(self):
|
||||
"""Test on a detached state: we shouldn't have '(detached' as topic."""
|
||||
self._run_git_review('-s')
|
||||
curr_branch = self._run_git('rev-parse', '--abbrev-ref', 'HEAD')
|
||||
# Note: git checkout --detach has been introduced in git 1.7.5 (2011)
|
||||
self._run_git('checkout', curr_branch + '^0')
|
||||
self._simple_change('some new message', 'just another file',
|
||||
self._dir('test', 'new_test_file.txt'))
|
||||
# switch to French, 'git branch' should return '(détaché du HEAD)'
|
||||
lang_env = os.getenv('LANG', 'C')
|
||||
os.environ.update(LANG='fr_FR.UTF-8')
|
||||
review = self._run_git_review('-n')
|
||||
os.environ.update(LANG=lang_env)
|
||||
# reattach
|
||||
self._run_git('checkout', curr_branch)
|
||||
# we should push to '(...)/master', not '(...)/(detached'
|
||||
self.assertTrue(review.strip().split('\n')[-1].endswith(curr_branch))
|
||||
|
||||
|
||||
class HttpGitReviewTestCase(tests.HttpMixin, GitReviewTestCase):
|
||||
"""Class for the git-review tests over HTTP(S)."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user