check-style: Allow deciding on individual suggestions with --rewrite
Currently, when the rewrite option is passed, the script does not give much choice on whether changes should be applied or not, it just does "git comit -a --amend". However, uncrustify is not always entirely right about the proposed style changes, or it might suggest changes in distant/unrelated bits in the changed functions. Thus the developer needs to be given some option. Change the approach of the --rewrite option, so that it first does "git add -p", so that individual changes may be decided upon, and after all the chunks were gone through, uses "git commit --squash" so that the changes may be reviewed before manually doing "git rebase --autosquash" to merge the changes. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2829>
This commit is contained in:
parent
d6062baef3
commit
a41c83be4f
@ -143,13 +143,21 @@ chunks = find_chunks(diff)
|
||||
changed = reformat_chunks(chunks, rewrite)
|
||||
|
||||
if dry_run is not True and rewrite is True:
|
||||
subprocess.run(["git", "commit", "--all", "--amend", "-C", "HEAD"], stdout=subprocess.DEVNULL)
|
||||
proc = subprocess.run(["git", "add", "-p"])
|
||||
if proc.returncode == 0:
|
||||
# Commit the added changes as a squash commit
|
||||
subprocess.run(
|
||||
["git", "commit", "--squash", "HEAD", "-C", "HEAD"],
|
||||
stdout=subprocess.DEVNULL)
|
||||
# Delete the unapplied changes
|
||||
subprocess.run(["git", "reset", "--hard"], stdout=subprocess.DEVNULL)
|
||||
os._exit(0)
|
||||
elif dry_run is True and changed is True:
|
||||
print(f"""
|
||||
Issue the following command in your local tree to apply the suggested changes:
|
||||
Issue the following commands in your local tree to apply the suggested changes:
|
||||
|
||||
$ git rebase {sha} --exec "./check-style.py -r"
|
||||
$ git rebase --autosquash {sha}
|
||||
""")
|
||||
os._exit(-1)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user