chiark / gitweb /
git-debpush: avoid a pipefail problem in get_file_from_ref
authorSean Whitton <spwhitton@spwhitton.name>
Sat, 19 Oct 2019 17:33:10 +0000 (10:33 -0700)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 2 Feb 2020 16:35:04 +0000 (16:35 +0000)
`grep -q` exits as soon as it finds a matching line, potentially
sending a SIGPIPE to git-ls-tree.  We have pipefail turned on, so that
can make the whole pipeline exit nonzero, which is wrong when grep did
in fact find a match.

This solution is more readable than disabling pipefail just for this
line (as is done elsewhere in git-debpush).

Closes: #940588
Reported-by: Andrej Shadura <andrewsh@debian.org>
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
git-debpush

index c3b067dca4eff7feb0edab1812c33694f3e29e5e..2790560cf21658b5275bcd7d180db9909d696c59 100755 (executable)
@@ -59,8 +59,10 @@ badusage () {
 get_file_from_ref () {
     local path=$1
 
+    # redirect to /dev/null instead of using `grep -Eq` to avoid grep
+    # SIGPIPEing git-ls-tree
     if git ls-tree --name-only -r "$branch" \
-            | grep -Eq "^$path$"; then
+            | grep -E "^$path$" >/dev/null; then
         git cat-file blob $branch:$path
     fi
 }