From 13d6c94cfb4783a8b92dd26c7a9b3de134d8c018 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 26 Jul 2021 13:57:31 -0400 Subject: [PATCH 1/9] bash-completion: fallback to default completion If we can't provide any completions, then fallback to the standard bash & readline ones. This allows completion based on the user's settings (e.g. local paths) to kick in. Bug: https://crbug.com/gerrit/14797 Test: `repo rebase ./src/` works in a CrOS checkout Change-Id: Iced343c4fc6fd3a932aab99875c1346687d187b6 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/312902 Reviewed-by: Xin Li Tested-by: Mike Frysinger --- completion.bash | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/completion.bash b/completion.bash index 0b52d29c..3c1fd683 100644 --- a/completion.bash +++ b/completion.bash @@ -118,4 +118,6 @@ __complete_repo() { return 0 } -complete -F __complete_repo repo +# Fallback to the default complete methods if we aren't able to provide anything +# useful. This will allow e.g. local paths to be used when it makes sense. +complete -F __complete_repo -o bashdefault -o default repo From b380322174c9b67da99ce743ff49382bab5cf351 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 26 Jul 2021 15:26:22 -0400 Subject: [PATCH 2/9] bash-completion: refactor unique subcommand processing Let's keep the main processing loop free of subcommand implementations by pulling the existing help & start commands into dedicated functions. Having a single giant function is harder to track as we add more and more logic in. Bug: https://crbug.com/gerrit/14797 Change-Id: I2b62dc430c0e7574f09aa4838f4ef03fbe4bf7fb Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/312903 Reviewed-by: Xin Li Tested-by: Mike Frysinger --- completion.bash | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/completion.bash b/completion.bash index 3c1fd683..04347ce3 100644 --- a/completion.bash +++ b/completion.bash @@ -66,6 +66,31 @@ __complete_repo_command_projects() { COMPREPLY=($(compgen -W "$(__complete_repo_list_projects)" -- "${current}")) } +# Complete `repo help`. +__complete_repo_command_help() { + local current=$1 + # CWORD=1 is "start". + # CWORD=2 is the which we complete here. + if [[ ${COMP_CWORD} -eq 2 ]]; then + COMPREPLY=( + $(compgen -W "$(__complete_repo_list_commands)" -- "${current}") + ) + fi +} + +# Complete `repo start`. +__complete_repo_command_start() { + local current=$1 + # CWORD=1 is "start". + # CWORD=2 is the which we don't complete. + # CWORD=3+ are which we complete here. + if [[ ${COMP_CWORD} -gt 2 ]]; then + COMPREPLY=( + $(compgen -W "$(__complete_repo_list_projects)" -- "${current}") + ) + fi +} + # Complete the repo subcommand arguments. __complete_repo_arg() { if [[ ${COMP_CWORD} -le 1 ]]; then @@ -86,21 +111,8 @@ __complete_repo_arg() { return 0 ;; - help) - if [[ ${COMP_CWORD} -eq 2 ]]; then - COMPREPLY=( - $(compgen -W "$(__complete_repo_list_commands)" -- "${current}") - ) - fi - return 0 - ;; - - start) - if [[ ${COMP_CWORD} -gt 2 ]]; then - COMPREPLY=( - $(compgen -W "$(__complete_repo_list_projects)" -- "${current}") - ) - fi + help|start) + __complete_repo_command_${command} "${current}" return 0 ;; From 5467185db0fe31558dbb57f08135c316861a86b1 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 26 Jul 2021 15:28:01 -0400 Subject: [PATCH 3/9] list: add a --relative-to option The current list output only shows project paths relative to the root of the repo client checkout. It can be helpful to also get a listing of paths based on other paths (e.g. the current working directory), so add an option to repo list to support that. We'll leverage this in bash completion to support completing projects by their local paths and not just remote names. Bug: https://crbug.com/gerrit/14797 Change-Id: Ia2b35d18c890217768448118b003874a1016efd4 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/312904 Reviewed-by: Xin Li Tested-by: Mike Frysinger --- completion.bash | 1 + man/repo-list.1 | 12 ++++++++---- subcmds/list.py | 16 +++++++++++++--- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/completion.bash b/completion.bash index 04347ce3..6a5bfe1c 100644 --- a/completion.bash +++ b/completion.bash @@ -37,6 +37,7 @@ __complete_repo_list_branches() { __complete_repo_list_projects() { local repo=${COMP_WORDS[0]} "${repo}" list -n 2>/dev/null + "${repo}" list -p --relative-to=. 2>/dev/null } # Complete the repo argument. diff --git a/man/repo-list.1 b/man/repo-list.1 index a86315ae..7f85e612 100644 --- a/man/repo-list.1 +++ b/man/repo-list.1 @@ -27,15 +27,19 @@ project is in \fB\-a\fR, \fB\-\-all\fR show projects regardless of checkout state .TP -\fB\-f\fR, \fB\-\-fullpath\fR -display the full work tree path instead of the -relative path -.TP \fB\-n\fR, \fB\-\-name\-only\fR display only the name of the repository .TP \fB\-p\fR, \fB\-\-path\-only\fR display only the path of the repository +.TP +\fB\-f\fR, \fB\-\-fullpath\fR +display the full work tree path instead of the +relative path +.TP +\fB\-\-relative\-to\fR=\fI\,PATH\/\fR +display paths relative to this one (default: top of +repo client checkout) .SS Logging options: .TP \fB\-v\fR, \fB\-\-verbose\fR diff --git a/subcmds/list.py b/subcmds/list.py index 8d0c5640..6adf85b7 100644 --- a/subcmds/list.py +++ b/subcmds/list.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import os + from command import Command, MirrorSafeCommand @@ -43,20 +45,26 @@ This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'. p.add_option('-a', '--all', action='store_true', help='show projects regardless of checkout state') - p.add_option('-f', '--fullpath', - dest='fullpath', action='store_true', - help='display the full work tree path instead of the relative path') p.add_option('-n', '--name-only', dest='name_only', action='store_true', help='display only the name of the repository') p.add_option('-p', '--path-only', dest='path_only', action='store_true', help='display only the path of the repository') + p.add_option('-f', '--fullpath', + dest='fullpath', action='store_true', + help='display the full work tree path instead of the relative path') + p.add_option('--relative-to', metavar='PATH', + help='display paths relative to this one (default: top of repo client checkout)') def ValidateOptions(self, opt, args): if opt.fullpath and opt.name_only: self.OptionParser.error('cannot combine -f and -n') + # Resolve any symlinks so the output is stable. + if opt.relative_to: + opt.relative_to = os.path.realpath(opt.relative_to) + def Execute(self, opt, args): """List all projects and the associated directories. @@ -76,6 +84,8 @@ This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'. def _getpath(x): if opt.fullpath: return x.worktree + if opt.relative_to: + return os.path.relpath(x.worktree, opt.relative_to) return x.relpath lines = [] From cfa00d6e3d6825cbe4390fbaaf5980cd6b1be77e Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 26 Jul 2021 15:30:10 -0400 Subject: [PATCH 4/9] bash-completion: complete projects with repo forall We need to add a little bit more logic here so we stop completing projects once we see the -c argument. Bug: https://crbug.com/gerrit/14797 Change-Id: Ic2ba4f3dd616ec49d8ad754ff62d0d6e0250dbe6 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/312905 Reviewed-by: Xin Li Tested-by: Mike Frysinger --- completion.bash | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/completion.bash b/completion.bash index 6a5bfe1c..09291d5c 100644 --- a/completion.bash +++ b/completion.bash @@ -14,6 +14,9 @@ # Programmable bash completion. https://github.com/scop/bash-completion +# TODO: Handle interspersed options. We handle `repo h`, but not +# `repo --time h`. + # Complete the list of repo subcommands. __complete_repo_list_commands() { local repo=${COMP_WORDS[0]} @@ -79,6 +82,23 @@ __complete_repo_command_help() { fi } +# Complete `repo forall`. +__complete_repo_command_forall() { + local current=$1 + # CWORD=1 is "forall". + # CWORD=2+ are *until* we hit the -c option. + local i + for (( i = 0; i < COMP_CWORD; ++i )); do + if [[ "${COMP_WORDS[i]}" == "-c" ]]; then + return 0 + fi + done + + COMPREPLY=( + $(compgen -W "$(__complete_repo_list_projects)" -- "${current}") + ) +} + # Complete `repo start`. __complete_repo_command_start() { local current=$1 @@ -112,7 +132,7 @@ __complete_repo_arg() { return 0 ;; - help|start) + help|start|forall) __complete_repo_command_${command} "${current}" return 0 ;; From 968d646f046355313008bfddfbd3fde1e0e14339 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 26 Jul 2021 23:20:29 -0400 Subject: [PATCH 5/9] repo: refactor internal --help/--version parsing The _ParseArgs method parses the arguments and processes some of the options, with the rest left to the _Run method. Simplify the _ParseArgs method to only parse arguments and have _Run handle all actual processing. This will make it easier to add more terminal options (ones that exit immediately without a subcommand), and makes it easier to understand the overall code flow. Change-Id: I47f7274c3f2b59378fd479e403e70fb24b681536 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/312906 Reviewed-by: Xin Li Tested-by: Mike Frysinger --- main.py | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/main.py b/main.py index f6631f5f..5c8ea85c 100755 --- a/main.py +++ b/main.py @@ -130,32 +130,21 @@ class _Repo(object): def _ParseArgs(self, argv): """Parse the main `repo` command line options.""" - name = None - glob = [] - - for i in range(len(argv)): - if not argv[i].startswith('-'): - name = argv[i] - if i > 0: - glob = argv[:i] + for i, arg in enumerate(argv): + if not arg.startswith('-'): + name = arg + glob = argv[:i] argv = argv[i + 1:] break - if not name: + else: + name = None glob = argv - name = 'help' argv = [] gopts, _gargs = global_options.parse_args(glob) - name, alias_args = self._ExpandAlias(name) - argv = alias_args + argv - - if gopts.help: - global_options.print_help() - commands = ' '.join(sorted(self.commands)) - wrapped_commands = textwrap.wrap(commands, width=77) - print('\nAvailable commands:\n %s' % ('\n '.join(wrapped_commands),)) - print('\nRun `repo help ` for command-specific details.') - global_options.exit() + if name: + name, alias_args = self._ExpandAlias(name) + argv = alias_args + argv return (name, gopts, argv) @@ -186,12 +175,23 @@ class _Repo(object): if gopts.trace: SetTrace() - if gopts.show_version: - if name == 'help': - name = 'version' - else: + + # Handle options that terminate quickly first. + if gopts.help: + global_options.print_help() + commands = ' '.join(sorted(self.commands)) + wrapped_commands = textwrap.wrap(commands, width=77) + print('\nAvailable commands:\n %s' % ('\n '.join(wrapped_commands),)) + print('\nRun `repo help ` for command-specific details.') + return 0 + elif gopts.show_version: + if name and name != 'help': print('fatal: invalid usage of --version', file=sys.stderr) return 1 + name = 'version' + elif not name: + # No subcommand specified, so show the help/subcommand. + name = 'help' SetDefaultColoring(gopts.color) From a024bd33b808489acc909036b63697a819cc6ce7 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 26 Jul 2021 23:31:06 -0400 Subject: [PATCH 6/9] repo: make --version always work We don't really care what the subcommand is set to when --version output is requested, so stop enforcing it. This fixes some weird behavior like `repo --version version` fails, but `repo --version help` works. The new logic skips subcommand validation, so `repo --version asdf` will still display the version output. This matches git behavior, and makes a bit of sense when we consider that the user really wants to see the tool version, and probably doesn't care about anything else on the command line. Change-Id: I87454d473c2c8869344b3888a7affaa2e03f5b0f Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/312907 Reviewed-by: Xin Li Tested-by: Mike Frysinger --- main.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/main.py b/main.py index 5c8ea85c..253f3112 100755 --- a/main.py +++ b/main.py @@ -185,9 +185,7 @@ class _Repo(object): print('\nRun `repo help ` for command-specific details.') return 0 elif gopts.show_version: - if name and name != 'help': - print('fatal: invalid usage of --version', file=sys.stderr) - return 1 + # Always allow global --version regardless of subcommand validity. name = 'version' elif not name: # No subcommand specified, so show the help/subcommand. From 56345c345bdfdd71399d17ccd0ffe8f39bf720eb Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 26 Jul 2021 23:46:32 -0400 Subject: [PATCH 7/9] repo: refactor help output handling Currently we have the behavior: * `repo`: Equivalent to `repo help` -- only shows common subcommands (with short description), and then exits 0. * `repo --help`: Shows repo's core options, lists all commands (no specific info), and then exits 0. The first case is not behaving well: * If you run `repo` without a specific subcommand, that's an error, so we should be exiting 1 instead. * Showing only subcommands and no actual option summary makes it seem like repo itself doesn't take any options. This confuses users. Let's rework things a bit. Now we have the behavior: * `repo`: Shows repo's core options, lists all commands (no specific info), and then exits 1. * `repo --help`: Shows repo's core options, shows common subcommands (with short description), and then exits 0. * `repo --help-all`: Shows repo's core options, shows all subcommands (with short description), and then exits 0. Basically we swap the behavior of `repo` and `repo --help`, and fix the exit status when the subcommand is missing. The addition of --help-all is mostly for the man pages. We were relying on `repo help --all` to generate the repo(1) man page, but that too omitted the core repo options. Now the man page includes all the core repo options and provides a summary of all commands. Change-Id: I1f99b99d5b8af2591f96a078d0647a3d76d6b0fc Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/312908 Reviewed-by: Xin Li Tested-by: Mike Frysinger --- main.py | 30 ++++++++++++++++++++++------- man/repo-manifest.1 | 19 +++++++++++-------- man/repo.1 | 42 ++++++++++++++++++++++++++++++++++++++--- release/update-manpages | 2 +- subcmds/help.py | 7 +++++++ 5 files changed, 81 insertions(+), 19 deletions(-) diff --git a/main.py b/main.py index 253f3112..229cb729 100755 --- a/main.py +++ b/main.py @@ -95,6 +95,8 @@ global_options = optparse.OptionParser( add_help_option=False) global_options.add_option('-h', '--help', action='store_true', help='show this help message and exit') +global_options.add_option('--help-all', action='store_true', + help='show this help message with all subcommands and exit') global_options.add_option('-p', '--paginate', dest='pager', action='store_true', help='display command output in the pager') @@ -128,6 +130,23 @@ class _Repo(object): self.repodir = repodir self.commands = all_commands + def _PrintHelp(self, short: bool = False, all_commands: bool = False): + """Show --help screen.""" + global_options.print_help() + print() + if short: + commands = ' '.join(sorted(self.commands)) + wrapped_commands = textwrap.wrap(commands, width=77) + print('Available commands:\n %s' % ('\n '.join(wrapped_commands),)) + print('\nRun `repo help ` for command-specific details.') + print('Bug reports:', Wrapper().BUG_URL) + else: + cmd = self.commands['help']() + if all_commands: + cmd.PrintAllCommandsBody() + else: + cmd.PrintCommonCommandsBody() + def _ParseArgs(self, argv): """Parse the main `repo` command line options.""" for i, arg in enumerate(argv): @@ -177,19 +196,16 @@ class _Repo(object): SetTrace() # Handle options that terminate quickly first. - if gopts.help: - global_options.print_help() - commands = ' '.join(sorted(self.commands)) - wrapped_commands = textwrap.wrap(commands, width=77) - print('\nAvailable commands:\n %s' % ('\n '.join(wrapped_commands),)) - print('\nRun `repo help ` for command-specific details.') + if gopts.help or gopts.help_all: + self._PrintHelp(short=False, all_commands=gopts.help_all) return 0 elif gopts.show_version: # Always allow global --version regardless of subcommand validity. name = 'version' elif not name: # No subcommand specified, so show the help/subcommand. - name = 'help' + self._PrintHelp(short=True) + return 1 SetDefaultColoring(gopts.color) diff --git a/man/repo-manifest.1 b/man/repo-manifest.1 index e42cc42e..be467607 100644 --- a/man/repo-manifest.1 +++ b/man/repo-manifest.1 @@ -36,6 +36,9 @@ output manifest in JSON format (experimental) \fB\-\-pretty\fR format output for humans to read .TP +\fB\-\-no\-local\-manifests\fR +ignore local manifests +.TP \fB\-o\fR \-|NAME.xml, \fB\-\-output\-file\fR=\fI\,\-\/\fR|NAME.xml file to save the manifest to .SS Logging options: @@ -95,7 +98,7 @@ include*)> .IP .IP - + @@ -393,13 +396,13 @@ Same syntax as the corresponding element of `project`. .PP Element annotation .PP -Zero or more annotation elements may be specified as children of a project -element. Each element describes a name\-value pair that will be exported into -each project's environment during a 'forall' command, prefixed with REPO__. In -addition, there is an optional attribute "keep" which accepts the case -insensitive values "true" (default) or "false". This attribute determines -whether or not the annotation will be kept when exported with the manifest -subcommand. +Zero or more annotation elements may be specified as children of a project or +remote element. Each element describes a name\-value pair. For projects, this +name\-value pair will be exported into each project's environment during a +\&'forall' command, prefixed with `REPO__`. In addition, there is an optional +attribute "keep" which accepts the case insensitive values "true" (default) or +"false". This attribute determines whether or not the annotation will be kept +when exported with the manifest subcommand. .PP Element copyfile .PP diff --git a/man/repo.1 b/man/repo.1 index 0bc3acdb..0e85b0b7 100644 --- a/man/repo.1 +++ b/man/repo.1 @@ -2,9 +2,44 @@ .TH REPO "1" "July 2021" "repo" "Repo Manual" .SH NAME repo \- repository management tool built on top of git -.SH DESCRIPTION -usage: repo COMMAND [ARGS] -The complete list of recognized repo commands are: +.SH SYNOPSIS +.B repo +[\fI\,-p|--paginate|--no-pager\/\fR] \fI\,COMMAND \/\fR[\fI\,ARGS\/\fR] +.SH OPTIONS +.TP +\fB\-h\fR, \fB\-\-help\fR +show this help message and exit +.TP +\fB\-\-help\-all\fR +show this help message with all subcommands and exit +.TP +\fB\-p\fR, \fB\-\-paginate\fR +display command output in the pager +.TP +\fB\-\-no\-pager\fR +disable the pager +.TP +\fB\-\-color\fR=\fI\,COLOR\/\fR +control color usage: auto, always, never +.TP +\fB\-\-trace\fR +trace git command execution (REPO_TRACE=1) +.TP +\fB\-\-trace\-python\fR +trace python command execution +.TP +\fB\-\-time\fR +time repo command execution +.TP +\fB\-\-version\fR +display this version of repo +.TP +\fB\-\-event\-log\fR=\fI\,EVENT_LOG\/\fR +filename of event log to append timeline to +.TP +\fB\-\-git\-trace2\-event\-log\fR=\fI\,GIT_TRACE2_EVENT_LOG\/\fR +directory to write git trace2 event log to +.SS "The complete list of recognized repo commands are:" .TP abandon Permanently abandon a development branch @@ -91,3 +126,4 @@ version Display the version of repo .PP See 'repo help ' for more information on a specific command. +Bug reports: https://bugs.chromium.org/p/gerrit/issues/entry?template=Repo+tool+issue diff --git a/release/update-manpages b/release/update-manpages index 3aeee206..f841f306 100755 --- a/release/update-manpages +++ b/release/update-manpages @@ -59,7 +59,7 @@ def main(argv): cmdlist.append(['help2man', '-N', '-n', 'repository management tool built on top of git', '-S', 'repo', '-m', 'Repo Manual', f'--version-string={version}', '-o', MANDIR.joinpath('repo.1'), TOPDIR.joinpath('repo'), - '-h', 'help --all']) + '-h', '--help-all']) with tempfile.TemporaryDirectory() as tempdir: repo_dir = Path(tempdir) / '.repo' diff --git a/subcmds/help.py b/subcmds/help.py index f302e75c..1a60ef45 100644 --- a/subcmds/help.py +++ b/subcmds/help.py @@ -50,14 +50,21 @@ Displays detailed usage information about a command. def _PrintAllCommands(self): print('usage: repo COMMAND [ARGS]') + self.PrintAllCommandsBody() + + def PrintAllCommandsBody(self): print('The complete list of recognized repo commands are:') commandNames = list(sorted(all_commands)) self._PrintCommands(commandNames) print("See 'repo help ' for more information on a " 'specific command.') + print('Bug reports:', Wrapper().BUG_URL) def _PrintCommonCommands(self): print('usage: repo COMMAND [ARGS]') + self.PrintCommonCommandsBody() + + def PrintCommonCommandsBody(self): print('The most commonly used repo commands are:') def gitc_supported(cmd): From 73c43b839fe2ff974f13b7b06f9538762ce0b0d8 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 26 Jul 2021 15:42:59 -0400 Subject: [PATCH 8/9] repo: add --show-toplevel akin to git Simple API to make it easy to find the top of the repo client checkout for users. This mirrors the `git rev-parse --show-toplevel` API. Change-Id: I0c3f98def089d0fc9ebcfa50aa3dc02091c1c273 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/312909 Reviewed-by: Xin Li Tested-by: Mike Frysinger --- main.py | 7 +++++++ man/repo.1 | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/main.py b/main.py index 229cb729..2050cabb 100755 --- a/main.py +++ b/main.py @@ -118,6 +118,10 @@ global_options.add_option('--time', global_options.add_option('--version', dest='show_version', action='store_true', help='display this version of repo') +global_options.add_option('--show-toplevel', + action='store_true', + help='display the path of the top-level directory of ' + 'the repo client checkout') global_options.add_option('--event-log', dest='event_log', action='store', help='filename of event log to append timeline to') @@ -202,6 +206,9 @@ class _Repo(object): elif gopts.show_version: # Always allow global --version regardless of subcommand validity. name = 'version' + elif gopts.show_toplevel: + print(os.path.dirname(self.repodir)) + return 0 elif not name: # No subcommand specified, so show the help/subcommand. self._PrintHelp(short=True) diff --git a/man/repo.1 b/man/repo.1 index 0e85b0b7..4aa76380 100644 --- a/man/repo.1 +++ b/man/repo.1 @@ -34,6 +34,10 @@ time repo command execution \fB\-\-version\fR display this version of repo .TP +\fB\-\-show\-toplevel\fR +display the path of the top\-level directory of the +repo client checkout +.TP \fB\-\-event\-log\fR=\fI\,EVENT_LOG\/\fR filename of event log to append timeline to .TP From ae86a460222c34b2f9cd600e6d17f8fd4f467fae Mon Sep 17 00:00:00 2001 From: Raman Tenneti Date: Tue, 27 Jul 2021 08:54:59 -0700 Subject: [PATCH 9/9] superproject: Skip updating of superproject when -l is used with sync. Skip updating the superproject when -l is present and use the existing superproject, if available (this would make sync -l work as it's intended to do), and fall back to sync without superproject when not (this would catch the case when superproject is enabled by automatic rollout). Tested: $ repo sync -j 20 -n NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version` /usr/local/google/home/rtenneti/work/android/src/aosp/.repo/exp-superproject/925043f706ba64db713e9bf3b55987e2-superproject.git: Initial setup for superproject completed. Fetching: 100% (1032/1032), done in 41.184s ... $ repo_dev sync -j 20 -l prebuilts/asuite/: discarding 1 commits prebuilts/runtime/: discarding 1 commits ... repo sync has finished successfully. + With superproject-override.xml and test it. $ ls -l .repo/exp-superproject/ total 176 drwxr-xr-x 7 rtenneti primarygroup 4096 Jul 27 14:10 925043f706ba64db713e9bf3b55987e2-superproject.git -rw-r--r-- 1 rtenneti primarygroup 172742 Jul 27 14:10 superproject_override.xml rtenneti@rtenneti:~/work/android/src/aosp$ repo_dev sync -j 20 -l ... repo sync has finished successfully. + Rename the file superproject-override.xml and test it. $ ls -l .repo/exp-superproject/ total 176 drwxr-xr-x 7 rtenneti primarygroup 4096 Jul 27 14:10 925043f706ba64db713e9bf3b55987e2-superproject.git -rw-r--r-- 1 rtenneti primarygroup 172742 Jul 27 14:10 temp.xml $ repo_dev sync -j 20 -l Checking out: 1% (12/1031) platform/external/rust/crates/fallible-streaming-iteexternal/linux-kselftest/: discarding 1 commits prebuilts/remoteexecution-client/: discarding 1 commits Checking out: 51% (536/1031) platform/prebuilts/gcc/darwin-x86/aarch64/.... .... Checking out: 100% (1031/1031), done in 5.478s repo sync has finished successfully. Bug: [google internal] b/184368268 Change-Id: I3aba5872e4f7c299977b92c2a39847ef28698c5a Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/312962 Reviewed-by: Mike Frysinger Reviewed-by: Jonathan Nieder Tested-by: Raman Tenneti --- git_superproject.py | 5 +++++ subcmds/sync.py | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/git_superproject.py b/git_superproject.py index 86100960..8769355c 100644 --- a/git_superproject.py +++ b/git_superproject.py @@ -106,6 +106,11 @@ class Superproject(object): """Returns a dictionary of projects and their commit ids.""" return self._project_commit_ids + @property + def manifest_path(self): + """Returns the manifest path if the path exists or None.""" + return self._manifest_path if os.path.exists(self._manifest_path) else None + def _GetBranch(self): """Returns the branch name for getting the approved manifest.""" p = self._manifest.manifestProject diff --git a/subcmds/sync.py b/subcmds/sync.py index a770c253..74617544 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -301,6 +301,12 @@ later is required to fix a server side protocol bug. self.repodir, self.git_event_log, quiet=opt.quiet) + if opt.local_only: + manifest_path = superproject.manifest_path + if manifest_path: + self._ReloadManifest(manifest_path, load_local_manifests) + return manifest_path + all_projects = self.GetProjects(args, missing_ok=True, submodules_ok=opt.fetch_submodules)