fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
f69f074f6
master
1#RUN: %fish -i %s 2# Note: ^ this is interactive so we test interactive behavior, 3# e.g. the fish_git_prompt variable handlers test `status is-interactive`. 4#REQUIRES: command -v git 5 6set -g fish( status fish-path) 7 8# Tests run from git (e.g. git rebase --exec 'ninja test'...) inherit a weird git environment. 9# Ensure that no git environment variables are inherited. 10for varnamein ( set -x| string match'GIT_*' | string replace -r' .*' '' ) 11set -e$varname 12end 13 14set -gx GIT_CONFIG_GLOBAL /dev/null# No ~/.gitconfig. We could also override $HOME. 15set -gx GIT_CONFIG_NOSYSTEM true# No /etc/gitconfig 16 17# Also ensure that git-core is not in $PATH, as this adds weird git commands like `git-add--interactive`. 18set PATH( string match --invert'*git-core*' --$PATH ) 19 20# Do some tests with `git` - completions are interesting, 21# but prompts would also be possible. 22 23set -l tmp( mktemp -d) 24 25cd $tmp 26git init> /dev/null2>&1 27 28# Commands and descriptions 29# Note: We *can't* list all here because in addition to aliases, 30# git also uses all commands in $PATH called `git-something` as custom commands, 31# so this depends on system state! 32 33# First set up a test alias - *before loading the completions* 34git config --local alias.re'restore --staged' 35 36# Test custom command completions by adding a command: 37 38set -p PATH$PWD 39echo "echo foo" > git-frobnicate 40if cygwin_noacl ./ 41echo "#!/bin/sh" > git-frobnicate 42else 43chmod +x git-frobnicate 44end 45 46complete -c git-frobnicate -xa'foo bar baz' 47complete -c git-frobnicate -l onto -xa'onto1 onto2' 48 49complete -C'git frobnicate ' 50#CHECK: bar 51#CHECK: baz 52#CHECK: foo 53 54complete -C'git frobnicate --onto ' 55#CHECK: onto1 56#CHECK: onto2 57 58complete -C'git frobnicate graft --onto ' 59#CHECK: onto1 60#CHECK: onto2 61 62complete -C'git ' | grep '^add'\t 63# (note: actual tab character in the check here) 64#CHECK: add Add file contents to the staging area 65 66touch foo 67 68complete -C'git add ' 69#CHECK: foo Untracked file 70#CHECK: git-frobnicate Untracked file 71 72complete -C'git add :' 73#CHECK: :/:foo Untracked file 74#CHECK: :/:git-frobnicate Untracked file 75 76git config alias.s status 77complete 'git s --s' 78# CHECK --short 79 80# Note: We can't rely on the initial branch because that might be 81# "master", or it could be changed to something else in future! 82git checkout -b newbranch> /dev/null2>&1 83fish_git_prompt 84echo # the git prompt doesn't print a newline 85#CHECK: (newbranch) 86 87set -g __fish_git_prompt_show_informative_status1 88fish_git_prompt 89echo 90#CHECK: (newbranch|✔) 91 92set -g __fish_git_prompt_show_informative_status0 93fish_git_prompt 94echo # the git prompt doesn't print a newline 95#CHECK: (newbranch) 96set -g __fish_git_prompt_show_informative_status1 97 98# Informative mode only shows untracked files if explicitly told. 99set -g __fish_git_prompt_showuntrackedfiles1 100fish_git_prompt 101echo 102#CHECK: (newbranch|…2) 103set -e __fish_git_prompt_show_informative_status 104set -e __fish_git_prompt_showuntrackedfiles 105 106# Confirm the mode changes back 107fish_git_prompt 108echo 109#CHECK: (newbranch) 110 111# (for some reason stagedstate is only shown with showdirtystate?) 112set -g __fish_git_prompt_showdirtystate1 113git add foo 114fish_git_prompt 115echo 116#CHECK: (newbranch +) 117set -g __fish_git_prompt_showdirtystate0 118fish_git_prompt 119echo 120#CHECK: (newbranch) 121set -g __fish_git_prompt_showdirtystate1 122 123set -g __fish_git_prompt_showuntrackedfiles1 124touch bananan 125fish_git_prompt 126echo 127#CHECK: (newbranch +%) 128set -g __fish_git_prompt_showuntrackedfiles0 129fish_git_prompt 130echo 131#CHECK: (newbranch +) 132set -g __fish_git_prompt_showuntrackedfiles1 133 134set -g __fish_git_prompt_status_order untrackedfiles stagedstate 135fish_git_prompt 136echo 137#CHECK: (newbranch %+) 138 139set -g __fish_git_prompt_status_order untrackedfiles 140fish_git_prompt 141echo 142#CHECK: (newbranch %) 143 144set -e __fish_git_prompt_showuntrackedfiles 145set -e __fish_git_prompt_status_order 146 147git -c user.email=banana@example.com -c user.name=banana commit -m foo> /dev/null 148fish_git_prompt 149echo 150#CHECK: (newbranch) 151 152echo test> foo 153fish_git_prompt 154echo 155#CHECK: (newbranch *) 156 157git add foo 158fish_git_prompt 159echo 160#CHECK: (newbranch +) 161 162set -e __fish_git_prompt_showdirtystate 163 164# Test that renames count as one staged change, not two (issue #11296). 165# git status --porcelain -z outputs rename source as a separate NUL-delimited field, 166# which should not be counted as an additional change. 167# Use a filename starting with R (in [ACDMRTU]) to trigger the miscount. 168git -c user.email=banana@example.com -c user.name=banana commit -m'commit staged foo' > /dev/null 169echo content> Rfile 170git add Rfile 171git -c user.email=banana@example.com -c user.name=banana commit -m'add Rfile' > /dev/null 172 173set -g __fish_git_prompt_show_informative_status1 174mkdir -p subdir 175git mv Rfile subdir/Rfile 176fish_git_prompt 177echo 178#CHECK: (newbranch|●1) 179git reset> /dev/null2>&1 180mv subdir/Rfile Rfile 181rmdir subdir 182set -e __fish_git_prompt_show_informative_status 183 184# Test displaying only stash count 185set -g __fish_git_prompt_show_informative_status1 186set -g __fish_git_prompt_showstashstate1 187set -g __fish_git_prompt_status_order stashstate 188set -g ___fish_git_prompt_char_stashstate'' 189set -g ___fish_git_prompt_char_cleanstate'' 190 191set -l identity -c user.email=banana@example.com -c user.name=banana 192git $identity commit -m Init> /dev/null 193echo changed> foo 194# (some git versions don't allow stash without giving an email) 195git $identity stash> /dev/null 196fish_git_prompt 197echo 198#CHECK: (newbranch|1) 199 200git $identity stash pop> /dev/null 201fish_git_prompt 202echo 203#CHECK: (newbranch) 204 205set -e __fish_git_prompt_show_informative_status 206set -e __fish_git_prompt_showstashstate 207set -e __fish_git_prompt_status_order 208set -e ___fish_git_prompt_char_stashstate 209set -e ___fish_git_prompt_char_cleanstate 210 211# Turn on everything and verify we correctly ignore sus config files. 212set -g __fish_git_prompt_status_order stagedstate invalidstate dirtystate untrackedfiles stashstate 213set -g __fish_git_prompt_showdirtystate1 214set -g __fish_git_prompt_show_informative_status1 215set -g __fish_git_prompt_showuntrackedfiles1 216rm -Rf .git * 217git init> /dev/null2>&1 218echo -n> ran.txt 219git config core.fsmonitor'echo fsmonitor >> ran.txt; false' 220git config core.sshCommand'echo sshCommand >> ran.txt; false' 221git config diff.external'echo diff >> ran.txt; false' 222touch untracked_file 223fish_git_prompt > /dev/null 224cat ran.txt# should output nothing 225 226test "$ ( complete -C'git re ' ) " = "$ ( complete -C'git restore --staged ' ) " 227or begin 228echo -- Oops re completes unlike restore --staged 229end 230 231$fish -c'complete -C "git -C ./.gi"' 232# CHECK: ./.git/ Directory