t / t3702-add-edit.shon commit Merge branch 'js/mingw-spawn-with-spaces-in-path' into maint (2f72ebf)
   1#!/bin/sh
   2#
   3# Copyright (c) 2007 Johannes E. Schindelin
   4#
   5
   6test_description='add -e basic tests'
   7. ./test-lib.sh
   8
   9
  10cat > file << EOF
  11LO, praise of the prowess of people-kings
  12of spear-armed Danes, in days long sped,
  13we have heard, and what honor the athelings won!
  14Oft Scyld the Scefing from squadroned foes,
  15from many a tribe, the mead-bench tore,
  16awing the earls. Since erst he lay
  17friendless, a foundling, fate repaid him:
  18for he waxed under welkin, in wealth he throve,
  19till before him the folk, both far and near,
  20who house by the whale-path, heard his mandate,
  21gave him gifts:  a good king he!
  22EOF
  23
  24cat > second-part << EOF
  25To him an heir was afterward born,
  26a son in his halls, whom heaven sent
  27to favor the folk, feeling their woe
  28that erst they had lacked an earl for leader
  29so long a while; the Lord endowed him,
  30the Wielder of Wonder, with world's renown.
  31EOF
  32
  33test_expect_success 'setup' '
  34
  35        git add file &&
  36        test_tick &&
  37        git commit -m initial file
  38
  39'
  40
  41cat > expected-patch << EOF
  42diff --git a/file b/file
  43--- a/file
  44+++ b/file
  45@@ -1,11 +1,6 @@
  46-LO, praise of the prowess of people-kings
  47-of spear-armed Danes, in days long sped,
  48-we have heard, and what honor the athelings won!
  49-Oft Scyld the Scefing from squadroned foes,
  50-from many a tribe, the mead-bench tore,
  51-awing the earls. Since erst he lay
  52-friendless, a foundling, fate repaid him:
  53-for he waxed under welkin, in wealth he throve,
  54-till before him the folk, both far and near,
  55-who house by the whale-path, heard his mandate,
  56-gave him gifts:  a good king he!
  57+To him an heir was afterward born,
  58+a son in his halls, whom heaven sent
  59+to favor the folk, feeling their woe
  60+that erst they had lacked an earl for leader
  61+so long a while; the Lord endowed him,
  62+the Wielder of Wonder, with world's renown.
  63EOF
  64
  65cat > patch << EOF
  66diff --git a/file b/file
  67index b9834b5..ef6e94c 100644
  68--- a/file
  69+++ b/file
  70@@ -3,1 +3,333 @@ of spear-armed Danes, in days long sped,
  71 we have heard, and what honor the athelings won!
  72+
  73 Oft Scyld the Scefing from squadroned foes,
  74@@ -2,7 +1,5 @@ awing the earls. Since erst he lay
  75 friendless, a foundling, fate repaid him:
  76+
  77 for he waxed under welkin, in wealth he throve,
  78EOF
  79
  80cat > expected << EOF
  81diff --git a/file b/file
  82--- a/file
  83+++ b/file
  84@@ -1,10 +1,12 @@
  85 LO, praise of the prowess of people-kings
  86 of spear-armed Danes, in days long sped,
  87 we have heard, and what honor the athelings won!
  88+
  89 Oft Scyld the Scefing from squadroned foes,
  90 from many a tribe, the mead-bench tore,
  91 awing the earls. Since erst he lay
  92 friendless, a foundling, fate repaid him:
  93+
  94 for he waxed under welkin, in wealth he throve,
  95 till before him the folk, both far and near,
  96 who house by the whale-path, heard his mandate,
  97EOF
  98
  99echo "#!$SHELL_PATH" >fake-editor.sh
 100cat >> fake-editor.sh <<\EOF
 101egrep -v '^index' "$1" >orig-patch &&
 102mv -f patch "$1"
 103EOF
 104
 105test_set_editor "$(pwd)/fake-editor.sh"
 106chmod a+x fake-editor.sh
 107
 108test_expect_success 'add -e' '
 109
 110        cp second-part file &&
 111        git add -e &&
 112        test_cmp second-part file &&
 113        test_cmp expected-patch orig-patch &&
 114        git diff --cached >actual &&
 115        grep -v index actual >out &&
 116        test_cmp expected out
 117
 118'
 119
 120test_expect_success 'add -e notices editor failure' '
 121        git reset --hard &&
 122        echo change >>file &&
 123        test_must_fail env GIT_EDITOR=false git add -e &&
 124        test_expect_code 1 git diff --exit-code
 125'
 126
 127test_done