From 1202a14d0250153bae2fb65bb340ae757d677b15 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Wed, 7 Dec 2022 12:09:25 +0100 Subject: 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. --- check-style.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'check-style.py') diff --git a/check-style.py b/check-style.py index c68927241..5ffa18f00 100755 --- a/check-style.py +++ b/check-style.py @@ -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) -- cgit v1.2.1