t / t7105-reset-patch.shon commit Merge branch 'kb/maint-bundle-doc' (69637e5)
   1#!/bin/sh
   2
   3test_description='git reset --patch'
   4. ./lib-patch-mode.sh
   5
   6test_expect_success PERL 'setup' '
   7        mkdir dir &&
   8        echo parent > dir/foo &&
   9        echo dummy > bar &&
  10        git add dir &&
  11        git commit -m initial &&
  12        test_tick &&
  13        test_commit second dir/foo head &&
  14        set_and_save_state bar bar_work bar_index &&
  15        save_head
  16'
  17
  18# note: bar sorts before foo, so the first 'n' is always to skip 'bar'
  19
  20test_expect_success PERL 'saying "n" does nothing' '
  21        set_and_save_state dir/foo work work &&
  22        (echo n; echo n) | git reset -p &&
  23        verify_saved_state dir/foo &&
  24        verify_saved_state bar
  25'
  26
  27test_expect_success PERL 'git reset -p' '
  28        (echo n; echo y) | git reset -p &&
  29        verify_state dir/foo work head &&
  30        verify_saved_state bar
  31'
  32
  33test_expect_success PERL 'git reset -p HEAD^' '
  34        (echo n; echo y) | git reset -p HEAD^ &&
  35        verify_state dir/foo work parent &&
  36        verify_saved_state bar
  37'
  38
  39# The idea in the rest is that bar sorts first, so we always say 'y'
  40# first and if the path limiter fails it'll apply to bar instead of
  41# dir/foo.  There's always an extra 'n' to reject edits to dir/foo in
  42# the failure case (and thus get out of the loop).
  43
  44test_expect_success PERL 'git reset -p dir' '
  45        set_state dir/foo work work &&
  46        (echo y; echo n) | git reset -p dir &&
  47        verify_state dir/foo work head &&
  48        verify_saved_state bar
  49'
  50
  51test_expect_success PERL 'git reset -p -- foo (inside dir)' '
  52        set_state dir/foo work work &&
  53        (echo y; echo n) | (cd dir && git reset -p -- foo) &&
  54        verify_state dir/foo work head &&
  55        verify_saved_state bar
  56'
  57
  58test_expect_success PERL 'git reset -p HEAD^ -- dir' '
  59        (echo y; echo n) | git reset -p HEAD^ -- dir &&
  60        verify_state dir/foo work parent &&
  61        verify_saved_state bar
  62'
  63
  64test_expect_success PERL 'none of this moved HEAD' '
  65        verify_saved_head
  66'
  67
  68
  69test_done