|
21 | 21 | set -u |
22 | 22 |
|
23 | 23 | # avoid [[ which is not POSIX sh. |
24 | | -if test "$#" != 1 ; then |
| 24 | +if test "$#" != 1; then |
25 | 25 | echo "$0 requires an argument." |
26 | 26 | exit 1 |
27 | 27 | fi |
28 | 28 |
|
29 | | -if test ! -f "$1" ; then |
| 29 | +if test ! -f "$1"; then |
30 | 30 | echo "file does not exist: $1" |
31 | 31 | exit 1 |
32 | 32 | fi |
33 | 33 |
|
34 | 34 | # Do not create a change id if requested |
35 | 35 | case "$(git config --get gerrit.createChangeId)" in |
36 | | - false) |
| 36 | +false) |
| 37 | + exit 0 |
| 38 | + ;; |
| 39 | +always) ;; |
| 40 | +*) |
| 41 | + # Do not create a change id for squash/fixup commits. |
| 42 | + if head -n1 "$1" | LC_ALL=C grep -q '^[a-z][a-z]*! '; then |
37 | 43 | exit 0 |
38 | | - ;; |
39 | | - always) |
40 | | - ;; |
41 | | - *) |
42 | | - # Do not create a change id for squash/fixup commits. |
43 | | - if head -n1 "$1" | LC_ALL=C grep -q '^[a-z][a-z]*! '; then |
44 | | - exit 0 |
45 | | - fi |
46 | | - ;; |
| 44 | + fi |
| 45 | + ;; |
47 | 46 | esac |
48 | 47 |
|
49 | | - |
50 | 48 | if git rev-parse --verify HEAD >/dev/null 2>&1; then |
51 | 49 | refhash="$(git rev-parse HEAD)" |
52 | 50 | else |
53 | 51 | refhash="$(git hash-object -t tree /dev/null)" |
54 | 52 | fi |
55 | 53 |
|
56 | | -random=$({ git var GIT_COMMITTER_IDENT ; echo "$refhash" ; cat "$1"; } | git hash-object --stdin) |
| 54 | +random=$({ |
| 55 | + git var GIT_COMMITTER_IDENT |
| 56 | + echo "$refhash" |
| 57 | + cat "$1" |
| 58 | +} | git hash-object --stdin) |
57 | 59 | dest="$1.tmp.${random}" |
58 | 60 |
|
59 | 61 | trap 'rm -f "$dest" "$dest-2"' EXIT |
60 | 62 |
|
61 | | -if ! sed -e '/>8/q' "$1" | git stripspace --strip-comments > "${dest}" ; then |
| 63 | +if ! sed -e '/>8/q' "$1" | git stripspace --strip-comments >"${dest}"; then |
62 | 64 | echo "cannot strip comments from $1" |
63 | 65 | exit 1 |
64 | 66 | fi |
65 | 67 |
|
66 | | -if test ! -s "${dest}" ; then |
| 68 | +if test ! -s "${dest}"; then |
67 | 69 | echo "file is empty: $1" |
68 | 70 | exit 1 |
69 | 71 | fi |
70 | 72 |
|
71 | 73 | reviewurl="$(git config --get gerrit.reviewUrl)" |
72 | | -if test -n "${reviewurl}" ; then |
| 74 | +if test -n "${reviewurl}"; then |
73 | 75 | token="Link" |
74 | 76 | value="${reviewurl%/}/id/I$random" |
75 | 77 | pattern=".*/id/I[0-9a-f]\{40\}" |
|
79 | 81 | pattern=".*" |
80 | 82 | fi |
81 | 83 |
|
82 | | -if git interpret-trailers --no-divider --parse < "$1" | grep -q "^$token: $pattern$" ; then |
| 84 | +if git interpret-trailers --no-divider --parse <"$1" | grep -q "^$token: $pattern$"; then |
83 | 85 | exit 0 |
84 | 86 | fi |
85 | 87 |
|
86 | 88 | # There must be a Signed-off-by trailer for the code below to work. Insert a |
87 | 89 | # sentinel at the end to make sure there is one. |
88 | 90 | # Avoid the --in-place option which only appeared in Git 2.8 |
89 | 91 | if ! git interpret-trailers \ |
90 | | - --no-divider \ |
91 | | - --trailer "Signed-off-by: SENTINEL" < "$1" > "$dest-2" ; then |
| 92 | + --no-divider \ |
| 93 | + --trailer "Signed-off-by: SENTINEL" <"$1" >"$dest-2"; then |
92 | 94 | echo "cannot insert Signed-off-by sentinel line in $1" |
93 | 95 | exit 1 |
94 | 96 | fi |
|
99 | 101 | # Avoid the --in-place option which only appeared in Git 2.8 |
100 | 102 | # Avoid the --where option which only appeared in Git 2.15 |
101 | 103 | if ! git -c trailer.where=before interpret-trailers \ |
102 | | - --no-divider \ |
103 | | - --trailer "Signed-off-by: $token: $value" < "$dest-2" | |
104 | | - sed -e "s/^Signed-off-by: \($token: \)/\1/" \ |
105 | | - -e "/^Signed-off-by: SENTINEL/d" > "$dest" ; then |
| 104 | + --no-divider \ |
| 105 | + --trailer "Signed-off-by: $token: $value" <"$dest-2" | |
| 106 | + sed -e "s/^Signed-off-by: \($token: \)/\1/" \ |
| 107 | + -e "/^Signed-off-by: SENTINEL/d" >"$dest"; then |
106 | 108 | echo "cannot insert $token line in $1" |
107 | 109 | exit 1 |
108 | 110 | fi |
109 | 111 |
|
110 | | -if ! mv "${dest}" "$1" ; then |
| 112 | +if ! mv "${dest}" "$1"; then |
111 | 113 | echo "cannot mv ${dest} to $1" |
112 | 114 | exit 1 |
113 | 115 | fi |
0 commit comments