Commit 512dfd67 authored by Thiago Perrotta's avatar Thiago Perrotta Committed by LUCI CQ

fetch: make --no-history and --no-hooks switches consistent

Before this commit, the following switches exist:

- --nohooks
- --no-history

They are not consistent. This commit makes the following switches
available:

- --nohooks, --no-hooks
- --nohistory, --no-history

Bug: None
Change-Id: Iaea2357c05e3dc69e3fac0fb9d823db903d811bb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3904446
Auto-Submit: Thiago Perrotta <tperrotta@chromium.org>
Commit-Queue: Aravind Vasudevan <aravindvasudev@google.com>
Reviewed-by: 's avatarAravind Vasudevan <aravindvasudev@google.com>
parent 18bdadc9
...@@ -140,7 +140,7 @@ class GclientGitCheckout(GclientCheckout, GitCheckout): ...@@ -140,7 +140,7 @@ class GclientGitCheckout(GclientCheckout, GitCheckout):
sync_cmd = ['sync'] sync_cmd = ['sync']
if self.options.nohooks: if self.options.nohooks:
sync_cmd.append('--nohooks') sync_cmd.append('--nohooks')
if self.options.no_history: if self.options.nohistory:
sync_cmd.append('--no-history') sync_cmd.append('--no-history')
if self.spec.get('with_branch_heads', False): if self.spec.get('with_branch_heads', False):
sync_cmd.append('--with_branch_heads') sync_cmd.append('--with_branch_heads')
...@@ -154,7 +154,7 @@ class GclientGitCheckout(GclientCheckout, GitCheckout): ...@@ -154,7 +154,7 @@ class GclientGitCheckout(GclientCheckout, GitCheckout):
'submodule', 'foreach', 'submodule', 'foreach',
'git config -f $toplevel/.git/config submodule.$name.ignore all', 'git config -f $toplevel/.git/config submodule.$name.ignore all',
cwd=wd) cwd=wd)
if not self.options.no_history: if not self.options.nohistory:
self.run_git( self.run_git(
'config', '--add', 'remote.origin.fetch', 'config', '--add', 'remote.origin.fetch',
'+refs/tags/*:refs/tags/*', cwd=wd) '+refs/tags/*:refs/tags/*', cwd=wd)
...@@ -194,10 +194,17 @@ def handle_args(argv): ...@@ -194,10 +194,17 @@ def handle_args(argv):
parser.add_argument('-n', '--dry-run', action='store_true', default=False, parser.add_argument('-n', '--dry-run', action='store_true', default=False,
help='Don\'t run commands, only print them.') help='Don\'t run commands, only print them.')
parser.add_argument('--nohooks', action='store_true', default=False, parser.add_argument('--nohooks',
help='Don\'t run hooks after checkout.') '--no-hooks',
parser.add_argument('--no-history', action='store_true', default=False, action='store_true',
help='Perform shallow clones, don\'t fetch the full git history.') default=False,
help='Don\'t run hooks after checkout.')
parser.add_argument(
'--nohistory',
'--no-history',
action='store_true',
default=False,
help='Perform shallow clones, don\'t fetch the full git history.')
parser.add_argument('--force', action='store_true', default=False, parser.add_argument('--force', action='store_true', default=False,
help='(dangerous) Don\'t look for existing .gclient file.') help='(dangerous) Don\'t look for existing .gclient file.')
parser.add_argument( parser.add_argument(
......
...@@ -48,40 +48,40 @@ class TestUtilityFunctions(unittest.TestCase): ...@@ -48,40 +48,40 @@ class TestUtilityFunctions(unittest.TestCase):
def test_handle_args_valid_usage(self): def test_handle_args_valid_usage(self):
response = fetch.handle_args(['filename', 'foo']) response = fetch.handle_args(['filename', 'foo'])
self.assertEqual(argparse.Namespace( self.assertEqual(
dry_run=False, argparse.Namespace(dry_run=False,
nohooks=False, nohooks=False,
no_history=False, nohistory=False,
force=False, force=False,
config='foo', config='foo',
protocol_override=None, protocol_override=None,
props=[]), response) props=[]), response)
response = fetch.handle_args([ response = fetch.handle_args([
'filename', '-n', '--dry-run', '--nohooks', '--no-history', '--force', 'filename', '-n', '--dry-run', '--nohooks', '--no-history', '--force',
'--protocol-override', 'sso', 'foo', '--some-param=1', '--bar=2' '--protocol-override', 'sso', 'foo', '--some-param=1', '--bar=2'
]) ])
self.assertEqual(argparse.Namespace( self.assertEqual(
dry_run=True, argparse.Namespace(dry_run=True,
nohooks=True, nohooks=True,
no_history=True, nohistory=True,
force=True, force=True,
config='foo', config='foo',
protocol_override='sso', protocol_override='sso',
props=['--some-param=1', '--bar=2']), response) props=['--some-param=1', '--bar=2']), response)
response = fetch.handle_args([ response = fetch.handle_args([
'filename', '-n', '--dry-run', '--nohooks', '--no-history', '--force', 'filename', '-n', '--dry-run', '--no-hooks', '--nohistory', '--force',
'-p', 'sso', 'foo', '--some-param=1', '--bar=2' '-p', 'sso', 'foo', '--some-param=1', '--bar=2'
]) ])
self.assertEqual(argparse.Namespace( self.assertEqual(
dry_run=True, argparse.Namespace(dry_run=True,
nohooks=True, nohooks=True,
no_history=True, nohistory=True,
force=True, force=True,
config='foo', config='foo',
protocol_override='sso', protocol_override='sso',
props=['--some-param=1', '--bar=2']), response) props=['--some-param=1', '--bar=2']), response)
@mock.patch('os.path.exists', return_value=False) @mock.patch('os.path.exists', return_value=False)
@mock.patch('sys.stdout', StringIO()) @mock.patch('sys.stdout', StringIO())
...@@ -237,8 +237,7 @@ class TestGclientGitCheckout(unittest.TestCase): ...@@ -237,8 +237,7 @@ class TestGclientGitCheckout(unittest.TestCase):
self.run_gclient = mock.patch('fetch.GclientCheckout.run_gclient').start() self.run_gclient = mock.patch('fetch.GclientCheckout.run_gclient').start()
self.run_git = mock.patch('fetch.GitCheckout.run_git').start() self.run_git = mock.patch('fetch.GitCheckout.run_git').start()
self.opts = argparse.Namespace( self.opts = argparse.Namespace(dry_run=False, nohooks=True, nohistory=False)
dry_run=False, nohooks=True, no_history=False)
specs = { specs = {
'solutions': [{ 'solutions': [{
'foo': 'bar', 'foo': 'bar',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment