git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC/PATCH] Bisect: add special treatment for bangs passed to "bisect run".

From
Christian Couder <chriscool@tuxfamily.org>
Date
May 1, 2007, 09:31 UTC
Message-ID
<20070501113112.c4b32b55.chriscool@tuxfamily.org>
Something like:
 $ git bisect run ! grep string my_file
does not work right now, probably because '!' is a shell keyword.
(This simple script shows the problem:
 $ echo "#"\!"/bin/sh" > ./simple_test.sh
 $ echo "echo \"running:\" \"\$@\"" >> ./simple_test.sh
 $ echo "\"\$@\"" >> ./simple_test.sh
 $ chmod +x ./simple_test.sh
 $ ./simple_test.sh ! grep foo bar.txt
 running: ! grep foo bar.txt
 ./simple_test.sh: line 3: !: command not found
)

This patch tries to work around this problem by counting how many bangs are passed at the beginning of the "bisect run" argument list and adding them back when evaluating "$@".

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 git-bisect.sh               |   25 +++++++++++++++++++++++--
 t/t6030-bisect-porcelain.sh |    9 +++++++++
 2 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/git-bisect.sh b/git-bisect.sh
index 1cd4561..f4ce199 100755
--- a/git-bisect.sh
+++ b/git-bisect.sh
@@ -307,10 +307,31 @@ bisect_replay () {
 bisect_run () {
     bisect_next_check fail
 
+    # Count '!' because they need special code.
+    bang_count=0
+    while [ "$1" == '!' ]
+    do
+      bang_count=$(expr $bang_count + 1)
+      shift
+    done
+    test $bang_count -gt 0 && bang_modulo=$(expr $bang_count % 2)
+
+    # Bisect loop.
     while true
     do
-      echo "running $@"
-      "$@"
+      # Run the command/script passed as argument.
+      if [ $bang_count -eq 0 ]; then
+	  echo "running $@"
+	  "$@"
+      else
+	  if [ $bang_modulo -eq 0 ]; then
+	      echo "running ! ( ! $@ )"
+	      ! ( ! "$@" )
+	  else
+	      echo "running ! $@"
+	      ! "$@"
+	  fi
+      fi
       res=$?
 
       # Check for really bad run error.
diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh
index 30f6ade..56fd645 100755
--- a/t/t6030-bisect-porcelain.sh
+++ b/t/t6030-bisect-porcelain.sh
@@ -99,6 +99,15 @@ test_expect_success \
      grep "$HASH4 is first bad commit" my_bisect_log.txt &&
      git bisect reset'
 
+# We again want to automatically find the commit that
+# introduced "Ciao" into hello.
+test_expect_success \
+    '"git bisect run" with bang in argument' \
+    'git bisect start $HASH4 $HASH1 &&
+     git bisect run ! grep Ciao hello > my_bisect_log.txt &&
+     grep "$HASH4 is first bad commit" my_bisect_log.txt &&
+     git bisect reset'
+
 #
 #
 test_done
-- 
1.5.2.rc0.71.g4342-dirty
Next: Uwe Kleine-König
Message 1 of 2 in “Bisect: add special treatment for bangs passed to "bisect run".”
  1. Bisect: add special treatment for bangs passed to "bisect run".Christian Couder, May 1, 2007
  2. Uwe Kleine-KönigMay 1, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.