#!/bin/sh global test_description := ''git rebase with its hook(s)'' source ./test-lib.sh test_expect_success setup ' echo hello >file && git add file && test_tick && git commit -m initial && echo goodbye >file && git add file && test_tick && git commit -m second && git checkout -b side HEAD^ && echo world >git && git add git && test_tick && git commit -m side && git checkout master && git log --pretty=oneline --abbrev-commit --graph --all && git branch test side ' test_expect_success 'rebase' ' git checkout test && git reset --hard side && git rebase master && test "z$(cat git)" = zworld ' test_expect_success 'rebase -i' ' git checkout test && git reset --hard side && EDITOR=true git rebase -i master && test "z$(cat git)" = zworld ' test_expect_success 'setup pre-rebase hook' ' mkdir -p .git/hooks && cat >.git/hooks/pre-rebase <.git/PRE-REBASE-INPUT EOF chmod +x .git/hooks/pre-rebase ' test_expect_success 'pre-rebase hook gets correct input (1)' ' git checkout test && git reset --hard side && git rebase master && test "z$(cat git)" = zworld && test "z$(cat .git/PRE-REBASE-INPUT)" = zmaster, ' test_expect_success 'pre-rebase hook gets correct input (2)' ' git checkout test && git reset --hard side && git rebase master test && test "z$(cat git)" = zworld && test "z$(cat .git/PRE-REBASE-INPUT)" = zmaster,test ' test_expect_success 'pre-rebase hook gets correct input (3)' ' git checkout test && git reset --hard side && git checkout master && git rebase master test && test "z$(cat git)" = zworld && test "z$(cat .git/PRE-REBASE-INPUT)" = zmaster,test ' test_expect_success 'pre-rebase hook gets correct input (4)' ' git checkout test && git reset --hard side && EDITOR=true git rebase -i master && test "z$(cat git)" = zworld && test "z$(cat .git/PRE-REBASE-INPUT)" = zmaster, ' test_expect_success 'pre-rebase hook gets correct input (5)' ' git checkout test && git reset --hard side && EDITOR=true git rebase -i master test && test "z$(cat git)" = zworld && test "z$(cat .git/PRE-REBASE-INPUT)" = zmaster,test ' test_expect_success 'pre-rebase hook gets correct input (6)' ' git checkout test && git reset --hard side && git checkout master && EDITOR=true git rebase -i master test && test "z$(cat git)" = zworld && test "z$(cat .git/PRE-REBASE-INPUT)" = zmaster,test ' test_expect_success 'setup pre-rebase hook that fails' ' mkdir -p .git/hooks && cat >.git/hooks/pre-rebase <)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (C {(test_expect_success)} {(setup)} { (SQ <"\n"> <"\techo hello >file &&\n"> <"\tgit add file &&\n"> <"\ttest_tick &&\n"> <"\tgit commit -m initial &&\n"> <"\techo goodbye >file &&\n"> <"\tgit add file &&\n"> <"\ttest_tick &&\n"> <"\tgit commit -m second &&\n"> <"\tgit checkout -b side HEAD^ &&\n"> <"\techo world >git &&\n"> <"\tgit add git &&\n"> <"\ttest_tick &&\n"> <"\tgit commit -m side &&\n"> <"\tgit checkout master &&\n"> <"\tgit log --pretty=oneline --abbrev-commit --graph --all &&\n"> <"\tgit branch test side\n"> ) } ) (C {(test_expect_success)} {(SQ )} { (SQ <"\n"> <"\tgit checkout test &&\n"> <"\tgit reset --hard side &&\n"> <"\tgit rebase master &&\n"> <"\ttest \"z$(cat git)\" = zworld\n"> ) } ) (C {(test_expect_success)} {(SQ <"rebase -i">)} { (SQ <"\n"> <"\tgit checkout test &&\n"> <"\tgit reset --hard side &&\n"> <"\tEDITOR=true git rebase -i master &&\n"> <"\ttest \"z$(cat git)\" = zworld\n"> ) } ) (C {(test_expect_success)} {(SQ <"setup pre-rebase hook">)} { (SQ <"\n"> <"\tmkdir -p .git/hooks &&\n"> <"\tcat >.git/hooks/pre-rebase < <"#!$SHELL_PATH\n"> <"echo \"\\$1,\\$2\" >.git/PRE-REBASE-INPUT\n"> <"EOF\n"> <"\tchmod +x .git/hooks/pre-rebase\n"> ) } ) (C {(test_expect_success)} {(SQ <"pre-rebase hook gets correct input (1)">)} { (SQ <"\n"> <"\tgit checkout test &&\n"> <"\tgit reset --hard side &&\n"> <"\tgit rebase master &&\n"> <"\ttest \"z$(cat git)\" = zworld &&\n"> <"\ttest \"z$(cat .git/PRE-REBASE-INPUT)\" = zmaster,\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"pre-rebase hook gets correct input (2)">)} { (SQ <"\n"> <"\tgit checkout test &&\n"> <"\tgit reset --hard side &&\n"> <"\tgit rebase master test &&\n"> <"\ttest \"z$(cat git)\" = zworld &&\n"> <"\ttest \"z$(cat .git/PRE-REBASE-INPUT)\" = zmaster,test\n"> ) } ) (C {(test_expect_success)} {(SQ <"pre-rebase hook gets correct input (3)">)} { (SQ <"\n"> <"\tgit checkout test &&\n"> <"\tgit reset --hard side &&\n"> <"\tgit checkout master &&\n"> <"\tgit rebase master test &&\n"> <"\ttest \"z$(cat git)\" = zworld &&\n"> <"\ttest \"z$(cat .git/PRE-REBASE-INPUT)\" = zmaster,test\n"> ) } ) (C {(test_expect_success)} {(SQ <"pre-rebase hook gets correct input (4)">)} { (SQ <"\n"> <"\tgit checkout test &&\n"> <"\tgit reset --hard side &&\n"> <"\tEDITOR=true git rebase -i master &&\n"> <"\ttest \"z$(cat git)\" = zworld &&\n"> <"\ttest \"z$(cat .git/PRE-REBASE-INPUT)\" = zmaster,\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"pre-rebase hook gets correct input (5)">)} { (SQ <"\n"> <"\tgit checkout test &&\n"> <"\tgit reset --hard side &&\n"> <"\tEDITOR=true git rebase -i master test &&\n"> <"\ttest \"z$(cat git)\" = zworld &&\n"> <"\ttest \"z$(cat .git/PRE-REBASE-INPUT)\" = zmaster,test\n"> ) } ) (C {(test_expect_success)} {(SQ <"pre-rebase hook gets correct input (6)">)} { (SQ <"\n"> <"\tgit checkout test &&\n"> <"\tgit reset --hard side &&\n"> <"\tgit checkout master &&\n"> <"\tEDITOR=true git rebase -i master test &&\n"> <"\ttest \"z$(cat git)\" = zworld &&\n"> <"\ttest \"z$(cat .git/PRE-REBASE-INPUT)\" = zmaster,test\n"> ) } ) (C {(test_expect_success)} {(SQ <"setup pre-rebase hook that fails">)} { (SQ <"\n"> <"\tmkdir -p .git/hooks &&\n"> <"\tcat >.git/hooks/pre-rebase < <"#!$SHELL_PATH\n"> <"false\n"> <"EOF\n"> <"\tchmod +x .git/hooks/pre-rebase\n"> ) } ) (C {(test_expect_success)} {(SQ <"pre-rebase hook stops rebase (1)">)} { (SQ <"\n"> <"\tgit checkout test &&\n"> <"\tgit reset --hard side &&\n"> <"\ttest_must_fail git rebase master &&\n"> <"\ttest \"z$(git symbolic-ref HEAD)\" = zrefs/heads/test &&\n"> <"\ttest 0 = $(git rev-list HEAD...side | wc -l)\n"> ) } ) (C {(test_expect_success)} {(SQ <"pre-rebase hook stops rebase (2)">)} { (SQ <"\n"> <"\tgit checkout test &&\n"> <"\tgit reset --hard side &&\n"> <"\ttest_must_fail env EDITOR=: git rebase -i master &&\n"> <"\ttest \"z$(git symbolic-ref HEAD)\" = zrefs/heads/test &&\n"> <"\ttest 0 = $(git rev-list HEAD...side | wc -l)\n"> ) } ) (C {(test_expect_success)} {(SQ <"rebase --no-verify overrides pre-rebase (1)">)} { (SQ <"\n"> <"\tgit checkout test &&\n"> <"\tgit reset --hard side &&\n"> <"\tgit rebase --no-verify master &&\n"> <"\ttest \"z$(git symbolic-ref HEAD)\" = zrefs/heads/test &&\n"> <"\ttest \"z$(cat git)\" = zworld\n"> ) } ) (C {(test_expect_success)} {(SQ <"rebase --no-verify overrides pre-rebase (2)">)} { (SQ <"\n"> <"\tgit checkout test &&\n"> <"\tgit reset --hard side &&\n"> <"\tEDITOR=true git rebase --no-verify -i master &&\n"> <"\ttest \"z$(git symbolic-ref HEAD)\" = zrefs/heads/test &&\n"> <"\ttest \"z$(cat git)\" = zworld\n"> ) } ) (C {(test_done)}) ] )