Git fork
at reftables-rust 102 lines 2.1 kB view raw
1#!/bin/sh 2 3test_description='GIT_EDITOR, core.editor, and stuff' 4 5. ./test-lib.sh 6 7unset EDITOR VISUAL GIT_EDITOR 8 9test_expect_success 'determine default editor' ' 10 vi=$(TERM=vt100 git var GIT_EDITOR) && 11 test -n "$vi" 12' 13 14test_expect_success setup ' 15 if ! expr "$vi" : "[a-z]*$" >/dev/null 16 then 17 vi= 18 fi && 19 20 for i in GIT_EDITOR core_editor EDITOR VISUAL $vi 21 do 22 write_script e-$i.sh <<-EOF || return 1 23 echo "Edited by $i" >"\$1" 24 EOF 25 done && 26 27 if ! test -z "$vi" 28 then 29 mv e-$vi.sh $vi 30 fi && 31 32 msg="Hand-edited" && 33 test_commit "$msg" && 34 test_commit_message HEAD -m "$msg" 35' 36 37test_expect_success 'dumb should error out when falling back on vi' ' 38 test_must_fail env TERM=dumb git commit --amend 39' 40 41test_expect_success 'dumb should prefer EDITOR to VISUAL' ' 42 TERM=dumb EDITOR=./e-EDITOR.sh VISUAL=./e-VISUAL.sh \ 43 git commit --amend && 44 test_commit_message HEAD -m "Edited by EDITOR" 45' 46 47for i in $vi EDITOR VISUAL core_editor GIT_EDITOR 48do 49 test_expect_success "Using $i" ' 50 if test "$i" = core_editor 51 then 52 test_config core.editor ./e-core_editor.sh 53 fi && 54 ( 55 case "$i" in 56 [A-Z]*) 57 eval "$i=./e-$i.sh" && 58 export $i 59 ;; 60 esac && 61 PATH="$PWD:$PATH" TERM=vt100 git commit --amend 62 ) && 63 test_commit_message HEAD -m "Edited by $i" 64 ' 65done 66 67test_expect_success 'Using editors with overrides' ' 68 ( 69 TERM=vt100 && 70 export TERM && 71 for i in $vi EDITOR VISUAL core_editor GIT_EDITOR 72 do 73 echo "Edited by $i" >expect && 74 case "$i" in 75 core_editor) 76 git config core.editor ./e-core_editor.sh 77 ;; 78 [A-Z]*) 79 eval "$i=./e-$i.sh" && 80 export $i 81 ;; 82 esac && 83 PATH="$PWD:$PATH" git commit --amend && 84 test_commit_message HEAD expect || exit 1 85 done 86 ) 87' 88 89test_expect_success 'editor with a space' ' 90 echo "echo space >\"\$1\"" >"e space.sh" && 91 chmod a+x "e space.sh" && 92 GIT_EDITOR="./e\ space.sh" git commit --amend && 93 test_commit_message HEAD -m space 94' 95 96test_expect_success 'core.editor with a space' ' 97 test_config core.editor \"./e\ space.sh\" && 98 git commit --amend && 99 test_commit_message HEAD -m space 100' 101 102test_done