2024-04-12 10:19:32 +00:00
|
|
|
#RUN: %fish -i %s | %filter-control-sequences
|
2021-01-19 18:16:17 +00:00
|
|
|
# Note: ^ this is interactive so we test interactive behavior,
|
|
|
|
# e.g. the fish_git_prompt variable handlers test `status is-interactive`.
|
2021-01-16 12:27:30 +00:00
|
|
|
#REQUIRES: command -v git
|
|
|
|
|
2022-06-26 20:41:44 +00:00
|
|
|
set -g fish (status fish-path)
|
|
|
|
|
2021-02-05 22:53:32 +00:00
|
|
|
# Tests run from git (e.g. git rebase --exec 'ninja test'...) inherit a weird git environment.
|
|
|
|
# Ensure that no git environment variables are inherited.
|
|
|
|
for varname in (set -x | string match 'GIT_*' | string replace -r ' .*' '')
|
2021-07-12 19:37:17 +00:00
|
|
|
set -e $varname
|
2021-02-05 22:53:32 +00:00
|
|
|
end
|
|
|
|
|
2021-07-12 19:37:17 +00:00
|
|
|
set -gx GIT_CONFIG_GLOBAL /dev/null # No ~/.gitconfig. We could also override $HOME.
|
|
|
|
set -gx GIT_CONFIG_NOSYSTEM true # No /etc/gitconfig
|
|
|
|
|
2021-02-05 22:53:32 +00:00
|
|
|
# Also ensure that git-core is not in $PATH, as this adds weird git commands like `git-add--interactive`.
|
|
|
|
set PATH (string match --invert '*git-core*' -- $PATH)
|
|
|
|
|
2021-01-16 12:27:30 +00:00
|
|
|
# Do some tests with `git` - completions are interesting,
|
|
|
|
# but prompts would also be possible.
|
|
|
|
|
|
|
|
set -l tmp (mktemp -d)
|
|
|
|
|
|
|
|
cd $tmp
|
|
|
|
git init >/dev/null 2>&1
|
|
|
|
|
|
|
|
# Commands and descriptions
|
|
|
|
# Note: We *can't* list all here because in addition to aliases,
|
|
|
|
# git also uses all commands in $PATH called `git-something` as custom commands,
|
|
|
|
# so this depends on system state!
|
2022-03-30 16:18:53 +00:00
|
|
|
|
|
|
|
# First set up a test alias - *before loading the completions*
|
|
|
|
git config --local alias.re 'restore --staged'
|
|
|
|
|
2023-01-09 17:33:29 +00:00
|
|
|
# Test custom command completions by adding a command:
|
|
|
|
|
|
|
|
set -p PATH $PWD
|
|
|
|
echo "echo foo" > git-frobnicate
|
|
|
|
chmod +x git-frobnicate
|
|
|
|
|
|
|
|
complete -c git-frobnicate -xa 'foo bar baz'
|
|
|
|
|
|
|
|
complete -C'git frobnicate '
|
|
|
|
#CHECK: bar
|
|
|
|
#CHECK: baz
|
|
|
|
#CHECK: foo
|
|
|
|
|
2021-03-04 15:25:41 +00:00
|
|
|
complete -C'git ' | grep '^add'\t
|
2021-01-16 12:27:30 +00:00
|
|
|
# (note: actual tab character in the check here)
|
2022-08-10 16:02:12 +00:00
|
|
|
#CHECK: add Add file contents to the staging area
|
2021-01-16 12:27:30 +00:00
|
|
|
|
|
|
|
touch foo
|
|
|
|
|
|
|
|
complete -C'git add '
|
|
|
|
#CHECK: foo Untracked file
|
2023-01-09 17:33:29 +00:00
|
|
|
#CHECK: git-frobnicate Untracked file
|
2021-01-16 12:27:30 +00:00
|
|
|
|
2022-06-07 18:10:13 +00:00
|
|
|
complete -C'git add :'
|
|
|
|
#CHECK: :/:foo Untracked file
|
2023-01-09 17:33:29 +00:00
|
|
|
#CHECK: :/:git-frobnicate Untracked file
|
2022-06-07 18:10:13 +00:00
|
|
|
|
2021-07-12 21:41:28 +00:00
|
|
|
git config alias.s status
|
|
|
|
complete 'git s --s'
|
|
|
|
# CHECK --short
|
|
|
|
|
2021-01-16 12:27:30 +00:00
|
|
|
# Note: We can't rely on the initial branch because that might be
|
|
|
|
# "master", or it could be changed to something else in future!
|
|
|
|
git checkout -b newbranch >/dev/null 2>&1
|
|
|
|
fish_git_prompt
|
|
|
|
echo # the git prompt doesn't print a newline
|
2021-04-13 16:57:06 +00:00
|
|
|
#CHECK: (newbranch)
|
2021-01-16 12:27:30 +00:00
|
|
|
|
2021-04-13 13:58:55 +00:00
|
|
|
set -g __fish_git_prompt_show_informative_status 1
|
|
|
|
fish_git_prompt
|
2021-01-16 12:27:30 +00:00
|
|
|
echo
|
2022-05-30 15:36:41 +00:00
|
|
|
#CHECK: (newbranch|✔)
|
|
|
|
|
2022-10-21 18:22:20 +00:00
|
|
|
set -g __fish_git_prompt_show_informative_status 0
|
|
|
|
fish_git_prompt
|
|
|
|
echo # the git prompt doesn't print a newline
|
|
|
|
#CHECK: (newbranch)
|
|
|
|
set -g __fish_git_prompt_show_informative_status 1
|
|
|
|
|
2022-05-30 15:36:41 +00:00
|
|
|
# Informative mode only shows untracked files if explicitly told.
|
|
|
|
set -g __fish_git_prompt_showuntrackedfiles 1
|
|
|
|
fish_git_prompt
|
|
|
|
echo
|
2023-01-09 17:33:29 +00:00
|
|
|
#CHECK: (newbranch|…2)
|
2021-04-13 13:58:55 +00:00
|
|
|
set -e __fish_git_prompt_show_informative_status
|
2022-05-30 15:36:41 +00:00
|
|
|
set -e __fish_git_prompt_showuntrackedfiles
|
2021-01-19 18:16:17 +00:00
|
|
|
|
|
|
|
# Confirm the mode changes back
|
|
|
|
fish_git_prompt
|
|
|
|
echo
|
2021-04-13 16:57:06 +00:00
|
|
|
#CHECK: (newbranch)
|
2021-04-13 13:58:55 +00:00
|
|
|
|
2021-04-13 16:57:06 +00:00
|
|
|
# (for some reason stagedstate is only shown with showdirtystate?)
|
|
|
|
set -g __fish_git_prompt_showdirtystate 1
|
2021-04-13 13:58:55 +00:00
|
|
|
git add foo
|
|
|
|
fish_git_prompt
|
|
|
|
echo
|
|
|
|
#CHECK: (newbranch +)
|
2022-10-21 18:22:20 +00:00
|
|
|
set -g __fish_git_prompt_showdirtystate 0
|
|
|
|
fish_git_prompt
|
|
|
|
echo
|
|
|
|
#CHECK: (newbranch)
|
|
|
|
set -g __fish_git_prompt_showdirtystate 1
|
2021-04-13 13:58:55 +00:00
|
|
|
|
|
|
|
set -g __fish_git_prompt_showuntrackedfiles 1
|
|
|
|
touch bananan
|
|
|
|
fish_git_prompt
|
|
|
|
echo
|
|
|
|
#CHECK: (newbranch +%)
|
2022-10-21 18:22:20 +00:00
|
|
|
set -g __fish_git_prompt_showuntrackedfiles 0
|
|
|
|
fish_git_prompt
|
|
|
|
echo
|
|
|
|
#CHECK: (newbranch +)
|
|
|
|
set -g __fish_git_prompt_showuntrackedfiles 1
|
2021-04-13 13:58:55 +00:00
|
|
|
|
|
|
|
set -g __fish_git_prompt_status_order untrackedfiles stagedstate
|
|
|
|
fish_git_prompt
|
|
|
|
echo
|
|
|
|
#CHECK: (newbranch %+)
|
|
|
|
|
|
|
|
set -g __fish_git_prompt_status_order untrackedfiles
|
|
|
|
fish_git_prompt
|
|
|
|
echo
|
|
|
|
#CHECK: (newbranch %)
|
2021-12-27 01:25:20 +00:00
|
|
|
|
2022-06-01 15:08:33 +00:00
|
|
|
set -e __fish_git_prompt_showuntrackedfiles
|
|
|
|
set -e __fish_git_prompt_status_order
|
|
|
|
|
|
|
|
git -c user.email=banana@example.com -c user.name=banana commit -m foo >/dev/null
|
|
|
|
fish_git_prompt
|
|
|
|
echo
|
|
|
|
#CHECK: (newbranch)
|
|
|
|
|
|
|
|
echo "test" > foo
|
|
|
|
fish_git_prompt
|
|
|
|
echo
|
|
|
|
#CHECK: (newbranch *)
|
|
|
|
|
|
|
|
git add foo
|
|
|
|
fish_git_prompt
|
|
|
|
echo
|
|
|
|
#CHECK: (newbranch +)
|
|
|
|
|
2023-02-15 18:32:50 +00:00
|
|
|
set -e __fish_git_prompt_showdirtystate
|
|
|
|
|
|
|
|
# Test displaying only stash count
|
|
|
|
set -g __fish_git_prompt_show_informative_status 1
|
|
|
|
set -g __fish_git_prompt_showstashstate 1
|
|
|
|
set -g __fish_git_prompt_status_order stashstate
|
|
|
|
set -g ___fish_git_prompt_char_stashstate ''
|
|
|
|
set -g ___fish_git_prompt_char_cleanstate ''
|
|
|
|
|
2023-02-15 19:11:46 +00:00
|
|
|
set -l identity -c user.email=banana@example.com -c user.name=banana
|
|
|
|
git $identity commit -m Init >/dev/null
|
2023-02-15 18:32:50 +00:00
|
|
|
echo 'changed' > foo
|
2023-02-15 19:11:46 +00:00
|
|
|
# (some git versions don't allow stash without giving an email)
|
|
|
|
git $identity stash >/dev/null
|
2023-02-15 18:32:50 +00:00
|
|
|
fish_git_prompt
|
|
|
|
echo
|
|
|
|
#CHECK: (newbranch|1)
|
|
|
|
|
2023-02-15 19:11:46 +00:00
|
|
|
git $identity stash pop >/dev/null
|
2023-02-15 18:32:50 +00:00
|
|
|
fish_git_prompt
|
|
|
|
echo
|
|
|
|
#CHECK: (newbranch)
|
|
|
|
|
|
|
|
set -e __fish_git_prompt_show_informative_status
|
|
|
|
set -e __fish_git_prompt_showstashstate
|
|
|
|
set -e __fish_git_prompt_status_order
|
|
|
|
set -e ___fish_git_prompt_char_stashstate
|
|
|
|
set -e ___fish_git_prompt_char_cleanstate
|
2022-06-01 15:08:33 +00:00
|
|
|
|
|
|
|
|
2021-12-27 01:25:20 +00:00
|
|
|
# Turn on everything and verify we correctly ignore sus config files.
|
|
|
|
set -g __fish_git_prompt_status_order stagedstate invalidstate dirtystate untrackedfiles stashstate
|
|
|
|
set -g __fish_git_prompt_showdirtystate 1
|
|
|
|
set -g __fish_git_prompt_show_informative_status 1
|
|
|
|
set -g __fish_git_prompt_showuntrackedfiles 1
|
|
|
|
rm -Rf .git *
|
|
|
|
git init >/dev/null 2>&1
|
|
|
|
echo -n > ran.txt
|
|
|
|
git config core.fsmonitor 'echo fsmonitor >> ran.txt; false'
|
|
|
|
git config core.sshCommand 'echo sshCommand >> ran.txt; false'
|
|
|
|
git config diff.external 'echo diff >> ran.txt; false'
|
|
|
|
touch untracked_file
|
|
|
|
fish_git_prompt > /dev/null
|
|
|
|
cat ran.txt # should output nothing
|
2022-03-30 16:18:53 +00:00
|
|
|
|
|
|
|
test "$(complete -C'git re ')" = "$(complete -C'git restore --staged ')"
|
|
|
|
or begin
|
|
|
|
echo -- Oops re completes unlike restore --staged
|
|
|
|
end
|
2022-06-26 20:41:44 +00:00
|
|
|
|
|
|
|
$fish -c 'complete -C "git -C ./.gi"'
|
|
|
|
# CHECK: ./.git/ Directory
|