Jelajahi Sumber

fix crash in case HEAD exists as a file

Bug: 1428373
Change-Id: If9d988d542345dbfa0e02f7c3d6f935b48372df4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5018937
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Helmut Januschka <helmut@januschka.com>
Helmut Januschka 1 tahun lalu
induk
melakukan
6444de14d1
3 mengubah file dengan 8 tambahan dan 6 penghapusan
  1. 1 1
      git_cl.py
  2. 4 3
      git_common.py
  3. 3 2
      tests/git_cl_test.py

+ 1 - 1
git_cl.py

@@ -1848,7 +1848,7 @@ class Changelist(object):
             return options.message.strip()
 
         # Use the subject of the last commit as title by default.
-        title = RunGit(['show', '-s', '--format=%s', 'HEAD']).strip()
+        title = RunGit(['show', '-s', '--format=%s', 'HEAD', '--']).strip()
         if options.force or options.skip_title:
             return title
         user_title = gclient_utils.AskForData('Title for patchset [%s]: ' %

+ 4 - 3
git_common.py

@@ -897,7 +897,8 @@ def set_config(option, value, scope='local'):
 def get_dirty_files():
     # Make sure index is up-to-date before running diff-index.
     run_with_retcode('update-index', '--refresh', '-q')
-    return run('diff-index', '--ignore-submodules', '--name-status', 'HEAD')
+    return run('diff-index', '--ignore-submodules', '--name-status', 'HEAD',
+               '--')
 
 
 def is_dirty_git_tree(cmd):
@@ -1006,10 +1007,10 @@ def tags(*args):
 
 def thaw():
     took_action = False
-    with run_stream('rev-list', 'HEAD') as stream:
+    with run_stream('rev-list', 'HEAD', '--') as stream:
         for sha in stream:
             sha = sha.strip().decode('utf-8')
-            msg = run('show', '--format=%f%b', '-s', 'HEAD')
+            msg = run('show', '--format=%f%b', '-s', 'HEAD', '--')
             match = FREEZE_MATCHER.match(msg)
             if not match:
                 if not took_action:

+ 3 - 2
tests/git_cl_test.py

@@ -919,7 +919,8 @@ class TestGitCl(unittest.TestCase):
                     title = 'Initial upload'
             else:
                 calls += [
-                    ((['git', 'show', '-s', '--format=%s', 'HEAD'], ), ''),
+                    ((['git', 'show', '-s', '--format=%s', 'HEAD',
+                       '--'], ), ''),
                     (('ask_for_data', 'Title for patchset []: '), 'User input'),
                 ]
                 title = 'User input'
@@ -3733,7 +3734,7 @@ class ChangelistTest(unittest.TestCase):
     LAST_COMMIT_SUBJECT = 'Fixes goat teleporter destination to be Australia'
 
     def _mock_run_git(commands):
-        if commands == ['show', '-s', '--format=%s', 'HEAD']:
+        if commands == ['show', '-s', '--format=%s', 'HEAD', '--']:
             return ChangelistTest.LAST_COMMIT_SUBJECT
 
     def setUp(self):