base unapprove on: git diff target...source | git patch-id

Issue #15 resolved
Julius Davies [bit-booster.com] created an issue

If we base the unapprove decision on the output of "git diff target...source | git patch-id", then all spurious unapproves should be eliminated.

Note: the triple-dot notation is key to keeping the diff stable, since git diff A...B is the same as git diff $(git merge-base A B) B. And it still works with syncing merges (e.g., git pull. Or: git checkout B; git merge A) since the point of those is to update the merge-base, while leaving the diff alone.

Here are some sample scenarios:

0. Starting state (based on http://admin@localhost:7990/bitbucket/scm/project_1/rep_1.git after "atlas-clean" and "atlas-run").

$ git checkout basic_branching --
$ git show -s --pretty="%h"  master basic_branching -- | xargs
0a943a2 d6edcbf
$ git diff master...basic_branching | git patch-id --stable
4940de4d9aa8d4e4d57450adaa146fcfd104e13c 

1. Master advances (to 2bd602d). Patch-id unchanged.

$ git checkout master
$ echo "1" >> file; git add file; git commit -m 'file edited'
$ git show -s --pretty="%h"  master basic_branching -- | xargs
2bd602d d6edcbf
$ git diff master...basic_branching | git patch-id --stable
4940de4d9aa8d4e4d57450adaa146fcfd104e13c 

2. basic_branching does a "git merge master" (to bd423cc). Patch-id unchanged.

$ git checkout basic_branching --
$ git merge master -m 'merge'
$ git show -s --pretty="%h"  master basic_branching -- | xargs
2bd602d bd423cc
$ git diff master...basic_branching | git patch-id --stable
4940de4d9aa8d4e4d57450adaa146fcfd104e13c

3. basic_branching receives an empty commit (to 9a7527f). Patch-id unchanged.

$ git commit -m 'empty' --allow-empty
$ git show -s --pretty="%h"  master basic_branching -- | xargs
2bd602d 9a7527f
$ git diff master...basic_branching | git patch-id --stable
4940de4d9aa8d4e4d57450adaa146fcfd104e13c

4. basic_branching does a rebase against master (becomes ffeb777). Patch-id unchanged.

$ git rebase master
$ git show -s --pretty="%h"  master basic_branching -- | xargs
2bd602d ffeb777
$ git diff master...basic_branching | git patch-id --stable
4940de4d9aa8d4e4d57450adaa146fcfd104e13c 

5. basic_branching squashes itself (becomes 3e94e36). Patch-id unchanged.

$ git checkout -b temp master
$ git merge --squash basic_branching
$ git commit
$ git branch --force basic_branching
$ git checkout basic_branching
$ git branch -D temp
$ git show -s --pretty="%h"  master basic_branching -- | xargs
2bd602d 3e94e36
$ git diff master...basic_branching | git patch-id --stable
4940de4d9aa8d4e4d57450adaa146fcfd104e13c 

6. basic_branching receives a material edit (to fb700e4). Patch-id changes!

$ echo "2" >> file; git add file; git commit -m 'file edited'
$ git show -s --pretty="%h"  master basic_branching -- | xargs
2bd602d fb700e4
$ git diff master...basic_branching | git patch-id --stable
b3e731b3a9b450b71c9212843538a1d7774ffc33 

7. basic_branching decides to "git revert" that change (to b933fc3). Patch-id reverts back to previous!

$ git revert HEAD
$ git show -s --pretty="%h"  master basic_branching -- | xargs
2bd602d b933fc3
$ git diff master...basic_branching | git patch-id --stable
4940de4d9aa8d4e4d57450adaa146fcfd104e13c 

I like this because if "basic_branching" was pushed just before the "git revert" the unapproval would trigger, but not if it was only pushed after the revert! (Obviously the unapproval would trigger twice if the branch was pushed both immediately before and after the revert.)

Scenario 8. git commit --amend to adjust a bad commit message.

Since git commit --allow-empty worked, I'm going to leave this one as an exercise for the reader. :-p

Comments (7)

  1. Julius Davies [bit-booster.com] reporter

    Scenario 8. git commit --amend to adjust a bad commit message. :-)

  2. Log in to comment