#!/bin/sh global test_description := ''stash -p'' source ./lib-patch-mode.sh if ! test_have_prereq PERL { global skip_all := ''skipping stash -p tests, perl not available'' test_done } test_expect_success 'setup' ' mkdir dir && echo parent > dir/foo && echo dummy > bar && echo committed > HEAD && git add bar dir/foo HEAD && git commit -m initial && test_tick && test_commit second dir/foo head && echo index > dir/foo && git add dir/foo && set_and_save_state bar bar_work bar_index && save_head ' # note: order of files with unstaged changes: HEAD bar dir/foo test_expect_success 'saying "n" does nothing' ' set_state HEAD HEADfile_work HEADfile_index && set_state dir/foo work index && (echo n; echo n; echo n) | test_must_fail git stash save -p && verify_state HEAD HEADfile_work HEADfile_index && verify_saved_state bar && verify_state dir/foo work index ' test_expect_success 'git stash -p' ' (echo y; echo n; echo y) | git stash save -p && verify_state HEAD committed HEADfile_index && verify_saved_state bar && verify_state dir/foo head index && git reset --hard && git stash apply && verify_state HEAD HEADfile_work committed && verify_state bar dummy dummy && verify_state dir/foo work head ' test_expect_success 'git stash -p --no-keep-index' ' set_state HEAD HEADfile_work HEADfile_index && set_state bar bar_work bar_index && set_state dir/foo work index && (echo y; echo n; echo y) | git stash save -p --no-keep-index && verify_state HEAD committed committed && verify_state bar bar_work dummy && verify_state dir/foo head head && git reset --hard && git stash apply --index && verify_state HEAD HEADfile_work HEADfile_index && verify_state bar dummy bar_index && verify_state dir/foo work index ' test_expect_success 'git stash --no-keep-index -p' ' set_state HEAD HEADfile_work HEADfile_index && set_state bar bar_work bar_index && set_state dir/foo work index && (echo y; echo n; echo y) | git stash save --no-keep-index -p && verify_state HEAD committed committed && verify_state dir/foo head head && verify_state bar bar_work dummy && git reset --hard && git stash apply --index && verify_state HEAD HEADfile_work HEADfile_index && verify_state bar dummy bar_index && verify_state dir/foo work index ' test_expect_success 'none of this moved HEAD' ' verify_saved_head ' test_expect_failure 'stash -p with split hunk' ' git reset --hard && cat >test <<-\EOF && aaa bbb ccc EOF git add test && git commit -m "initial" && cat >test <<-\EOF && aaa added line 1 bbb added line 2 ccc EOF printf "%s\n" s n y q | test_might_fail git stash -p 2>error && ! test_must_be_empty error && grep "added line 1" test && ! grep "added line 2" test ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"stash -p">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./lib-patch-mode.sh)}) (If arms: [ (if_arm cond: [(Pipeline children:[(C {(test_have_prereq)} {(PERL)})] negated:True)] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:skip_all) op: Equal rhs: {(SQ <"skipping stash -p tests, perl not available">)} spids: [25] ) ] spids: [25] ) (C {(test_done)}) ] spids: [-1 22] ) ] spids: [-1 33] ) (C {(test_expect_success)} {(SQ )} { (SQ <"\n"> <"\tmkdir dir &&\n"> <"\techo parent > dir/foo &&\n"> <"\techo dummy > bar &&\n"> <"\techo committed > HEAD &&\n"> <"\tgit add bar dir/foo HEAD &&\n"> <"\tgit commit -m initial &&\n"> <"\ttest_tick &&\n"> <"\ttest_commit second dir/foo head &&\n"> <"\techo index > dir/foo &&\n"> <"\tgit add dir/foo &&\n"> <"\tset_and_save_state bar bar_work bar_index &&\n"> <"\tsave_head\n"> ) } ) (C {(test_expect_success)} {(SQ <"saying \"n\" does nothing">)} { (SQ <"\n"> <"\tset_state HEAD HEADfile_work HEADfile_index &&\n"> <"\tset_state dir/foo work index &&\n"> <"\t(echo n; echo n; echo n) | test_must_fail git stash save -p &&\n"> <"\tverify_state HEAD HEADfile_work HEADfile_index &&\n"> <"\tverify_saved_state bar &&\n"> <"\tverify_state dir/foo work index\n"> ) } ) (C {(test_expect_success)} {(SQ <"git stash -p">)} { (SQ <"\n"> <"\t(echo y; echo n; echo y) | git stash save -p &&\n"> <"\tverify_state HEAD committed HEADfile_index &&\n"> <"\tverify_saved_state bar &&\n"> <"\tverify_state dir/foo head index &&\n"> <"\tgit reset --hard &&\n"> <"\tgit stash apply &&\n"> <"\tverify_state HEAD HEADfile_work committed &&\n"> <"\tverify_state bar dummy dummy &&\n"> <"\tverify_state dir/foo work head\n"> ) } ) (C {(test_expect_success)} {(SQ <"git stash -p --no-keep-index">)} { (SQ <"\n"> <"\tset_state HEAD HEADfile_work HEADfile_index &&\n"> <"\tset_state bar bar_work bar_index &&\n"> <"\tset_state dir/foo work index &&\n"> <"\t(echo y; echo n; echo y) | git stash save -p --no-keep-index &&\n"> <"\tverify_state HEAD committed committed &&\n"> <"\tverify_state bar bar_work dummy &&\n"> <"\tverify_state dir/foo head head &&\n"> <"\tgit reset --hard &&\n"> <"\tgit stash apply --index &&\n"> <"\tverify_state HEAD HEADfile_work HEADfile_index &&\n"> <"\tverify_state bar dummy bar_index &&\n"> <"\tverify_state dir/foo work index\n"> ) } ) (C {(test_expect_success)} {(SQ <"git stash --no-keep-index -p">)} { (SQ <"\n"> <"\tset_state HEAD HEADfile_work HEADfile_index &&\n"> <"\tset_state bar bar_work bar_index &&\n"> <"\tset_state dir/foo work index &&\n"> <"\t(echo y; echo n; echo y) | git stash save --no-keep-index -p &&\n"> <"\tverify_state HEAD committed committed &&\n"> <"\tverify_state dir/foo head head &&\n"> <"\tverify_state bar bar_work dummy &&\n"> <"\tgit reset --hard &&\n"> <"\tgit stash apply --index &&\n"> <"\tverify_state HEAD HEADfile_work HEADfile_index &&\n"> <"\tverify_state bar dummy bar_index &&\n"> <"\tverify_state dir/foo work index\n"> ) } ) (C {(test_expect_success)} {(SQ <"none of this moved HEAD">)} {(SQ <"\n"> <"\tverify_saved_head\n">)}) (C {(test_expect_failure)} {(SQ <"stash -p with split hunk">)} { (SQ <"\n"> <"\tgit reset --hard &&\n"> <"\tcat >test <<-\\EOF &&\n"> <"\taaa\n"> <"\tbbb\n"> <"\tccc\n"> <"\tEOF\n"> <"\tgit add test &&\n"> <"\tgit commit -m \"initial\" &&\n"> <"\tcat >test <<-\\EOF &&\n"> <"\taaa\n"> <"\tadded line 1\n"> <"\tbbb\n"> <"\tadded line 2\n"> <"\tccc\n"> <"\tEOF\n"> <"\tprintf \"%s\\n\" s n y q |\n"> <"\ttest_might_fail git stash -p 2>error &&\n"> <"\t! test_must_be_empty error &&\n"> <"\tgrep \"added line 1\" test &&\n"> <"\t! grep \"added line 2\" test\n"> ) } ) (C {(test_done)}) ] )