Skip to content

Commit a8014a8

Browse files
committed
add usr/bin/p-cache-git
Ref: pytest-dev/pytest#5301
1 parent e536c9c commit a8014a8

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

usr/bin/p-cache-git

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/sh
2+
# Wrapper around git in .pytest_cache/v/cache.
3+
#
4+
# This is meant to be useful to stash/save/restore the cache, e.g. when using
5+
# the `--lf` (last-failed) mode etc.
6+
#
7+
# NOTE: you can also use `git -C .pytest_cache/v/cache …` directly, of course..
8+
#
9+
# TODO:
10+
# - short action names to stash/pop?
11+
# - completion (IIRC this requires fix for -C in zsh?)
12+
13+
set -e
14+
# set -x
15+
16+
error() {
17+
echo "$@"
18+
exit 64
19+
}
20+
21+
root=".pytest_cache/v/cache"
22+
cdup="$(git rev-parse --show-cdup)"
23+
if [ -n "$cdup" ]; then
24+
root="$cdup/$root"
25+
fi
26+
27+
if ! [ -d "$root" ]; then
28+
error "Directory $root does not exist"
29+
fi
30+
31+
cd "$root"
32+
33+
if ! [ -e ".git" ]; then
34+
git init .
35+
git commit --allow-empty -m "init"
36+
git add --all .
37+
git commit -m "initial state"
38+
fi
39+
40+
git "$@"

0 commit comments

Comments
 (0)