diff --git a/recipe_modules/git/api.py b/recipe_modules/git/api.py index dddb1de80..746c18fe5 100644 --- a/recipe_modules/git/api.py +++ b/recipe_modules/git/api.py @@ -409,3 +409,22 @@ class GitApi(recipe_api.RecipeApi): if not rev_list_args: rev_list_args = ['--all'] self('bundle', 'create', bundle_path, *rev_list_args, **kwargs) + + def new_branch(self, branch, name=None, upstream=None, **kwargs): + """Runs git new-branch on a Git repository, to be used before git cl upload. + + Args: + branch (str): new branch name, which must not yet exist. + name (str): step name. + upstream (str): to origin/master. + kwargs: Forwarded to '__call__'. + """ + env = kwargs.pop('env', {}) + env['PATH'] = self.m.path.pathsep.join([ + str(self.package_repo_resource()), '%(PATH)s']) + args = ['new-branch', branch] + if upstream: + args.extend(['--upstream', upstream]) + if not name: + name = 'git new-branch %s' % branch + return self(*args, name=name, env=env, **kwargs) diff --git a/recipe_modules/git/example.expected/basic.json b/recipe_modules/git/example.expected/basic.json index f4cafcbe5..97a2b595a 100644 --- a/recipe_modules/git/example.expected/basic.json +++ b/recipe_modules/git/example.expected/basic.json @@ -152,6 +152,32 @@ "cwd": "[SLAVE_BUILD]/src", "name": "git status cannot_fail_build" }, + { + "cmd": [ + "git", + "new-branch", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch refactor" + }, + { + "cmd": [ + "git", + "new-branch", + "feature", + "--upstream", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch feature" + }, { "cmd": [ "git", diff --git a/recipe_modules/git/example.expected/basic_branch.json b/recipe_modules/git/example.expected/basic_branch.json index 4a63e621a..fca2bb50f 100644 --- a/recipe_modules/git/example.expected/basic_branch.json +++ b/recipe_modules/git/example.expected/basic_branch.json @@ -152,6 +152,32 @@ "cwd": "[SLAVE_BUILD]/src", "name": "git status cannot_fail_build" }, + { + "cmd": [ + "git", + "new-branch", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch refactor" + }, + { + "cmd": [ + "git", + "new-branch", + "feature", + "--upstream", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch feature" + }, { "cmd": [ "git", diff --git a/recipe_modules/git/example.expected/basic_file_name.json b/recipe_modules/git/example.expected/basic_file_name.json index e5d3c448f..49a993126 100644 --- a/recipe_modules/git/example.expected/basic_file_name.json +++ b/recipe_modules/git/example.expected/basic_file_name.json @@ -154,6 +154,32 @@ "cwd": "[SLAVE_BUILD]/src", "name": "git status cannot_fail_build" }, + { + "cmd": [ + "git", + "new-branch", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch refactor" + }, + { + "cmd": [ + "git", + "new-branch", + "feature", + "--upstream", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch feature" + }, { "cmd": [ "git", diff --git a/recipe_modules/git/example.expected/basic_hash.json b/recipe_modules/git/example.expected/basic_hash.json index e971c64e6..4641d453f 100644 --- a/recipe_modules/git/example.expected/basic_hash.json +++ b/recipe_modules/git/example.expected/basic_hash.json @@ -151,6 +151,32 @@ "cwd": "[SLAVE_BUILD]/src", "name": "git status cannot_fail_build" }, + { + "cmd": [ + "git", + "new-branch", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch refactor" + }, + { + "cmd": [ + "git", + "new-branch", + "feature", + "--upstream", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch feature" + }, { "cmd": [ "git", diff --git a/recipe_modules/git/example.expected/basic_ref.json b/recipe_modules/git/example.expected/basic_ref.json index 4a73951a1..d9d9b7941 100644 --- a/recipe_modules/git/example.expected/basic_ref.json +++ b/recipe_modules/git/example.expected/basic_ref.json @@ -152,6 +152,32 @@ "cwd": "[SLAVE_BUILD]/src", "name": "git status cannot_fail_build" }, + { + "cmd": [ + "git", + "new-branch", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch refactor" + }, + { + "cmd": [ + "git", + "new-branch", + "feature", + "--upstream", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch feature" + }, { "cmd": [ "git", diff --git a/recipe_modules/git/example.expected/basic_submodule_update_force.json b/recipe_modules/git/example.expected/basic_submodule_update_force.json index d5f2f28d2..6af758912 100644 --- a/recipe_modules/git/example.expected/basic_submodule_update_force.json +++ b/recipe_modules/git/example.expected/basic_submodule_update_force.json @@ -153,6 +153,32 @@ "cwd": "[SLAVE_BUILD]/src", "name": "git status cannot_fail_build" }, + { + "cmd": [ + "git", + "new-branch", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch refactor" + }, + { + "cmd": [ + "git", + "new-branch", + "feature", + "--upstream", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch feature" + }, { "cmd": [ "git", diff --git a/recipe_modules/git/example.expected/cannot_fail_build.json b/recipe_modules/git/example.expected/cannot_fail_build.json index 7386381e1..7db28983b 100644 --- a/recipe_modules/git/example.expected/cannot_fail_build.json +++ b/recipe_modules/git/example.expected/cannot_fail_build.json @@ -156,6 +156,32 @@ "@@@STEP_EXCEPTION@@@" ] }, + { + "cmd": [ + "git", + "new-branch", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch refactor" + }, + { + "cmd": [ + "git", + "new-branch", + "feature", + "--upstream", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch feature" + }, { "cmd": [ "git", diff --git a/recipe_modules/git/example.expected/cat-file_test.json b/recipe_modules/git/example.expected/cat-file_test.json index dd24905e9..94cac8532 100644 --- a/recipe_modules/git/example.expected/cat-file_test.json +++ b/recipe_modules/git/example.expected/cat-file_test.json @@ -152,6 +152,32 @@ "cwd": "[SLAVE_BUILD]/src", "name": "git status cannot_fail_build" }, + { + "cmd": [ + "git", + "new-branch", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch refactor" + }, + { + "cmd": [ + "git", + "new-branch", + "feature", + "--upstream", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch feature" + }, { "cmd": [ "git", diff --git a/recipe_modules/git/example.expected/count-objects_delta.json b/recipe_modules/git/example.expected/count-objects_delta.json index 82895bddd..fcb715177 100644 --- a/recipe_modules/git/example.expected/count-objects_delta.json +++ b/recipe_modules/git/example.expected/count-objects_delta.json @@ -225,6 +225,32 @@ "cwd": "[SLAVE_BUILD]/src", "name": "git status cannot_fail_build" }, + { + "cmd": [ + "git", + "new-branch", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch refactor" + }, + { + "cmd": [ + "git", + "new-branch", + "feature", + "--upstream", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch feature" + }, { "cmd": [ "git", diff --git a/recipe_modules/git/example.expected/count-objects_failed.json b/recipe_modules/git/example.expected/count-objects_failed.json index d7ddb067f..e65c8d270 100644 --- a/recipe_modules/git/example.expected/count-objects_failed.json +++ b/recipe_modules/git/example.expected/count-objects_failed.json @@ -156,6 +156,32 @@ "cwd": "[SLAVE_BUILD]/src", "name": "git status cannot_fail_build" }, + { + "cmd": [ + "git", + "new-branch", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch refactor" + }, + { + "cmd": [ + "git", + "new-branch", + "feature", + "--upstream", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch feature" + }, { "cmd": [ "git", diff --git a/recipe_modules/git/example.expected/count-objects_with_bad_output.json b/recipe_modules/git/example.expected/count-objects_with_bad_output.json index 9b176e860..23214b740 100644 --- a/recipe_modules/git/example.expected/count-objects_with_bad_output.json +++ b/recipe_modules/git/example.expected/count-objects_with_bad_output.json @@ -157,6 +157,32 @@ "cwd": "[SLAVE_BUILD]/src", "name": "git status cannot_fail_build" }, + { + "cmd": [ + "git", + "new-branch", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch refactor" + }, + { + "cmd": [ + "git", + "new-branch", + "feature", + "--upstream", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch feature" + }, { "cmd": [ "git", diff --git a/recipe_modules/git/example.expected/curl_trace_file.json b/recipe_modules/git/example.expected/curl_trace_file.json index ba561d873..f4ffdb9b0 100644 --- a/recipe_modules/git/example.expected/curl_trace_file.json +++ b/recipe_modules/git/example.expected/curl_trace_file.json @@ -154,6 +154,32 @@ "cwd": "[SLAVE_BUILD]/src", "name": "git status cannot_fail_build" }, + { + "cmd": [ + "git", + "new-branch", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch refactor" + }, + { + "cmd": [ + "git", + "new-branch", + "feature", + "--upstream", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch feature" + }, { "cmd": [ "git", diff --git a/recipe_modules/git/example.expected/git-cache-checkout.json b/recipe_modules/git/example.expected/git-cache-checkout.json index 068c33d8b..5dd47423d 100644 --- a/recipe_modules/git/example.expected/git-cache-checkout.json +++ b/recipe_modules/git/example.expected/git-cache-checkout.json @@ -199,6 +199,32 @@ "cwd": "[SLAVE_BUILD]/src", "name": "git status cannot_fail_build" }, + { + "cmd": [ + "git", + "new-branch", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch refactor" + }, + { + "cmd": [ + "git", + "new-branch", + "feature", + "--upstream", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch feature" + }, { "cmd": [ "git", diff --git a/recipe_modules/git/example.expected/platform_win.json b/recipe_modules/git/example.expected/platform_win.json index b12b3b0c6..27d89c49f 100644 --- a/recipe_modules/git/example.expected/platform_win.json +++ b/recipe_modules/git/example.expected/platform_win.json @@ -165,6 +165,32 @@ "cwd": "[SLAVE_BUILD]\\src", "name": "git status cannot_fail_build" }, + { + "cmd": [ + "RECIPE_PACKAGE_REPO[depot_tools]\\git.bat", + "new-branch", + "refactor" + ], + "cwd": "[SLAVE_BUILD]\\src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools];%(PATH)s" + }, + "name": "git new-branch refactor" + }, + { + "cmd": [ + "RECIPE_PACKAGE_REPO[depot_tools]\\git.bat", + "new-branch", + "feature", + "--upstream", + "refactor" + ], + "cwd": "[SLAVE_BUILD]\\src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools];%(PATH)s" + }, + "name": "git new-branch feature" + }, { "cmd": [ "RECIPE_PACKAGE_REPO[depot_tools]\\git.bat", diff --git a/recipe_modules/git/example.expected/rebase_failed.json b/recipe_modules/git/example.expected/rebase_failed.json index 82ff98064..d44b67d68 100644 --- a/recipe_modules/git/example.expected/rebase_failed.json +++ b/recipe_modules/git/example.expected/rebase_failed.json @@ -152,6 +152,32 @@ "cwd": "[SLAVE_BUILD]/src", "name": "git status cannot_fail_build" }, + { + "cmd": [ + "git", + "new-branch", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch refactor" + }, + { + "cmd": [ + "git", + "new-branch", + "feature", + "--upstream", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch feature" + }, { "cmd": [ "git", diff --git a/recipe_modules/git/example.expected/remote_not_origin.json b/recipe_modules/git/example.expected/remote_not_origin.json index 5132e1b4a..0514ebb70 100644 --- a/recipe_modules/git/example.expected/remote_not_origin.json +++ b/recipe_modules/git/example.expected/remote_not_origin.json @@ -154,6 +154,32 @@ "cwd": "[SLAVE_BUILD]/src", "name": "git status cannot_fail_build" }, + { + "cmd": [ + "git", + "new-branch", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch refactor" + }, + { + "cmd": [ + "git", + "new-branch", + "feature", + "--upstream", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch feature" + }, { "cmd": [ "git", diff --git a/recipe_modules/git/example.expected/set_got_revision.json b/recipe_modules/git/example.expected/set_got_revision.json index 685431f52..15dfd1c33 100644 --- a/recipe_modules/git/example.expected/set_got_revision.json +++ b/recipe_modules/git/example.expected/set_got_revision.json @@ -153,6 +153,32 @@ "cwd": "[SLAVE_BUILD]/src", "name": "git status cannot_fail_build" }, + { + "cmd": [ + "git", + "new-branch", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch refactor" + }, + { + "cmd": [ + "git", + "new-branch", + "feature", + "--upstream", + "refactor" + ], + "cwd": "[SLAVE_BUILD]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:%(PATH)s" + }, + "name": "git new-branch feature" + }, { "cmd": [ "git", diff --git a/recipe_modules/git/example.py b/recipe_modules/git/example.py index 484b7385b..8eeec89dd 100644 --- a/recipe_modules/git/example.py +++ b/recipe_modules/git/example.py @@ -67,6 +67,11 @@ def RunSteps(api): api.git('status', name='git status cannot_fail_build', can_fail_build=False) + # You should run git new-branch before you upload something with git cl. + api.git.new_branch('refactor') # Upstream is origin/master by default. + # And use upstream kwarg to set up different upstream for tracking. + api.git.new_branch('feature', upstream='refactor') + # You can use api.git.rebase to rebase the current branch onto another one api.git.rebase(name_prefix='my repo', branch='origin/master', dir_path=api.path['checkout'],