mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
Merge #5903: feat: enable optional rebasing as part of github-merge.py script
f44c07f75d
feat: enable optional rebasing as part of github-merge.py script (pasta)
Pull request description:
## Issue being fixed or feature implemented
this will allow us to rebase the PR before merging as we do now; and then right after merge it into develop and push
note we can not simply rebase locally before merging as we would then violate the "all changes must be done through PR rule"
When rebasing locally; we also check the range-diff (should be all >'s indicating a commit being pulled in from the rebase and ='s indicating the commits are the same as the base PR. This ensures that when we force push we will not invalidate previously created reviews.
## What was done?
## How Has This Been Tested?
Rebased and Merged PR with it
## Breaking Changes
None
## Checklist:
_Go over all the following points, and put an `x` in all the boxes that apply._
- [x] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have added or updated relevant unit/integration/functional/e2e tests
- [ ] I have made corresponding changes to the documentation
- [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_
Top commit has no ACKs.
Tree-SHA512: 020be8f2451d8945ca10b6388d8bffea0736c43eb410b3f0d9cb5dc07eefd661d8d8c9f0a749ed0accd8288c2fb161f379408022eb2590bd50fa55c0145e072c
This commit is contained in:
commit
7ab37529e7
@ -249,6 +249,10 @@ def main():
|
||||
sys.exit(1)
|
||||
title = info['title'].strip()
|
||||
body = info['body'].strip()
|
||||
# Extract forker's repo SSH URL and branch name
|
||||
forker_repo_ssh_url = info['head']['repo']['ssh_url']
|
||||
target_branch = info['head']['ref']
|
||||
|
||||
# precedence order for destination branch argument:
|
||||
# - command line argument
|
||||
# - githubmerge.branch setting
|
||||
@ -274,6 +278,57 @@ def main():
|
||||
except subprocess.CalledProcessError:
|
||||
print("ERROR: Cannot find pull request #%s or branch %s on %s." % (pull,branch,host_repo), file=stderr)
|
||||
sys.exit(3)
|
||||
|
||||
# Ask the user if they want to rebase the branch
|
||||
rebase_reply = ask_prompt("Would you like to rebase the branch? Type 'yes' to rebase or anything else to continue without rebasing.").lower()
|
||||
if rebase_reply == 'yes':
|
||||
try:
|
||||
subprocess.check_call([GIT, 'checkout', head_branch])
|
||||
# Capture the commit hash of head_branch before the rebase
|
||||
head_commit_before_rebase = subprocess.check_output([GIT, 'rev-parse', 'HEAD']).strip().decode('utf-8')
|
||||
# Identify the base commit before the rebase
|
||||
base_commit_before_rebase = subprocess.check_output([GIT, 'merge-base', base_branch, head_branch]).strip().decode('utf-8')
|
||||
|
||||
# Perform the rebase
|
||||
subprocess.check_call([GIT, 'rebase', base_branch])
|
||||
|
||||
# Identify the new head commit after rebase
|
||||
new_head_commit = subprocess.check_output([GIT, 'rev-parse', 'HEAD']).strip().decode('utf-8')
|
||||
|
||||
# Using git range-diff to compare changes before and after the rebase
|
||||
range_diff_output = subprocess.check_output([GIT, 'range-diff', base_commit_before_rebase + '..' + head_commit_before_rebase, base_commit_before_rebase + '..' + new_head_commit], stderr=subprocess.STDOUT)
|
||||
|
||||
# Check the range-diff output for significant changes
|
||||
if not range_diff_output:
|
||||
print("No significant changes detected by git range-diff.")
|
||||
else:
|
||||
print("Significant changes detected by git range-diff. Please review the output below:")
|
||||
print(range_diff_output.decode('utf-8'))
|
||||
try:
|
||||
subprocess.check_call([GIT,'log','--graph','--topo-order','--pretty=format:'+COMMIT_FORMAT])
|
||||
except:
|
||||
pass
|
||||
review_reply = ask_prompt("Do you want to continue with force push? Type 'yes' to continue or anything else to abort.").lower()
|
||||
if review_reply != 'yes':
|
||||
sys.exit(5)
|
||||
|
||||
# If no significant changes or user accepts changes, force push the rebased branch to the PR branch
|
||||
# subprocess.check_call([GIT, 'push', host_repo, head_branch + ':' + 'pull/' + pull + '/head'])
|
||||
try:
|
||||
subprocess.check_call([GIT, 'push', '--force', forker_repo_ssh_url, f'HEAD:refs/heads/{target_branch}'])
|
||||
print(f"Force pushed to {target_branch} on {forker_repo_ssh_url}.")
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Error while pushing: {str(e)}", file=stderr)
|
||||
sys.exit(1)
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
print("ERROR: ", e.output.decode('utf-8'))
|
||||
sys.exit(4)
|
||||
|
||||
subprocess.check_call([GIT,'checkout','-q',base_branch])
|
||||
subprocess.call([GIT,'branch','-q','-D',local_merge_branch], stderr=devnull)
|
||||
subprocess.check_call([GIT,'checkout','-q','-b',local_merge_branch])
|
||||
|
||||
try:
|
||||
subprocess.check_call([GIT,'log','-q','-1','refs/heads/'+head_branch], stdout=devnull, stderr=stdout)
|
||||
head_commit = subprocess.check_output([GIT,'log','-1','--pretty=format:%H',head_branch]).decode('utf-8')
|
||||
|
Loading…
Reference in New Issue
Block a user