Skip to content
Snippets Groups Projects
Commit 685fbe4b authored by Bastien Montagne's avatar Bastien Montagne
Browse files

clang-format branch merge/rebase helper: add support for non-master base branch.

In some cases one has a hierarchy of branches built one on top of the other,
this option allows to merge or rebase from another branch than master.
parent 3b7f58fb
No related branches found
No related tags found
No related merge requests found
...@@ -12,18 +12,27 @@ def get_string(cmd): ...@@ -12,18 +12,27 @@ def get_string(cmd):
# Parse arguments. # Parse arguments.
mode = None mode = None
if len(sys.argv) == 2: base_branch = 'master'
if len(sys.argv) >= 2:
if sys.argv[1] == '--rebase': if sys.argv[1] == '--rebase':
mode = 'rebase' mode = 'rebase'
elif sys.argv[1] == '--merge': elif sys.argv[1] == '--merge':
mode = 'merge' mode = 'merge'
if len(sys.argv) == 4:
if sys.argv[2] == '--base_branch':
base_branch = sys.argv[3]
if mode == None: if mode == None:
print("Merge or rebase Blender master into a branch in 3 steps,") print("Merge or rebase Blender master (or another base branch) into a branch in 3 steps,")
print("to automatically merge clang-format changes.") print("to automatically merge clang-format changes.")
print("") print("")
print(" --rebase Perform equivalent of 'git rebase master'") print(" --rebase Perform equivalent of 'git rebase master'")
print(" --merge Perform equivalent of 'git merge master'") print(" --merge Perform equivalent of 'git merge master'")
print("")
print("Optional arguments:")
print(" --base_branch <branch name> Use given branch instead of master")
print(" (assuming that base branch has already been updated")
print(" and has the initial clang-format commit).")
sys.exit(0) sys.exit(0)
# Verify we are in the right directory. # Verify we are in the right directory.
...@@ -53,7 +62,7 @@ if mode == 'rebase': ...@@ -53,7 +62,7 @@ if mode == 'rebase':
mode_cmd = 'rebase' mode_cmd = 'rebase'
else: else:
branch = get_string(['git', 'rev-parse', '--abbrev-ref', 'HEAD']) branch = get_string(['git', 'rev-parse', '--abbrev-ref', 'HEAD'])
mode_cmd = 'merge --no-edit -m "Merge \'master\' into \'' + branch + '\'"'; mode_cmd = 'merge --no-edit -m "Merge \'' + base_branch + '\' into \'' + branch + '\'"';
# Rebase up to the clang-format commit. # Rebase up to the clang-format commit.
code = os.system('git merge-base --is-ancestor ' + pre_format_commit + ' HEAD') code = os.system('git merge-base --is-ancestor ' + pre_format_commit + ' HEAD')
...@@ -78,7 +87,7 @@ if code != 0: ...@@ -78,7 +87,7 @@ if code != 0:
os.system('git commit -m "Cleanup: apply clang format"') os.system('git commit -m "Cleanup: apply clang format"')
# Rebase remaning commits # Rebase remaning commits
code = os.system('git ' + mode_cmd + ' master') code = os.system('git ' + mode_cmd + ' ' + base_branch)
if code != 0: if code != 0:
print("BLENDER MERGE: resolve conflicts, complete " + mode + " and you're done") print("BLENDER MERGE: resolve conflicts, complete " + mode + " and you're done")
else: else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment