mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 02:31:29 +00:00
Colorize branch names for rebase-update
To ease the UX of finding the branch name when there's a conflict to resolve. Change-Id: I34d16f2f7bd897a60e96b0391772b5d8985f3cb6 Bug: none Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6278647 Commit-Queue: Josip Sokcevic <sokcevic@chromium.org> Reviewed-by: Josip Sokcevic <sokcevic@chromium.org> Auto-Submit: Paul Irish <paulirish@chromium.org> Reviewed-by: Gavin Mak <gavinmak@google.com>
This commit is contained in:
@@ -18,10 +18,15 @@ from pprint import pformat
|
||||
|
||||
import gclient_utils
|
||||
import git_common as git
|
||||
import setup_color
|
||||
|
||||
from third_party import colorama
|
||||
|
||||
STARTING_BRANCH_KEY = 'depot-tools.rebase-update.starting-branch'
|
||||
STARTING_WORKDIR_KEY = 'depot-tools.rebase-update.starting-workdir'
|
||||
|
||||
RESET = colorama.Fore.RESET + colorama.Back.RESET + colorama.Style.RESET_ALL
|
||||
BRIGHT = colorama.Style.BRIGHT
|
||||
|
||||
def find_return_branch_workdir():
|
||||
"""Finds the branch and working directory which we should return to after
|
||||
@@ -140,6 +145,9 @@ def remove_empty_branches(branch_tree):
|
||||
print(git.run('branch', '-d', branch))
|
||||
|
||||
|
||||
def format_branch_name(branch):
|
||||
return BRIGHT + branch + RESET
|
||||
|
||||
def rebase_branch(branch, parent, start_hash, no_squash):
|
||||
logging.debug('considering %s(%s) -> %s(%s) : %s', branch,
|
||||
git.hash_one(branch), parent, git.hash_one(parent),
|
||||
@@ -160,7 +168,7 @@ def rebase_branch(branch, parent, start_hash, no_squash):
|
||||
|
||||
if git.hash_one(parent) != start_hash:
|
||||
# Try a plain rebase first
|
||||
print('Rebasing:', branch)
|
||||
print('Rebasing:', format_branch_name(branch))
|
||||
consider_squashing = git.get_num_commits(branch) != 1 and not (
|
||||
no_squash)
|
||||
rebase_ret = git.rebase(parent,
|
||||
@@ -180,7 +188,10 @@ def rebase_branch(branch, parent, start_hash, no_squash):
|
||||
if not consider_squashing:
|
||||
print(mid_rebase_message)
|
||||
return False
|
||||
print("Failed! Attempting to squash", branch, "...", end=' ')
|
||||
print("Failed! Attempting to squash",
|
||||
format_branch_name(branch),
|
||||
"...",
|
||||
end=' ')
|
||||
sys.stdout.flush()
|
||||
squash_branch = branch + "_squash_attempt"
|
||||
git.run('checkout', '-b', squash_branch)
|
||||
@@ -225,7 +236,7 @@ def rebase_branch(branch, parent, start_hash, no_squash):
|
||||
print(mid_rebase_message)
|
||||
return False
|
||||
else:
|
||||
print('%s up-to-date' % branch)
|
||||
print('%s up-to-date' % format_branch_name(branch))
|
||||
|
||||
git.remove_merge_base(branch)
|
||||
git.get_or_create_merge_base(branch)
|
||||
@@ -324,7 +335,7 @@ def main(args=None):
|
||||
if branches_to_rebase:
|
||||
skipped = set(skipped).intersection(branches_to_rebase)
|
||||
for branch in skipped:
|
||||
print('Skipping %s: No upstream specified' % branch)
|
||||
print('Skipping %s: No upstream specified' % format_branch_name(branch))
|
||||
|
||||
if not opts.no_fetch:
|
||||
fetch_remotes(branch_tree)
|
||||
@@ -345,7 +356,7 @@ def main(args=None):
|
||||
if branches_to_rebase and branch not in branches_to_rebase:
|
||||
continue
|
||||
if git.is_dormant(branch):
|
||||
print('Skipping dormant branch', branch)
|
||||
print('Skipping dormant branch', format_branch_name(branch))
|
||||
else:
|
||||
ret = rebase_branch(branch, parent, merge_base[branch],
|
||||
opts.no_squash)
|
||||
@@ -369,7 +380,7 @@ def main(args=None):
|
||||
print()
|
||||
print('The following branches could not be cleanly rebased:')
|
||||
for branch in unrebased_branches:
|
||||
print(' %s' % branch)
|
||||
print(' %s' % format_branch_name(branch))
|
||||
|
||||
if not retcode:
|
||||
if not opts.keep_empty:
|
||||
@@ -406,6 +417,7 @@ def main(args=None):
|
||||
|
||||
|
||||
if __name__ == '__main__': # pragma: no cover
|
||||
setup_color.init()
|
||||
try:
|
||||
sys.exit(main())
|
||||
except KeyboardInterrupt:
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
import os
|
||||
import sys
|
||||
from unittest import mock
|
||||
|
||||
DEPOT_TOOLS_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
sys.path.insert(0, DEPOT_TOOLS_ROOT)
|
||||
@@ -67,6 +68,8 @@ class GitRebaseUpdateTest(git_test_utils.GitRepoReadWriteTestBase):
|
||||
self.repo.git('branch', '--set-upstream-to', 'origin/main', 'branch_G')
|
||||
|
||||
self.repo.to_schema_refs += ['origin/main']
|
||||
mock.patch('git_rebase_update.RESET', '').start()
|
||||
mock.patch('git_rebase_update.BRIGHT', '').start()
|
||||
|
||||
def tearDown(self):
|
||||
self.origin.nuke()
|
||||
|
||||
Reference in New Issue
Block a user