replace: add tests for --edit
authorChristian Couder <chriscool@tuxfamily.org>
Sat, 17 May 2014 12:16:37 +0000 (14:16 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 19 May 2014 20:39:53 +0000 (13:39 -0700)
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t6050-replace.sh
index 719a11673bfc93463870d7d601eb3a0634b59b48..68b3cb26d90c5b88d28bbd03e8d50d4527f8a19b 100755 (executable)
@@ -318,6 +318,33 @@ test_expect_success 'test --format long' '
        test_cmp expected actual
 '
 
+test_expect_success 'setup a fake editor' '
+       write_script fakeeditor <<-\EOF
+               sed -e "s/A U Thor/A fake Thor/" "$1" >"$1.new"
+               mv "$1.new" "$1"
+       EOF
+'
+
+test_expect_success '--edit with and without already replaced object' '
+       test_must_fail env GIT_EDITOR=./fakeeditor git replace --edit "$PARA3" &&
+       GIT_EDITOR=./fakeeditor git replace --force --edit "$PARA3" &&
+       git replace -l | grep "$PARA3" &&
+       git cat-file commit "$PARA3" | grep "A fake Thor" &&
+       git replace -d "$PARA3" &&
+       GIT_EDITOR=./fakeeditor git replace --edit "$PARA3" &&
+       git replace -l | grep "$PARA3" &&
+       git cat-file commit "$PARA3" | grep "A fake Thor"
+'
+
+test_expect_success '--edit and change nothing or command failed' '
+       git replace -d "$PARA3" &&
+       test_must_fail env GIT_EDITOR=true git replace --edit "$PARA3" &&
+       test_must_fail env GIT_EDITOR="./fakeeditor;false" git replace --edit "$PARA3" &&
+       GIT_EDITOR=./fakeeditor git replace --edit "$PARA3" &&
+       git replace -l | grep "$PARA3" &&
+       git cat-file commit "$PARA3" | grep "A fake Thor"
+'
+
 test_expect_success 'replace ref cleanup' '
        test -n "$(git replace)" &&
        git replace -d $(git replace) &&