forked from GitoxideLabs/gitoxide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.sh
79 lines (73 loc) · 1.91 KB
/
helpers.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Must be sourced into the main journey test
function set-static-git-environment() {
set -a
export GIT_AUTHOR_DATE="2020-09-09 09:06:03 +0800"
export GIT_COMMITTER_DATE="${GIT_AUTHOR_DATE}"
export GIT_AUTHOR_NAME="Sebastian Thiel"
export GIT_COMMITTER_NAME="${GIT_AUTHOR_NAME}"
export GIT_AUTHOR_EMAIL="git@example.com"
export GIT_COMMITTER_EMAIL="${GIT_AUTHOR_EMAIL}"
set +a
}
function remove-paths() {
sed -E 's#/.*#"#g'
}
function repo-with-remotes() {
if [[ $((($# - 1) % 2)) != 0 ]] || [[ $# = 0 ]]; then
echo "need <path> (<remote> <url>)[,...] tuples"
exit 42
fi
mkdir -p "$1"
(
cd "$1"
shift
git init
while [[ $# != 0 ]]; do
git remote add "$1" "$2"
shift 2
done
git config commit.gpgsign false
git config tag.gpgsign false
touch a
git add a
git commit -m "non-bare"
) &>/dev/null
}
function small-repo-in-sandbox() {
sandbox
{
git init
git checkout -b main
git config commit.gpgsign false
git config tag.gpgsign false
touch a
git add a
git commit -m "first"
git tag unannotated
touch b
git add b
git commit -m "second"
git tag annotated -m "tag message"
git branch dev
echo hi >> b
git commit -am "third"
} &>/dev/null
}
function launch-git-daemon() {
local port=9418
if nc -z localhost "$port"; then
echo "Port $port should not have been open before this test's run of the git daemon!" >&2
return 1
fi
if pgrep git-daemon; then
# TODO: This may be over-broad, as we only need port 9418 (on whatever of 127.0.0.1 and ::1 exist).
echo 'An instance of git-daemon seems to be running already!' >&2
return 1
fi
git -c uploadpack.allowRefInWant=true daemon --verbose --base-path=. --export-all --user-path &>/dev/null &
daemon_pid=$!
while ! nc -z localhost "$port"; do
sleep 0.1
done
trap 'kill $daemon_pid' EXIT
}