{"thread":{"id":"32051","subject":"[PATCH] t9402: sed -i is not portable","startedAt":"2012-11-10T08:01:44Z","lastAt":"2012-11-10T08:01:44Z","messageCount":1,"participants":["Torsten Bögershausen"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"202739","messageId":"201211100901.45223.tboegi@web.de","threadId":"32051","inReplyTo":null,"subject":"[PATCH] t9402: sed -i is not portable","fromName":"Torsten Bögershausen","fromEmail":"tboegi@web.de","sentAt":"2012-11-10T08:01:44Z","receivedAt":"2012-11-10T08:01:44Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"The command line\nsed -i -e \"s/foo/bar/\" filename\nworks as expected under GNU/Linux:\nall \"foo\" are replaced by \"bar\" in the file \"filename\"\n\nsed on other systems like e.g. Mac OS X creates a backup file\ncalled filename-e, because the -i must be followed by a file name.\nAs the -i is not in POSIX either, avoid it completely\n\nImprove check_end_tree() and check_end_full_tree() to use test_cmp,\nand use the && between each line.\n\nSigned-off-by: Torsten Bögershausen <tboegi@web.de>\n---\nThis must be applied on peff/pu\n\n t/t9402-git-cvsserver-refs.sh | 44 ++++++++++++++++++++++---------------------\n 1 file changed, 23 insertions(+), 21 deletions(-)\n\ndiff --git a/t/t9402-git-cvsserver-refs.sh b/t/t9402-git-cvsserver-refs.sh\nindex 858ef0f..5138f14 100755\n--- a/t/t9402-git-cvsserver-refs.sh\n+++ b/t/t9402-git-cvsserver-refs.sh\n@@ -28,27 +28,26 @@ check_file() {\n }\n \n check_end_tree() {\n-    sandbox=\"$1\"\n-    expectCount=$(wc -l < \"$WORKDIR/check.list\")\n-    cvsCount=$(find \"$sandbox\" -name CVS -prune -o -type f -print | wc -l)\n-    test x\"$cvsCount\" = x\"$expectCount\"\n-    stat=$?\n-    echo \"check_end $sandbox : $stat cvs=$cvsCount expect=$expectCount\" \\\n-\t>> \"$WORKDIR/check.log\"\n-    return $stat\n+    sandbox=\"$1\" &&\n+    wc -l < \"$WORKDIR/check.list\" > expected &&\n+    find \"$sandbox\" -type f | grep -v \"/CVS\" > \"$WORKDIR/check.cvsCount\" &&\n+    wc -l < \"$WORKDIR/check.cvsCount\" >actual &&\n+    test_cmp expected actual &&\n+\t\trm expected actual &&\n+\t\tsort < \"$WORKDIR/check.list\" > expected &&\n+\t\tsort < \"$WORKDIR/check.cvsCount\" | sed -e \"s%cvswork/%%\" >actual &&\n+    test_cmp expected actual &&\n+\t\trm expected actual\n }\n \n check_end_full_tree() {\n-    sandbox=\"$1\"\n-    ver=\"$2\"\n-    expectCount=$(wc -l < \"$WORKDIR/check.list\")\n-    cvsCount=$(find \"$sandbox\" -name CVS -prune -o -type f -print | wc -l)\n-    gitCount=$(git ls-tree -r \"$2\" | wc -l)\n-    test x\"$cvsCount\" = x\"$expectCount\" -a x\"$gitCount\" = x\"$expectCount\"\n-    stat=$?\n-    echo \"check_end $sandbox : $stat cvs=$cvsCount git=$gitCount expect=$expectCount\" \\\n-\t>> \"$WORKDIR/check.log\"\n-    return $stat\n+    sandbox=\"$1\" &&\n+    sort < \"$WORKDIR/check.list\" >expected &&\n+    find \"$sandbox\" -name CVS -prune -o -type f -print | sed -e \"s%$sandbox/%%\" | sort >act1 &&\n+\t\ttest_cmp expected act1 &&\n+    git ls-tree -r \"$2\" | sed -e \"s/^.*blob [0-9a-fA-F]*[\t ]*//\" | sort > act2 &&\n+\t\ttest_cmp expected act2 &&\n+    rm expected act1 act2\n }\n \n #########\n@@ -155,7 +154,8 @@ test_expect_success 'cvs co b1 [cvswork3]' '\n \n test_expect_success 'edit cvswork3 and save diff' '\n     ( cd cvswork3 &&\n-      sed -i -e \"s/line1/line1 - data/\" adir/afile &&\n+      sed -e \"s/line1/line1 - data/\" adir/afile >adir/afileNEW &&\n+\t\t\tmv -f adir/afileNEW adir/afile &&\n       echo \"afile5\" > adir/afile5 &&\n       rm t2 &&\n       cvs -f add adir/afile5 &&\n@@ -168,7 +168,8 @@ test_expect_success 'setup v1.2 on b1' '\n     git checkout b1 &&\n     echo \"new v1.2\" > t3 &&\n     rm t2 &&\n-    sed -i -e \"s/line3/line3 - more data/\" adir/afile &&\n+    sed -e \"s/line3/line3 - more data/\" adir/afile >adir/afileNEW &&\n+\t\tmv -f adir/afileNEW adir/afile &&\n     rm adir/a2file &&\n     echo \"a3file\" >> adir/a3file &&\n     echo \"bfile line 3\" >> adir/bdir/bfile &&\n@@ -300,7 +301,8 @@ test_expect_success 'root dir rm file [cvswork2]' '\n \n test_expect_success 'subdir edit/add/rm files [cvswork2' '\n     ( cd cvswork2 &&\n-      sed -i -e \"s/line 1/line 1 (v2)/\" adir/bdir/bfile &&\n+      sed -e \"s/line 1/line 1 (v2)/\" adir/bdir/bfile >adir/bdir/bfileNEW &&\n+      mv -f adir/bdir/bfileNEW adir/bdir/bfile &&\n       rm adir/bdir/b2file &&\n       cd adir &&\n       cvs -f rm bdir/b2file &&\n-- \n1.7.12\n"}]}