-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-ignore
executable file
·41 lines (33 loc) · 947 Bytes
/
git-ignore
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
#!/bin/bash
# SPDX-License-Identifier: GPL-3.0-only
# Copyright 2022, Mattias Bengtsson <[email protected]>
set -e
set -o pipefail
function usage {
cat <<EOM
usage: git ignore [<path|pattern>...]
where:
<path> is a regular file path.
<pattern> is a literal gitignore pattern starting with a '/'.
EOM
}
if [[ " ${*} " == *" --help "* ]] || [[ " ${*} " == *" -h "* ]]; then
usage
exit
fi
# Check that we're inside a git worktree
git rev-parse --is-inside-work-tree >/dev/null
TOPLEVEL="$(git rev-parse --show-toplevel 2>/dev/null)"
if [ "${#}" -le 0 ]; then
usage >&2
exit 2
fi
for f in "${@}"; do
if [ "${f:0:1}" = '/' ]; then
# Take paths beginning with '/' as literal `.gitignore` lines
echo "${f}"
else
# Resolve the rest relative to the git top directory.
echo "/$(realpath --strip --relative-to="${TOPLEVEL}" "${f}")"
fi
done >> "${TOPLEVEL}/.gitignore"