Skip to content

Commit

Permalink
[SPARK-9383][PROJECT-INFRA] PR merge script should reset back to prev…
Browse files Browse the repository at this point in the history
…ious branch when possible

This patch modifies our PR merge script to reset back to a named branch when restoring the original checkout upon exit. When the committer is originally checked out to a detached head, then they will be restored back to that same ref (the same as today's behavior).

This is a slightly updated version of apache#7569, with an extra fix to handle the detached head corner-case.

Author: Josh Rosen <joshrosen@databricks.com>

Closes apache#10709 from JoshRosen/SPARK-9383.
  • Loading branch information
JoshRosen committed Jan 13, 2016
1 parent 38148f7 commit 97e0c7c
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions dev/merge_spark_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,21 @@ def standardize_jira_ref(text):

return clean_text


def get_current_ref():
ref = run_cmd("git rev-parse --abbrev-ref HEAD").strip()
if ref == 'HEAD':
# The current ref is a detached HEAD, so grab its SHA.
return run_cmd("git rev-parse HEAD").strip()
else:
return ref


def main():
global original_head

os.chdir(SPARK_HOME)
original_head = run_cmd("git rev-parse HEAD")[:8]
original_head = get_current_ref()

branches = get_json("%s/branches" % GITHUB_API_BASE)
branch_names = filter(lambda x: x.startswith("branch-"), [x['name'] for x in branches])
Expand Down Expand Up @@ -449,5 +459,8 @@ def main():
(failure_count, test_count) = doctest.testmod()
if failure_count:
exit(-1)

main()
try:
main()
except:
clean_up()
raise

0 comments on commit 97e0c7c

Please sign in to comment.