diff --git a/recipes/README.recipes.md b/recipes/README.recipes.md index 2360e6300..7ac453570 100644 --- a/recipes/README.recipes.md +++ b/recipes/README.recipes.md @@ -401,7 +401,7 @@ Returns: Return a git command step. -— **def [bundle\_create](/recipes/recipe_modules/git/api.py#370)(self, bundle_path, rev_list_args=None, \*\*kwargs):** +— **def [bundle\_create](/recipes/recipe_modules/git/api.py#374)(self, bundle_path, rev_list_args=None, \*\*kwargs):** Run 'git bundle create' on a Git repository. @@ -415,7 +415,7 @@ Args: Outputs the contents of a file at a given revision. -— **def [checkout](/recipes/recipe_modules/git/api.py#110)(self, url, ref=None, dir_path=None, recursive=False, submodules=True, submodule_update_force=False, keep_paths=None, step_suffix=None, curl_trace_file=None, can_fail_build=True, set_got_revision=False, remote_name=None, display_fetch_size=None, file_name=None, submodule_update_recursive=True, use_git_cache=False, progress=True):** +— **def [checkout](/recipes/recipe_modules/git/api.py#110)(self, url, ref=None, dir_path=None, recursive=False, submodules=True, submodule_update_force=False, keep_paths=None, step_suffix=None, curl_trace_file=None, can_fail_build=True, set_got_revision=False, remote_name=None, display_fetch_size=None, file_name=None, submodule_update_recursive=True, use_git_cache=False, progress=True, tags=False):** Performs a full git checkout and returns sha1 of checked out revision. @@ -449,11 +449,12 @@ Args: "git fetch origin" or "git push origin". * arbitrary refs such refs/whatever/not-fetched-by-default-to-cache progress (bool): wether to show progress for fetch or not + tags (bool): Also fetch tags. Returns: If the checkout was successful, this returns the commit hash of the checked-out-repo. Otherwise this returns None. -— **def [config\_get](/recipes/recipe_modules/git/api.py#343)(self, prop_name, \*\*kwargs):** +— **def [config\_get](/recipes/recipe_modules/git/api.py#347)(self, prop_name, \*\*kwargs):** Returns: (str) The Git config output, or None if no output was generated. @@ -478,7 +479,7 @@ Returns: Fetches all tags from the remote. -— **def [get\_remote\_url](/recipes/recipe_modules/git/api.py#360)(self, remote_name=None, \*\*kwargs):** +— **def [get\_remote\_url](/recipes/recipe_modules/git/api.py#364)(self, remote_name=None, \*\*kwargs):** Returns: (str) The URL of the remote Git repository, or None. @@ -486,11 +487,11 @@ Args: remote_name: (str) The name of the remote to query, defaults to 'origin'. kwargs: Forwarded to '__call__'. -— **def [get\_timestamp](/recipes/recipe_modules/git/api.py#315)(self, commit='HEAD', test_data=None, \*\*kwargs):** +— **def [get\_timestamp](/recipes/recipe_modules/git/api.py#319)(self, commit='HEAD', test_data=None, \*\*kwargs):** Find and return the timestamp of the given commit. -— **def [new\_branch](/recipes/recipe_modules/git/api.py#383)(self, branch, name=None, upstream=None, \*\*kwargs):** +— **def [new\_branch](/recipes/recipe_modules/git/api.py#387)(self, branch, name=None, upstream=None, \*\*kwargs):** Runs git new-branch on a Git repository, to be used before git cl upload. @@ -500,7 +501,7 @@ Args: upstream (str): to origin/master. kwargs: Forwarded to '__call__'. -— **def [rebase](/recipes/recipe_modules/git/api.py#324)(self, name_prefix, branch, dir_path, remote_name=None, \*\*kwargs):** +— **def [rebase](/recipes/recipe_modules/git/api.py#328)(self, name_prefix, branch, dir_path, remote_name=None, \*\*kwargs):** Run rebase HEAD onto branch Args: diff --git a/recipes/recipe_modules/git/api.py b/recipes/recipe_modules/git/api.py index 9a9eee23d..adc250753 100644 --- a/recipes/recipe_modules/git/api.py +++ b/recipes/recipe_modules/git/api.py @@ -114,7 +114,7 @@ class GitApi(recipe_api.RecipeApi): set_got_revision=False, remote_name=None, display_fetch_size=None, file_name=None, submodule_update_recursive=True, - use_git_cache=False, progress=True): + use_git_cache=False, progress=True, tags=False): """Performs a full git checkout and returns sha1 of checked out revision. Args: @@ -147,6 +147,7 @@ class GitApi(recipe_api.RecipeApi): "git fetch origin" or "git push origin". * arbitrary refs such refs/whatever/not-fetched-by-default-to-cache progress (bool): wether to show progress for fetch or not + tags (bool): Also fetch tags. Returns: If the checkout was successful, this returns the commit hash of the checked-out-repo. Otherwise this returns None. @@ -248,6 +249,9 @@ class GitApi(recipe_api.RecipeApi): fetch_env['GIT_CURL_VERBOSE'] = '1' fetch_stderr = self.m.raw_io.output(leak_to=curl_trace_file) + if tags: + fetch_args.append('--tags') + fetch_step_name = 'git fetch%s' % step_suffix if display_fetch_size: count_objects_before_fetch = self.count_objects( diff --git a/recipes/recipe_modules/git/examples/full.expected/basic_tags.json b/recipes/recipe_modules/git/examples/full.expected/basic_tags.json new file mode 100644 index 000000000..38af3da9f --- /dev/null +++ b/recipes/recipe_modules/git/examples/full.expected/basic_tags.json @@ -0,0 +1,225 @@ +[ + { + "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", + "retry", + "fetch", + "origin", + "master", + "--recurse-submodules", + "--progress", + "--tags" + ], + "cwd": "[START_DIR]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:" + }, + "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", + "stdout": "/path/to/tmp/", + "~followup_annotations": [ + "@@@STEP_TEXT@
checked out 'deadbeef'
@@@" + ] + }, + { + "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", + "stdout": "/path/to/tmp/" + }, + { + "cmd": [ + "git", + "config", + "--get", + "remote.origin.url" + ], + "cwd": "[START_DIR]/src", + "infra_step": true, + "name": "git config remote.origin.url", + "stdout": "/path/to/tmp/", + "~followup_annotations": [ + "@@@STEP_TEXT@foo@@@" + ] + }, + { + "cmd": [ + "git", + "show", + "HEAD", + "--format=%at", + "-s" + ], + "cwd": "[START_DIR]/src", + "infra_step": true, + "name": "git show", + "stdout": "/path/to/tmp/" + }, + { + "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_PACKAGE_REPO[depot_tools]:" + }, + "infra_step": true, + "name": "git new-branch refactor" + }, + { + "cmd": [ + "git", + "new-branch", + "feature", + "--upstream", + "refactor" + ], + "cwd": "[START_DIR]/src", + "env": { + "PATH": "RECIPE_PACKAGE_REPO[depot_tools]:" + }, + "infra_step": true, + "name": "git new-branch feature" + }, + { + "cmd": [ + "git", + "rebase", + "origin/master" + ], + "cwd": "[START_DIR]/src", + "infra_step": true, + "name": "my repo rebase" + }, + { + "cmd": [ + "git", + "bundle", + "create", + "[START_DIR]/all.bundle", + "--all" + ], + "cwd": "[START_DIR]/src", + "infra_step": true, + "name": "git bundle" + }, + { + "name": "$result", + "recipe_result": null, + "status_code": 0 + } +] \ No newline at end of file diff --git a/recipes/recipe_modules/git/examples/full.py b/recipes/recipe_modules/git/examples/full.py index abdc6df03..c01712751 100644 --- a/recipes/recipe_modules/git/examples/full.py +++ b/recipes/recipe_modules/git/examples/full.py @@ -38,7 +38,8 @@ def RunSteps(api): display_fetch_size=api.properties.get('display_fetch_size'), file_name=api.properties.get('checkout_file_name'), submodule_update_recursive=submodule_update_recursive, - use_git_cache=api.properties.get('use_git_cache')) + use_git_cache=api.properties.get('use_git_cache'), + tags=api.properties.get('tags')) assert retVal == "deadbeef", ( "expected retVal to be %r but was %r" % ("deadbeef", retVal)) @@ -93,6 +94,7 @@ def RunSteps(api): def GenTests(api): yield api.test('basic') + yield api.test('basic_tags') + api.properties(tags=True) yield api.test('basic_ref') + api.properties(revision='refs/foo/bar') yield api.test('basic_branch') + api.properties(revision='refs/heads/testing') yield api.test('basic_hash') + api.properties(