contrib: nfs: update to 4.0.0
[vlc.git] / extras / misc / cherry-test.sh
blob892350b1e635a4b2e09cb40a64fa5daf420ea2be
1 #!/bin/sh
3 usage()
5 cat << EOF
6 usage: $0 <original_branch> [commit_range]
8 Check that cherry pick commits are properly formatted/documented.
9 Differing patches are put in patches-new/ and patches-orig/
11 original_branch: the branch where the cherry-picked commits come from
12 commit_range : the commits to check (origin/master..HEAD if not specified)
14 - edits are marked as
15 (cherry picked from commit <hash>) (edited)
16 edited:
18 - rebases (unmodified code) are marked as
19 (cherry picked from commit <hash>) (rebased)
20 rebased:
21 EOF
24 if test -z "$1"; then
25 echo "Missing original branch"
26 usage
27 exit 1
29 ORIGINAL_BRANCH=$1
31 if test -n "$2"; then
32 COMMIT_RANGE=$2
33 else
34 COMMIT_RANGE="origin/master..HEAD"
37 CHERY_PICK_DETECT="cherry picked from commit "
39 NOT_CHERRY_PICKED=`git log --invert-grep --grep "$CHERY_PICK_DETECT" --pretty=%h $COMMIT_RANGE`
40 if test -n "$NOT_CHERRY_PICKED"; then
41 echo "ERROR: some commits are not cherry-picked:"
42 git log --invert-grep --grep "$CHERY_PICK_DETECT" --pretty=oneline $COMMIT_RANGE
43 exit 1
46 CHERRY_PICKED=`git log --grep "$CHERY_PICK_DETECT" --pretty=%H $COMMIT_RANGE`
47 mkdir -p patches-new
48 mkdir -p patches-orig
50 EXIT_CODE=0
51 for l in $CHERRY_PICKED; do
52 GIT_LOG=`git log -n 1 $l~1..$l`
54 h=`echo "$GIT_LOG" | grep "$CHERY_PICK_DETECT" | sed -e "s/cherry picked from commit//" -e "s/Edited and //" -e "s/(//" | cut -c6-45`
56 # Check that the cherry picked hash exist in the original branch
57 HASH_EXISTS=`git merge-base --is-ancestor $h $ORIGINAL_BRANCH 2> /dev/null || echo FAIL`
58 if test -n "$HASH_EXISTS"; then
59 echo "Invalid Hash for:"
60 git log -n 1 $l
61 exit 1
64 # Check the cherry picked commit has a Signed Off mark
65 SIGNED_OFF=`echo "$GIT_LOG" | grep "Signed-off-by: "`
66 if test -z "$SIGNED_OFF"; then
67 echo "Missing signed off for:"
68 git log -n 1 $l
71 IS_MARKED_REBASED=`echo "$GIT_LOG" | grep "(cherry picked from commit $h) (rebased)"`
72 IS_MARKED_EDITED=`echo "$GIT_LOG" | grep "(cherry picked from commit $h) (edited)"`
74 git diff --no-color --minimal --ignore-all-space $l~1..$l | sed -e "/index /d" -e "s/@@ .*/@@/" > patches-new/$h.diff
75 git diff --no-color --minimal --ignore-all-space $h~1..$h | sed -e "/index /d" -e "s/@@ .*/@@/" > patches-orig/$h.diff
76 PATCH_DIFF=`diff -t -w patches-new/$h.diff patches-orig/$h.diff | sed -e '/^> --- /d' -e '/^> +++ /d' -e '/^---/d' -e '/^> @@/d' -e '/^< @@/d' -e '/^[0-9]\+/d'`
77 if test -z "$PATCH_DIFF"; then
78 if test -n "$IS_MARKED_EDITED"; then
79 echo "Incorrectly marked edited: $(git log $l~1..$l --oneline)"
80 EXIT_CODE=1
82 if test -n "$IS_MARKED_REBASED"; then
83 echo "Incorrectly marked rebased: $(git log $l~1..$l --oneline)"
84 EXIT_CODE=1
86 rm -rf patches-new/$h.diff patches-orig/$h.diff
87 continue
90 PATCH_DIFF2=`echo "$PATCH_DIFF" | sed -e "/\(> -\|> +\| diff \)/!d" | sed -e "/> +$/d" -e "/> -$/d"`
92 if test -n "$IS_MARKED_REBASED"; then
93 if test -n "$PATCH_DIFF2"; then
94 echo "Edit marked as rebase: $(git log $l~1..$l)"
95 EXIT_CODE=1
96 continue
99 IS_EXPLAINED=`echo "$GIT_LOG" | grep "rebased:"`
100 if test -z "$IS_EXPLAINED"; then
101 echo "Unexplained rebase: $(git log $l~1..$l)"
102 EXIT_CODE=1
103 else
104 rm -rf patches-new/$h.diff patches-orig/$h.diff
106 else
107 if test -z "$PATCH_DIFF2"; then
108 echo "Rebase marked as edit: $(git log $l~1..$l)"
109 EXIT_CODE=1
110 continue
113 if test -z "$IS_MARKED_EDITED"; then
114 echo "Unmarked edit: $(git log $l~1..$l)"
115 EXIT_CODE=1
116 else
117 IS_EXPLAINED=`echo "$GIT_LOG" | grep "edited:"`
118 if test -z "$IS_EXPLAINED"; then
119 echo "Unexplained edit: $(git log $l~1..$l)"
120 EXIT_CODE=1
121 else
122 rm -rf patches-new/$h.diff patches-orig/$h.diff
126 done
128 exit $EXIT_CODE