If you run something like "guilt header '.*'" the command would crash,
because the grep comand that tries to ensure that the patch exist
would detect a match, but the later code expected the match to be

Fixed by comparing exact strings.

And as a creeping feature "guilt header" will now try to use the
supplied patch name as an unachored regexp if no exact match was
found.  If the regexp yields a unique match, it is used; if more than
one patch matches, the names of all patches are listed and the command
fails.  (Exercise left to the reader: generalized this so that "guilt
push" also accepts a unique regular expression.)

Signed-off-by: Per Cederqvist <ced...@opera.com>
 guilt-header | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/guilt-header b/guilt-header
index 41e00cc..4701b31 100755
--- a/guilt-header
+++ b/guilt-header
@@ -45,10 +45,32 @@ esac
 [ -z "$patch" ] && die "No patches applied."
 # check that patch exists in the series
-ret=`get_full_series | grep -e "^$patch\$" | wc -l`
-if [ $ret -eq 0 ]; then
-       die "Patch $patch is not in the series"
+full_series=`get_tmp_file series`
+get_full_series > "$full_series"
+while read x; do
+       if [ "$x" = "$patch" ]; then
+               found_patch="$patch"
+               break
+       fi
+done < "$full_series"
+if [ -z "$found_patch" ]; then
+       TMP_MATCHES=`get_tmp_file series`
+       grep "$patch" < "$full_series" > "$TMP_MATCHES"
+       nr=`wc -l < $TMP_MATCHES`
+       if [ $nr -gt 1 ]; then
+               echo "$patch does not uniquely identify a patch. Did you mean 
any of these?" >&2
+               sed 's/^/  /' "$TMP_MATCHES" >&2
+               rm -f "$TMP_MATCHES"
+               exit 1
+       elif [ $nr -eq 0 ]; then
+               rm -f "$TMP_MATCHES"
+               die "Patch $patch is not in the series"
+       fi
+       found_patch=`cat $TMP_MATCHES`
+       rm -f "$TMP_MATCHES"
 # FIXME: warn if we're editing an applied patch

To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to