Add --bypass-hooks option to git_sync_cl_chain.py
Change-Id: I14c82b9684df1cc4a4f4f0f1b12e22af1eed027b
diff --git a/tools/git_sync_cl_chain.py b/tools/git_sync_cl_chain.py
index 7dc512e..0fd65c6 100755
--- a/tools/git_sync_cl_chain.py
+++ b/tools/git_sync_cl_chain.py
@@ -40,6 +40,9 @@
def ParseOptions(argv):
result = optparse.OptionParser()
+ result.add_option('--bypass-hooks',
+ help='Bypass presubmit hooks',
+ action='store_true')
result.add_option('--delete', '-d',
help='Delete closed branches',
choices=['y', 'n', 'ask'],
@@ -103,7 +106,7 @@
utils.RunCmd(['git', 'checkout', branch.name], quiet=True)
- status = get_status_for_current_branch()
+ status = get_status_for_current_branch(branch)
print('Syncing %s (status: %s)' % (branch.name, status))
pull_for_current_branch(branch, options)
@@ -135,8 +138,10 @@
'Cannot upload branch %s since it comes after a local branch'
% branch.name)
else:
- utils.RunCmd(
- ['git', 'cl', 'upload', '-m', options.message], quiet=True)
+ upload_cmd = ['git', 'cl', 'upload', '-m', options.message]
+ if options.bypass_hooks:
+ upload_cmd.append('--bypass-hooks')
+ utils.RunCmd(upload_cmd, quiet=True)
if get_delete_branches_option(closed_branches, options):
delete_branches(closed_branches)
@@ -169,11 +174,13 @@
answer = sys.stdin.read(1)
return answer.lower() == 'y'
-def get_status_for_current_branch():
+def get_status_for_current_branch(current_branch):
+ if current_branch.name == 'main':
+ return 'main'
return utils.RunCmd(['git', 'cl', 'status', '--field', 'status'], quiet=True)[0].strip()
def is_root_branch(branch, options):
- return branch == options.from_branch or branch.upstream is None
+ return branch.name == options.from_branch or branch.upstream is None
def pull_for_current_branch(branch, options):
if branch.name == 'main' and options.skip_main:
diff --git a/tools/utils.py b/tools/utils.py
index 1fb323f..ecd172c 100644
--- a/tools/utils.py
+++ b/tools/utils.py
@@ -209,6 +209,8 @@
self._quiet = quiet
def log(self, text):
+ if len(text.strip()) == 0:
+ return
if self._quiet:
if self._has_printed:
sys.stdout.write(ProgressLogger.UP + ProgressLogger.CLEAR_LINE)