#!/bin/sh global test_description := ''git reset --patch'' source ./lib-patch-mode.sh test_expect_success PERL 'setup' ' mkdir dir && echo parent > dir/foo && echo dummy > bar && git add dir && git commit -m initial && test_tick && test_commit second dir/foo head && set_and_save_state bar bar_work bar_index && save_head ' # note: bar sorts before foo, so the first 'n' is always to skip 'bar' test_expect_success PERL 'saying "n" does nothing' ' set_and_save_state dir/foo work work && (echo n; echo n) | git reset -p && verify_saved_state dir/foo && verify_saved_state bar ' test_expect_success PERL 'git reset -p' ' (echo n; echo y) | git reset -p >output && verify_state dir/foo work head && verify_saved_state bar && test_i18ngrep "Unstage" output ' test_expect_success PERL 'git reset -p HEAD^' ' (echo n; echo y) | git reset -p HEAD^ >output && verify_state dir/foo work parent && verify_saved_state bar && test_i18ngrep "Apply" output ' # The idea in the rest is that bar sorts first, so we always say 'y' # first and if the path limiter fails it'll apply to bar instead of # dir/foo. There's always an extra 'n' to reject edits to dir/foo in # the failure case (and thus get out of the loop). test_expect_success PERL 'git reset -p dir' ' set_state dir/foo work work && (echo y; echo n) | git reset -p dir && verify_state dir/foo work head && verify_saved_state bar ' test_expect_success PERL 'git reset -p -- foo (inside dir)' ' set_state dir/foo work work && (echo y; echo n) | (cd dir && git reset -p -- foo) && verify_state dir/foo work head && verify_saved_state bar ' test_expect_success PERL 'git reset -p HEAD^ -- dir' ' (echo y; echo n) | git reset -p HEAD^ -- dir && verify_state dir/foo work parent && verify_saved_state bar ' test_expect_success PERL 'none of this moved HEAD' ' verify_saved_head ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"git reset --patch">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./lib-patch-mode.sh)}) (C {(test_expect_success)} {(PERL)} {(SQ )} { (SQ <"\n"> <"\tmkdir dir &&\n"> <"\techo parent > dir/foo &&\n"> <"\techo dummy > bar &&\n"> <"\tgit add dir &&\n"> <"\tgit commit -m initial &&\n"> <"\ttest_tick &&\n"> <"\ttest_commit second dir/foo head &&\n"> <"\tset_and_save_state bar bar_work bar_index &&\n"> <"\tsave_head\n"> ) } ) (C {(test_expect_success)} {(PERL)} {(SQ <"saying \"n\" does nothing">)} { (SQ <"\n"> <"\tset_and_save_state dir/foo work work &&\n"> <"\t(echo n; echo n) | git reset -p &&\n"> <"\tverify_saved_state dir/foo &&\n"> <"\tverify_saved_state bar\n"> ) } ) (C {(test_expect_success)} {(PERL)} {(SQ <"git reset -p">)} { (SQ <"\n"> <"\t(echo n; echo y) | git reset -p >output &&\n"> <"\tverify_state dir/foo work head &&\n"> <"\tverify_saved_state bar &&\n"> <"\ttest_i18ngrep \"Unstage\" output\n"> ) } ) (C {(test_expect_success)} {(PERL)} {(SQ <"git reset -p HEAD^">)} { (SQ <"\n"> <"\t(echo n; echo y) | git reset -p HEAD^ >output &&\n"> <"\tverify_state dir/foo work parent &&\n"> <"\tverify_saved_state bar &&\n"> <"\ttest_i18ngrep \"Apply\" output\n"> ) } ) (C {(test_expect_success)} {(PERL)} {(SQ <"git reset -p dir">)} { (SQ <"\n"> <"\tset_state dir/foo work work &&\n"> <"\t(echo y; echo n) | git reset -p dir &&\n"> <"\tverify_state dir/foo work head &&\n"> <"\tverify_saved_state bar\n"> ) } ) (C {(test_expect_success)} {(PERL)} {(SQ <"git reset -p -- foo (inside dir)">)} { (SQ <"\n"> <"\tset_state dir/foo work work &&\n"> <"\t(echo y; echo n) | (cd dir && git reset -p -- foo) &&\n"> <"\tverify_state dir/foo work head &&\n"> <"\tverify_saved_state bar\n"> ) } ) (C {(test_expect_success)} {(PERL)} {(SQ <"git reset -p HEAD^ -- dir">)} { (SQ <"\n"> <"\t(echo y; echo n) | git reset -p HEAD^ -- dir &&\n"> <"\tverify_state dir/foo work parent &&\n"> <"\tverify_saved_state bar\n"> ) } ) (C {(test_expect_success)} {(PERL)} {(SQ <"none of this moved HEAD">)} {(SQ <"\n"> <"\tverify_saved_head\n">)} ) (C {(test_done)}) ] )