t / t7005-editor.shon commit git-remote: reject adding remotes with invalid names (24b6177)
   1#!/bin/sh
   2
   3test_description='GIT_EDITOR, core.editor, and stuff'
   4
   5. ./test-lib.sh
   6
   7for i in GIT_EDITOR core_editor EDITOR VISUAL vi
   8do
   9        cat >e-$i.sh <<-EOF
  10        echo "Edited by $i" >"\$1"
  11        EOF
  12        chmod +x e-$i.sh
  13done
  14unset vi
  15mv e-vi.sh vi
  16unset EDITOR VISUAL GIT_EDITOR
  17
  18test_expect_success setup '
  19
  20        msg="Hand edited" &&
  21        echo "$msg" >expect &&
  22        git add vi &&
  23        test_tick &&
  24        git commit -m "$msg" &&
  25        git show -s --pretty=oneline |
  26        sed -e "s/^[0-9a-f]* //" >actual &&
  27        diff actual expect
  28
  29'
  30
  31TERM=dumb
  32export TERM
  33test_expect_success 'dumb should error out when falling back on vi' '
  34
  35        if git commit --amend
  36        then
  37                echo "Oops?"
  38                false
  39        else
  40                : happy
  41        fi
  42'
  43
  44TERM=vt100
  45export TERM
  46for i in vi EDITOR VISUAL core_editor GIT_EDITOR
  47do
  48        echo "Edited by $i" >expect
  49        unset EDITOR VISUAL GIT_EDITOR
  50        git config --unset-all core.editor
  51        case "$i" in
  52        core_editor)
  53                git config core.editor ./e-core_editor.sh
  54                ;;
  55        [A-Z]*)
  56                eval "$i=./e-$i.sh"
  57                export $i
  58                ;;
  59        esac
  60        test_expect_success "Using $i" '
  61                git --exec-path=. commit --amend &&
  62                git show -s --pretty=oneline |
  63                sed -e "s/^[0-9a-f]* //" >actual &&
  64                diff actual expect
  65        '
  66done
  67
  68unset EDITOR VISUAL GIT_EDITOR
  69git config --unset-all core.editor
  70for i in vi EDITOR VISUAL core_editor GIT_EDITOR
  71do
  72        echo "Edited by $i" >expect
  73        case "$i" in
  74        core_editor)
  75                git config core.editor ./e-core_editor.sh
  76                ;;
  77        [A-Z]*)
  78                eval "$i=./e-$i.sh"
  79                export $i
  80                ;;
  81        esac
  82        test_expect_success "Using $i (override)" '
  83                git --exec-path=. commit --amend &&
  84                git show -s --pretty=oneline |
  85                sed -e "s/^[0-9a-f]* //" >actual &&
  86                diff actual expect
  87        '
  88done
  89
  90test_expect_success 'editor with a space' '
  91
  92        if echo "echo space > \"\$1\"" > "e space.sh"
  93        then
  94                chmod a+x "e space.sh" &&
  95                GIT_EDITOR="./e\ space.sh" git commit --amend &&
  96                test space = "$(git show -s --pretty=format:%s)"
  97        else
  98                say "Skipping; FS does not support spaces in filenames"
  99        fi
 100
 101'
 102
 103unset GIT_EDITOR
 104test_expect_success 'core.editor with a space' '
 105
 106        if test -f "e space.sh"
 107        then
 108                git config core.editor \"./e\ space.sh\" &&
 109                git commit --amend &&
 110                test space = "$(git show -s --pretty=format:%s)"
 111        else
 112                say "Skipping; FS does not support spaces in filenames"
 113        fi
 114
 115'
 116
 117test_done