| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='rebase should reread the todo file if an exec modifies it' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | . "$TEST_DIRECTORY"/lib-rebase.sh |
| 7 | |
| 8 | test_expect_success 'setup' ' |
| 9 | test_commit first file && |
| 10 | test_commit second file && |
| 11 | test_commit third file |
| 12 | ' |
| 13 | |
| 14 | test_expect_success 'rebase exec modifies rebase-todo' ' |
| 15 | todo=.git/rebase-merge/git-rebase-todo && |
| 16 | git rebase HEAD~1 -x "echo exec touch F >>$todo" && |
| 17 | test -e F |
| 18 | ' |
| 19 | |
| 20 | test_expect_success 'rebase exec with an empty list does not exec anything' ' |
| 21 | git rebase HEAD -x "true" 2>output && |
| 22 | ! grep "Executing: true" output |
| 23 | ' |
| 24 | |
| 25 | test_expect_success 'loose object cache vs re-reading todo list' ' |
| 26 | GIT_REBASE_TODO=.git/rebase-merge/git-rebase-todo && |
| 27 | export GIT_REBASE_TODO && |
| 28 | write_script append-todo.sh <<-\EOS && |
| 29 | # For values 5 and 6, this yields SHA-1s with the same first two digits |
| 30 | echo "pick $(git rev-parse --short \ |
| 31 | $(printf "%s\\n" \ |
| 32 | "tree $EMPTY_TREE" \ |
| 33 | "author A U Thor <author@example.org> $1 +0000" \ |
| 34 | "committer A U Thor <author@example.org> $1 +0000" \ |
| 35 | "" \ |
| 36 | "$1" | |
| 37 | git hash-object -t commit -w --stdin))" >>$GIT_REBASE_TODO |
| 38 | |
| 39 | shift |
| 40 | test -z "$*" || |
| 41 | echo "exec $0 $*" >>$GIT_REBASE_TODO |
| 42 | EOS |
| 43 | |
| 44 | git rebase HEAD -x "./append-todo.sh 5 6" |
| 45 | ' |
| 46 | |
| 47 | test_expect_success 'todo is re-read after reword and squash' ' |
| 48 | write_script reword-editor.sh <<-\EOS && |
| 49 | GIT_SEQUENCE_EDITOR="echo \"exec echo $(cat file) >>actual\" >>" \ |
| 50 | git rebase --edit-todo |
| 51 | EOS |
| 52 | |
| 53 | test_write_lines first third >expected && |
| 54 | set_fake_editor && |
| 55 | GIT_SEQUENCE_EDITOR="$EDITOR" FAKE_LINES="reword 1 squash 2 fixup 3" \ |
| 56 | GIT_EDITOR=./reword-editor.sh git rebase -i --root third && |
| 57 | test_cmp expected actual |
| 58 | ' |
| 59 | |
| 60 | test_expect_success 're-reading todo doesnt interfere with revert --edit' ' |
| 61 | git reset --hard third && |
| 62 | |
| 63 | git revert --edit third second && |
| 64 | |
| 65 | cat >expect <<-\EOF && |
| 66 | Revert "second" |
| 67 | Revert "third" |
| 68 | third |
| 69 | second |
| 70 | first |
| 71 | EOF |
| 72 | git log --format="%s" >actual && |
| 73 | test_cmp expect actual |
| 74 | ' |
| 75 | |
| 76 | test_expect_success 're-reading todo doesnt interfere with cherry-pick --edit' ' |
| 77 | git reset --hard first && |
| 78 | |
| 79 | git cherry-pick --edit second third && |
| 80 | |
| 81 | cat >expect <<-\EOF && |
| 82 | third |
| 83 | second |
| 84 | first |
| 85 | EOF |
| 86 | git log --format="%s" >actual && |
| 87 | test_cmp expect actual |
| 88 | ' |
| 89 | |
| 90 | test_done |