t / t7005-editor.shon commit Merge branch 'jc/maint-add-sync-stat' (c78a249)
   1#!/bin/sh
   2
   3test_description='GIT_EDITOR, core.editor, and stuff'
   4
   5. ./test-lib.sh
   6
   7OLD_TERM="$TERM"
   8
   9for i in GIT_EDITOR core_editor EDITOR VISUAL vi
  10do
  11        cat >e-$i.sh <<-EOF
  12        echo "Edited by $i" >"\$1"
  13        EOF
  14        chmod +x e-$i.sh
  15done
  16unset vi
  17mv e-vi.sh vi
  18PATH=".:$PATH"
  19unset EDITOR VISUAL GIT_EDITOR
  20
  21test_expect_success setup '
  22
  23        msg="Hand edited" &&
  24        echo "$msg" >expect &&
  25        git add vi &&
  26        test_tick &&
  27        git commit -m "$msg" &&
  28        git show -s --pretty=oneline |
  29        sed -e "s/^[0-9a-f]* //" >actual &&
  30        diff actual expect
  31
  32'
  33
  34TERM=dumb
  35export TERM
  36test_expect_success 'dumb should error out when falling back on vi' '
  37
  38        if git commit --amend
  39        then
  40                echo "Oops?"
  41                exit 1
  42        else
  43                : happy
  44        fi
  45'
  46
  47TERM=vt100
  48export TERM
  49for i in vi EDITOR VISUAL core_editor GIT_EDITOR
  50do
  51        echo "Edited by $i" >expect
  52        unset EDITOR VISUAL GIT_EDITOR
  53        git config --unset-all core.editor
  54        case "$i" in
  55        core_editor)
  56                git config core.editor ./e-core_editor.sh
  57                ;;
  58        [A-Z]*)
  59                eval "$i=./e-$i.sh"
  60                export $i
  61                ;;
  62        esac
  63        test_expect_success "Using $i" '
  64                git commit --amend &&
  65                git show -s --pretty=oneline |
  66                sed -e "s/^[0-9a-f]* //" >actual &&
  67                diff actual expect
  68        '
  69done
  70
  71unset EDITOR VISUAL GIT_EDITOR
  72git config --unset-all core.editor
  73for i in vi EDITOR VISUAL core_editor GIT_EDITOR
  74do
  75        echo "Edited by $i" >expect
  76        case "$i" in
  77        core_editor)
  78                git config core.editor ./e-core_editor.sh
  79                ;;
  80        [A-Z]*)
  81                eval "$i=./e-$i.sh"
  82                export $i
  83                ;;
  84        esac
  85        test_expect_success "Using $i (override)" '
  86                git commit --amend &&
  87                git show -s --pretty=oneline |
  88                sed -e "s/^[0-9a-f]* //" >actual &&
  89                diff actual expect
  90        '
  91done
  92
  93TERM="$OLD_TERM"
  94
  95test_done