Skip to content

Commit

Permalink
init: add --manifest-upstream-branch
Browse files Browse the repository at this point in the history
When a sha1 is provided to '--manifest-branch', the ref which
is expected to contain that sha1 can be provided using the new
'--manifest-upstream-branch' option. This is useful with
'--current-branch' to avoid having to sync all heads and tags,
or with a commit that comes from a non-head/tag ref (like a
Gerrit change ref).

Change-Id: I46a3e255ca69ed9e809039e58b0c163e02af94ef
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/436717
Reviewed-by: Josip Sokcevic <sokcevic@google.com>
Commit-Queue: Kaushik Lingarkar <kaushik.lingarkar@linaro.org>
Tested-by: Kaushik Lingarkar <kaushik.lingarkar@linaro.org>
  • Loading branch information
Kaushik Lingarkar authored and LUCI committed Sep 26, 2024
1 parent fabab4e commit d7ebdf5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
11 changes: 10 additions & 1 deletion man/repo-init.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man.
.TH REPO "1" "October 2022" "repo init" "Repo Manual"
.TH REPO "1" "September 2024" "repo init" "Repo Manual"
.SH NAME
repo \- repo init - manual page for repo init
.SH SYNOPSIS
Expand Down Expand Up @@ -28,6 +28,11 @@ manifest repository location
\fB\-b\fR REVISION, \fB\-\-manifest\-branch\fR=\fI\,REVISION\/\fR
manifest branch or revision (use HEAD for default)
.TP
\fB\-\-manifest\-upstream\-branch\fR=\fI\,BRANCH\/\fR
when a commit is provided to \fB\-\-manifest\-branch\fR, this
is the name of the git ref in which the commit can be
found
.TP
\fB\-m\fR NAME.xml, \fB\-\-manifest\-name\fR=\fI\,NAME\/\fR.xml
initial manifest file
.TP
Expand Down Expand Up @@ -163,6 +168,10 @@ The optional \fB\-b\fR argument can be used to select the manifest branch to che
and use. If no branch is specified, the remote's default branch is used. This is
equivalent to using \fB\-b\fR HEAD.
.PP
The optional \fB\-\-manifest\-upstream\-branch\fR argument can be used when a commit is
provided to \fB\-\-manifest\-branch\fR (or \fB\-b\fR), to specify the name of the git ref in
which the commit can be found.
.PP
The optional \fB\-m\fR argument can be used to specify an alternate manifest to be
used. If no manifest is specified, the manifest default.xml will be used.
.PP
Expand Down
8 changes: 7 additions & 1 deletion repo
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ if not REPO_REV:
BUG_URL = "https://issues.gerritcodereview.com/issues/new?component=1370071"

# increment this whenever we make important changes to this script
VERSION = (2, 45)
VERSION = (2, 48)

# increment this if the MAINTAINER_KEYS block is modified
KEYRING_VERSION = (2, 3)
Expand Down Expand Up @@ -282,6 +282,12 @@ def InitParser(parser):
metavar="REVISION",
help="manifest branch or revision (use HEAD for default)",
)
group.add_option(
"--manifest-upstream-branch",
help="when a commit is provided to --manifest-branch, this "
"is the name of the git ref in which the commit can be found",
metavar="BRANCH",
)
group.add_option(
"-m",
"--manifest-name",
Expand Down
11 changes: 11 additions & 0 deletions subcmds/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class Init(InteractiveCommand, MirrorSafeCommand):
to checkout and use. If no branch is specified, the remote's default
branch is used. This is equivalent to using -b HEAD.
The optional --manifest-upstream-branch argument can be used when a commit is
provided to --manifest-branch (or -b), to specify the name of the git ref in
which the commit can be found.
The optional -m argument can be used to specify an alternate manifest
to be used. If no manifest is specified, the manifest default.xml
will be used.
Expand Down Expand Up @@ -135,6 +139,7 @@ def _SyncManifest(self, opt):
# manifest project is special and is created when instantiating the
# manifest which happens before we parse options.
self.manifest.manifestProject.clone_depth = opt.manifest_depth
self.manifest.manifestProject.upstream = opt.manifest_upstream_branch
clone_filter_for_depth = (
"blob:none" if (_REPO_ALLOW_SHALLOW == "0") else None
)
Expand Down Expand Up @@ -317,6 +322,12 @@ def ValidateOptions(self, opt, args):
" be used with --standalone-manifest."
)

if opt.manifest_upstream_branch and opt.manifest_branch is None:
self.OptionParser.error(
"--manifest-upstream-branch cannot be used without "
"--manifest-branch."
)

if args:
if opt.manifest_url:
self.OptionParser.error(
Expand Down

0 comments on commit d7ebdf5

Please sign in to comment.