aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuis Hector Chavez <lhchavez@google.com>2016-11-30 17:01:36 +0000
committerandroid-build-merger <android-build-merger@google.com>2016-11-30 17:01:36 +0000
commit1265b558b74f18572411d3233578701b336ed1d3 (patch)
treef30e423be69544b353f9c115da8b862bb9551600
parentbee1fea3b2d821c01d81f576dd0e54b7d77a8d51 (diff)
parentf6ce62d673ebcca99719422380e94f68ce085a6b (diff)
downloadrepohooks-1265b558b74f18572411d3233578701b336ed1d3.tar.gz
Add more environment variables am: e9db4ebaf5
am: f6ce62d673 Change-Id: I48baaccd5d7178624561f6c54461ee8c95c11de2
-rw-r--r--README.md9
-rwxr-xr-xpre-upload.py5
-rw-r--r--rh/git.py15
3 files changed, 26 insertions, 3 deletions
diff --git a/README.md b/README.md
index e011d8a..fd3b97f 100644
--- a/README.md
+++ b/README.md
@@ -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))
diff --git a/rh/git.py b/rh/git.py
index c78eb3b..8cf2557 100644
--- a/rh/git.py
+++ b/rh/git.py
@@ -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]