Skip to content

Commit f949844

Browse files
Miklos Vajnagitster
authored andcommitted
contrib/hooks: add an example pre-auto-gc hook
It disables git-gc --auto when you are running Linux and you are not on AC. Signed-off-by: Miklos Vajna <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0b85d92 commit f949844

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

contrib/hooks/pre-auto-gc-battery

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/sh
2+
#
3+
# An example hook script to verify if you are on battery, in case you
4+
# are running Linux. Called by git-gc --auto with no arguments. The hook
5+
# should exit with non-zero status after issuing an appropriate message
6+
# if it wants to stop the auto repacking.
7+
#
8+
# This hook is stored in the contrib/hooks directory. Your distribution
9+
# may have put this somewhere else. If you want to use this hook, you
10+
# should make this script executable then link to it in the repository
11+
# you would like to use it in.
12+
#
13+
# For example, if the hook is stored in
14+
# /usr/share/git-core/contrib/hooks/pre-auto-gc-battery:
15+
#
16+
# chmod a+x pre-auto-gc-battery
17+
# cd /path/to/your/repository.git
18+
# ln -sf /usr/share/git-core/contrib/hooks/pre-auto-gc-battery \
19+
# hooks/pre-auto-gc
20+
21+
if test -x /sbin/on_ac_power && /sbin/on_ac_power
22+
then
23+
exit 0
24+
elif test "$(cat /sys/class/power_supply/AC/online 2>/dev/null)" = 1
25+
then
26+
exit 0
27+
elif grep -q 'on-line' /proc/acpi/ac_adapter/AC/state 2>/dev/null
28+
then
29+
exit 0
30+
elif grep -q '0x01$' /proc/apm 2>/dev/null
31+
then
32+
exit 0
33+
fi
34+
35+
echo "Auto packing deferred; not on AC"
36+
exit 1

0 commit comments

Comments
 (0)