git new-branch adds upstream_current

git new-branch --upstream_current <branch_name>
can create a new branch tracking the current branch.
I need this in my recipe so adding this flag to the
recipe module.

Bug: 1238169
Change-Id: I1816b8d78867848e7a8f80337a6d82db8b6ef777
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3095037
Commit-Queue: Sven Zheng <svenzheng@chromium.org>
Reviewed-by: Robbie Iannucci <iannucci@chromium.org>
changes/37/3095037/5
Sven Zheng 4 years ago committed by LUCI CQ
parent 0cb0d64c93
commit af70e1bf3b

@ -567,7 +567,7 @@ Returns: (str) The URL of the remote Git repository, or None.
Find and return the timestamp of the given commit.
&mdash; **def [new\_branch](/recipes/recipe_modules/git/api.py#401)(self, branch, name=None, upstream=None, \*\*kwargs):**
&mdash; **def [new\_branch](/recipes/recipe_modules/git/api.py#401)(self, branch, name=None, upstream=None, upstream_current=False, \*\*kwargs):**
Runs git new-branch on a Git repository, to be used before git cl
upload.
@ -576,6 +576,7 @@ Args:
* branch (str): new branch name, which must not yet exist.
* name (str): step name.
* upstream (str): to origin/main.
* upstream_current (bool): whether to use '--upstream_current'.
* kwargs: Forwarded to '__call__'.
&mdash; **def [rebase](/recipes/recipe_modules/git/api.py#337)(self, name_prefix, branch, dir_path, remote_name=None, \*\*kwargs):**

@ -398,7 +398,12 @@ class GitApi(recipe_api.RecipeApi):
rev_list_args = ['--all']
self('bundle', 'create', bundle_path, *rev_list_args, **kwargs)
def new_branch(self, branch, name=None, upstream=None, **kwargs):
def new_branch(self,
branch,
name=None,
upstream=None,
upstream_current=False,
**kwargs):
"""Runs git new-branch on a Git repository, to be used before git cl
upload.
@ -406,14 +411,19 @@ class GitApi(recipe_api.RecipeApi):
* branch (str): new branch name, which must not yet exist.
* name (str): step name.
* upstream (str): to origin/main.
* upstream_current (bool): whether to use '--upstream_current'.
* kwargs: Forwarded to '__call__'.
"""
if upstream and upstream_current:
raise ValueError('Can not define both upstream and upstream_current')
env = self.m.context.env
env['PATH'] = self.m.path.pathsep.join([
str(self.repo_resource()), '%(PATH)s'])
args = ['new-branch', branch]
if upstream:
args.extend(['--upstream', upstream])
if upstream_current:
args.append('--upstream_current')
if not name:
name = 'git new-branch %s' % branch
with self.m.context(env=env):

@ -189,6 +189,20 @@
"infra_step": true,
"name": "git new-branch feature"
},
{
"cmd": [
"git",
"new-branch",
"track_current",
"--upstream_current"
],
"cwd": "[START_DIR]/src",
"env": {
"PATH": "RECIPE_REPO[depot_tools]:<PATH>"
},
"infra_step": true,
"name": "git new-branch track_current"
},
{
"cmd": [
"git",

@ -189,6 +189,20 @@
"infra_step": true,
"name": "git new-branch feature"
},
{
"cmd": [
"git",
"new-branch",
"track_current",
"--upstream_current"
],
"cwd": "[START_DIR]/src",
"env": {
"PATH": "RECIPE_REPO[depot_tools]:<PATH>"
},
"infra_step": true,
"name": "git new-branch track_current"
},
{
"cmd": [
"git",

@ -191,6 +191,20 @@
"infra_step": true,
"name": "git new-branch feature"
},
{
"cmd": [
"git",
"new-branch",
"track_current",
"--upstream_current"
],
"cwd": "[START_DIR]/src",
"env": {
"PATH": "RECIPE_REPO[depot_tools]:<PATH>"
},
"infra_step": true,
"name": "git new-branch track_current"
},
{
"cmd": [
"git",

@ -188,6 +188,20 @@
"infra_step": true,
"name": "git new-branch feature"
},
{
"cmd": [
"git",
"new-branch",
"track_current",
"--upstream_current"
],
"cwd": "[START_DIR]/src",
"env": {
"PATH": "RECIPE_REPO[depot_tools]:<PATH>"
},
"infra_step": true,
"name": "git new-branch track_current"
},
{
"cmd": [
"git",

@ -189,6 +189,20 @@
"infra_step": true,
"name": "git new-branch feature"
},
{
"cmd": [
"git",
"new-branch",
"track_current",
"--upstream_current"
],
"cwd": "[START_DIR]/src",
"env": {
"PATH": "RECIPE_REPO[depot_tools]:<PATH>"
},
"infra_step": true,
"name": "git new-branch track_current"
},
{
"cmd": [
"git",

@ -190,6 +190,20 @@
"infra_step": true,
"name": "git new-branch feature"
},
{
"cmd": [
"git",
"new-branch",
"track_current",
"--upstream_current"
],
"cwd": "[START_DIR]/src",
"env": {
"PATH": "RECIPE_REPO[depot_tools]:<PATH>"
},
"infra_step": true,
"name": "git new-branch track_current"
},
{
"cmd": [
"git",

@ -190,6 +190,20 @@
"infra_step": true,
"name": "git new-branch feature"
},
{
"cmd": [
"git",
"new-branch",
"track_current",
"--upstream_current"
],
"cwd": "[START_DIR]/src",
"env": {
"PATH": "RECIPE_REPO[depot_tools]:<PATH>"
},
"infra_step": true,
"name": "git new-branch track_current"
},
{
"cmd": [
"git",

@ -192,6 +192,20 @@
"infra_step": true,
"name": "git new-branch feature"
},
{
"cmd": [
"git",
"new-branch",
"track_current",
"--upstream_current"
],
"cwd": "[START_DIR]/src",
"env": {
"PATH": "RECIPE_REPO[depot_tools]:<PATH>"
},
"infra_step": true,
"name": "git new-branch track_current"
},
{
"cmd": [
"git",

@ -189,6 +189,20 @@
"infra_step": true,
"name": "git new-branch feature"
},
{
"cmd": [
"git",
"new-branch",
"track_current",
"--upstream_current"
],
"cwd": "[START_DIR]/src",
"env": {
"PATH": "RECIPE_REPO[depot_tools]:<PATH>"
},
"infra_step": true,
"name": "git new-branch track_current"
},
{
"cmd": [
"git",

@ -262,6 +262,20 @@
"infra_step": true,
"name": "git new-branch feature"
},
{
"cmd": [
"git",
"new-branch",
"track_current",
"--upstream_current"
],
"cwd": "[START_DIR]/src",
"env": {
"PATH": "RECIPE_REPO[depot_tools]:<PATH>"
},
"infra_step": true,
"name": "git new-branch track_current"
},
{
"cmd": [
"git",

@ -192,6 +192,20 @@
"infra_step": true,
"name": "git new-branch feature"
},
{
"cmd": [
"git",
"new-branch",
"track_current",
"--upstream_current"
],
"cwd": "[START_DIR]/src",
"env": {
"PATH": "RECIPE_REPO[depot_tools]:<PATH>"
},
"infra_step": true,
"name": "git new-branch track_current"
},
{
"cmd": [
"git",

@ -194,6 +194,20 @@
"infra_step": true,
"name": "git new-branch feature"
},
{
"cmd": [
"git",
"new-branch",
"track_current",
"--upstream_current"
],
"cwd": "[START_DIR]/src",
"env": {
"PATH": "RECIPE_REPO[depot_tools]:<PATH>"
},
"infra_step": true,
"name": "git new-branch track_current"
},
{
"cmd": [
"git",

@ -190,6 +190,20 @@
"infra_step": true,
"name": "git new-branch feature"
},
{
"cmd": [
"git",
"new-branch",
"track_current",
"--upstream_current"
],
"cwd": "[START_DIR]/src",
"env": {
"PATH": "RECIPE_REPO[depot_tools]:<PATH>"
},
"infra_step": true,
"name": "git new-branch track_current"
},
{
"cmd": [
"git",

@ -237,6 +237,20 @@
"infra_step": true,
"name": "git new-branch feature"
},
{
"cmd": [
"git",
"new-branch",
"track_current",
"--upstream_current"
],
"cwd": "[START_DIR]/src",
"env": {
"PATH": "RECIPE_REPO[depot_tools]:<PATH>"
},
"infra_step": true,
"name": "git new-branch track_current"
},
{
"cmd": [
"git",

@ -0,0 +1,198 @@
[
{
"cmd": [
"python",
"-u",
"RECIPE_MODULE[depot_tools::git]/resources/git_setup.py",
"--path",
"[START_DIR]/src",
"--url",
"https://chromium.googlesource.com/chromium/src.git"
],
"name": "git setup"
},
{
"cmd": [
"git",
"fetch",
"origin",
"main",
"--recurse-submodules",
"--progress"
],
"cwd": "[START_DIR]/src",
"env": {
"PATH": "RECIPE_REPO[depot_tools]:<PATH>"
},
"infra_step": true,
"name": "git fetch"
},
{
"cmd": [
"git",
"checkout",
"-f",
"FETCH_HEAD"
],
"cwd": "[START_DIR]/src",
"infra_step": true,
"name": "git checkout"
},
{
"cmd": [
"git",
"rev-parse",
"HEAD"
],
"cwd": "[START_DIR]/src",
"infra_step": true,
"name": "read revision",
"~followup_annotations": [
"@@@STEP_TEXT@<br/>checked out 'deadbeef'<br/>@@@"
]
},
{
"cmd": [
"git",
"clean",
"-f",
"-d",
"-x"
],
"cwd": "[START_DIR]/src",
"infra_step": true,
"name": "git clean"
},
{
"cmd": [
"git",
"submodule",
"sync"
],
"cwd": "[START_DIR]/src",
"infra_step": true,
"name": "submodule sync"
},
{
"cmd": [
"git",
"submodule",
"update",
"--init",
"--recursive"
],
"cwd": "[START_DIR]/src",
"infra_step": true,
"name": "submodule update"
},
{
"cmd": [
"git",
"-c",
"foo=bar",
"count-objects",
"-v"
],
"cwd": "[START_DIR]/src",
"infra_step": true,
"name": "count-objects"
},
{
"cmd": [
"git",
"config",
"--get",
"remote.origin.url"
],
"cwd": "[START_DIR]/src",
"infra_step": true,
"name": "git config remote.origin.url",
"~followup_annotations": [
"@@@STEP_TEXT@foo@@@"
]
},
{
"cmd": [
"git",
"show",
"HEAD",
"--format=%at",
"-s"
],
"cwd": "[START_DIR]/src",
"infra_step": true,
"name": "git show"
},
{
"cmd": [
"git",
"fetch",
"origin",
"--tags"
],
"cwd": "[START_DIR]/src",
"infra_step": true,
"name": "git fetch tags"
},
{
"cmd": [
"git",
"status"
],
"cwd": "[START_DIR]/src",
"infra_step": true,
"name": "git status"
},
{
"cmd": [
"git",
"status"
],
"cwd": "[START_DIR]/src",
"infra_step": true,
"name": "git status can_fail_build"
},
{
"cmd": [
"git",
"status"
],
"cwd": "[START_DIR]/src",
"infra_step": true,
"name": "git status cannot_fail_build"
},
{
"cmd": [
"git",
"new-branch",
"refactor"
],
"cwd": "[START_DIR]/src",
"env": {
"PATH": "RECIPE_REPO[depot_tools]:<PATH>"
},
"infra_step": true,
"name": "git new-branch refactor"
},
{
"cmd": [],
"name": "RECIPE CRASH (Uncaught exception)",
"~followup_annotations": [
"@@@STEP_EXCEPTION@@@",
"The recipe has crashed at point 'Uncaught exception'!",
"",
"Traceback (most recent call last):",
" File \"RECIPE_REPO[depot_tools]/recipes/recipe_modules/git/examples/full.py\", line 83, in RunSteps",
" upstream_current=True)",
" File \"RECIPE_REPO[depot_tools]/recipes/recipe_modules/git/api.py\", line 418, in new_branch",
" raise ValueError('Can not define both upstream and upstream_current')",
"ValueError: Can not define both upstream and upstream_current"
]
},
{
"failure": {
"humanReason": "Uncaught Exception: ValueError('Can not define both upstream and upstream_current',)"
},
"name": "$result"
}
]

@ -189,6 +189,20 @@
"infra_step": true,
"name": "git new-branch feature"
},
{
"cmd": [
"git",
"new-branch",
"track_current",
"--upstream_current"
],
"cwd": "[START_DIR]\\src",
"env": {
"PATH": "RECIPE_REPO[depot_tools];<PATH>"
},
"infra_step": true,
"name": "git new-branch track_current"
},
{
"cmd": [
"git",

@ -189,6 +189,20 @@
"infra_step": true,
"name": "git new-branch feature"
},
{
"cmd": [
"git",
"new-branch",
"track_current",
"--upstream_current"
],
"cwd": "[START_DIR]/src",
"env": {
"PATH": "RECIPE_REPO[depot_tools]:<PATH>"
},
"infra_step": true,
"name": "git new-branch track_current"
},
{
"cmd": [
"git",

@ -191,6 +191,20 @@
"infra_step": true,
"name": "git new-branch feature"
},
{
"cmd": [
"git",
"new-branch",
"track_current",
"--upstream_current"
],
"cwd": "[START_DIR]/src",
"env": {
"PATH": "RECIPE_REPO[depot_tools]:<PATH>"
},
"infra_step": true,
"name": "git new-branch track_current"
},
{
"cmd": [
"git",

@ -190,6 +190,20 @@
"infra_step": true,
"name": "git new-branch feature"
},
{
"cmd": [
"git",
"new-branch",
"track_current",
"--upstream_current"
],
"cwd": "[START_DIR]/src",
"env": {
"PATH": "RECIPE_REPO[depot_tools]:<PATH>"
},
"infra_step": true,
"name": "git new-branch track_current"
},
{
"cmd": [
"git",

@ -76,9 +76,15 @@ def RunSteps(api):
# You should run git new-branch before you upload something with git cl.
api.git.new_branch('refactor') # Upstream is origin/main by default.
if api.properties.get('set_both_upstream_and_upstream_current'):
api.git.new_branch('failed_new_branch',
upstream='will_fail',
upstream_current=True)
# And use upstream kwarg to set up different upstream for tracking.
api.git.new_branch('feature', upstream='refactor')
# A new branching tracking the current branch, which is 'feature'.
api.git.new_branch('track_current', upstream_current=True)
# You can use api.git.rebase to rebase the current branch onto another one
api.git.rebase(name_prefix='my repo', branch='origin/main',
dir_path=api.path['checkout'],
@ -168,3 +174,7 @@ def GenTests(api):
yield (
api.test('git-cache-checkout') +
api.properties(use_git_cache=True))
yield (api.test('new_branch_failed') +
api.properties(set_both_upstream_and_upstream_current=True) +
api.expect_exception('ValueError'))

Loading…
Cancel
Save