diff options
author | Luis Hector Chavez <lhchavez@google.com> | 2016-11-30 17:07:05 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-11-30 17:07:05 +0000 |
commit | 55456e9f5802c5322788bdbc15705f53b26b4c45 (patch) | |
tree | f30e423be69544b353f9c115da8b862bb9551600 | |
parent | 413eadc25bb8cf66fc981496f41798736d0c61fd (diff) | |
parent | 1265b558b74f18572411d3233578701b336ed1d3 (diff) | |
download | repohooks-55456e9f5802c5322788bdbc15705f53b26b4c45.tar.gz |
Add more environment variables am: e9db4ebaf5 am: f6ce62d673
am: 1265b558b7
Change-Id: I61152477ae2fdf01201b136e7dcfab8711da64fb
-rw-r--r-- | README.md | 9 | ||||
-rwxr-xr-x | pre-upload.py | 5 | ||||
-rw-r--r-- | rh/git.py | 15 |
3 files changed, 26 insertions, 3 deletions
@@ -82,8 +82,13 @@ A few environment variables are set so scripts don't need to discover things. e.g. `platform/tools/repohooks` * `REPO_PATH`: The path to the project relative to the root. e.g. `tools/repohooks` -* `REPO_REMOTE`: The remote git URL. - e.g. `https://android.googlesource.com/platform/tools/repohooks` +* `REPO_REMOTE`: The name of the git remote. + e.g. `aosp`. +* `REPO_LREV`: The name of the remote revision, translated to a local tracking + branch. This is typically latest commit in the remote-tracking branch. + e.g. `ec044d3e9b608ce275f02092f86810a3ba13834e` +* `REPO_RREV`: The remote revision. + e.g. `master` * `PREUPLOAD_COMMIT`: The commit that is currently being checked. e.g. `1f89dce0468448fa36f632d2fc52175cd6940a91` diff --git a/pre-upload.py b/pre-upload.py index f15a9b7..447b8bf 100755 --- a/pre-upload.py +++ b/pre-upload.py @@ -205,14 +205,17 @@ def _run_project_hooks(project_name, proj_dir=None, # Set up the environment like repo would with the forall command. try: remote = rh.git.get_upstream_remote() + upstream_branch = rh.git.get_upstream_branch() except rh.utils.RunCommandError as e: print('upstream remote cannot be found: %s' % (e,), file=sys.stderr) print('Did you run repo start?', file=sys.stderr) sys.exit(1) os.environ.update({ - 'REPO_PROJECT': project_name, + 'REPO_LREV': rh.git.get_commit_for_ref(upstream_branch), 'REPO_PATH': proj_dir, + 'REPO_PROJECT': project_name, 'REPO_REMOTE': remote, + 'REPO_RREV': rh.git.get_remote_revision(upstream_branch, remote), }) output = Output(project_name, len(hooks)) @@ -70,6 +70,21 @@ def get_upstream_branch(): return full_upstream.replace('heads', 'remotes/' + remote) +def get_commit_for_ref(ref): + """Returns the latest commit for this ref.""" + cmd = ['git', 'rev-parse', ref] + result = rh.utils.run_command(cmd, capture_output=True) + return result.output.strip() + + +def get_remote_revision(ref, remote): + """Returns the remote revision for this ref.""" + prefix = 'refs/remotes/%s/' % remote + if ref.startswith(prefix): + return ref[len(prefix):] + return ref + + def get_patch(commit): """Returns the patch for this commit.""" cmd = ['git', 'format-patch', '--stdout', '-1', commit] |