tide/tests/_tide_item_git.test.fish

107 lines
2.1 KiB
Fish
Raw Normal View History

2021-02-11 02:45:36 +03:00
# RUN: %fish %s
2022-09-05 19:56:50 +03:00
_tide_parent_dirs
2021-02-11 02:45:36 +03:00
function _git
2021-02-11 05:05:32 +03:00
git $argv >/dev/null 2>&1
end
function _git_item
2021-02-11 02:45:36 +03:00
_tide_decolor (_tide_item_git)
end
2021-02-11 03:13:16 +03:00
# Create directory
set -l dir (mktemp -d)
mkdir -p $dir/{normal-repo, bare-repo, submodule-repo, massive-status-repo}
2021-02-11 03:13:16 +03:00
# Not in git repo
2021-04-14 07:57:11 +03:00
cd $dir
2021-02-11 05:05:32 +03:00
_git_item # CHECK:
2021-02-11 03:13:16 +03:00
2021-04-14 07:57:11 +03:00
# -------- normal repo tests --------
cd ./normal-repo
2021-02-11 05:05:32 +03:00
_git init
2021-04-14 07:57:11 +03:00
_git branch -m main
2021-02-11 02:45:36 +03:00
# Branch
2021-02-11 05:05:32 +03:00
_git_item # CHECK: main
2021-02-11 02:45:36 +03:00
2021-04-14 07:57:11 +03:00
# .git dir
cd .git/
_git_item # CHECK: main
cd ..
2021-02-11 02:45:36 +03:00
# Untracked
2022-04-22 18:16:05 +03:00
echo >foo
2021-02-11 05:05:32 +03:00
_git_item # CHECK: main ?1
2021-02-11 02:45:36 +03:00
# Staged
2021-02-11 05:05:32 +03:00
_git add foo
_git_item # CHECK: main +1
2021-02-11 02:45:36 +03:00
2021-02-11 05:07:24 +03:00
git config --local user.email "you@example.com"
git config --local user.name "Your Name"
2021-02-11 05:05:32 +03:00
_git commit -am 'Add foo'
2021-02-11 02:45:36 +03:00
# Dirty
2021-02-11 05:05:32 +03:00
echo hello >foo
_git_item # CHECK: main !1
2021-02-11 02:45:36 +03:00
# Stash
2021-02-11 05:05:32 +03:00
_git stash
_git_item # CHECK: main *1
2021-02-11 02:45:36 +03:00
2021-02-11 05:05:32 +03:00
_git stash pop
_git commit -am 'Append hello to foo'
2021-02-11 02:45:36 +03:00
# SHA
2021-02-11 05:05:32 +03:00
_git checkout HEAD~
_git_item # CHECK: {{@\w*}}
2021-04-14 07:57:11 +03:00
# --- Long branches ---
2021-10-31 20:53:43 +03:00
_git checkout main
_git checkout -b very_long_branch_name
2022-01-05 02:04:55 +03:00
set -lx tide_git_truncation_length 10
set -lx tide_git_truncation_strategy
_git_item # CHECK: very_long…
set -lx tide_git_truncation_strategy l
_git_item # CHECK: …anch_name
2021-10-31 20:53:43 +03:00
# Branch same length as tide_git_truncation_length
_git checkout -b 10charhere
_git_item # CHECK: 10charhere
2021-10-31 20:53:43 +03:00
2021-04-14 07:57:11 +03:00
# -------- bare repo test --------
cd $dir/bare-repo
_git init --bare
_git branch -m main
_git_item # CHECK: main
2022-04-22 18:16:05 +03:00
# ------ submodule repo test ------
cd $dir/submodule-repo
_git init
_git branch -m main
# temporary workaround for git bug https://bugs.launchpad.net/ubuntu/+source/git/+bug/1993586
_git -c protocol.file.allow=always submodule add $dir/normal-repo
2022-04-22 18:16:05 +03:00
_git_item # CHECK: main +2
cd normal-repo
_git_item # CHECK: 10charhere
2022-04-22 18:16:05 +03:00
cd ..
echo >new_main_git_file
_git_item # CHECK: main +2 ?1
echo >normal-repo/new_submodule_file
_git_item # CHECK: main +2 !1 ?1
cd normal-repo
_git_item # CHECK: 10charhere ?1
2022-04-22 18:16:05 +03:00
# --- Massive git status ---
cd $dir/massive-status-repo
_git init
_git branch -m main
mock git "--no-optional-locks status --porcelain" "string repeat -n100000 'D some-file-name'\n"
_git_item # CHECK: main +100000
2022-04-22 18:16:05 +03:00
# ------ cleanup ------
command rm -r $dir