Miklos Vajna | f949844 | 2008-04-02 21:35:11 +0200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # An example hook script to verify if you are on battery, in case you |
Jonathan del Strother | c33912a | 2008-09-30 00:36:28 +0100 | [diff] [blame] | 4 | # are running Linux or OS X. Called by git-gc --auto with no arguments. |
| 5 | # The hook should exit with non-zero status after issuing an appropriate |
| 6 | # message if it wants to stop the auto repacking. |
Miklos Vajna | f949844 | 2008-04-02 21:35:11 +0200 | [diff] [blame] | 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 | # |
Miklos Vajna | f949844 | 2008-04-02 21:35:11 +0200 | [diff] [blame] | 16 | # cd /path/to/your/repository.git |
| 17 | # ln -sf /usr/share/git-core/contrib/hooks/pre-auto-gc-battery \ |
| 18 | # hooks/pre-auto-gc |
| 19 | |
Adam Borowski | 781262c | 2018-02-28 23:12:04 +0100 | [diff] [blame] | 20 | if test -x /sbin/on_ac_power && (/sbin/on_ac_power;test $? -ne 1) |
Miklos Vajna | f949844 | 2008-04-02 21:35:11 +0200 | [diff] [blame] | 21 | then |
| 22 | exit 0 |
| 23 | elif test "$(cat /sys/class/power_supply/AC/online 2>/dev/null)" = 1 |
| 24 | then |
| 25 | exit 0 |
| 26 | elif grep -q 'on-line' /proc/acpi/ac_adapter/AC/state 2>/dev/null |
| 27 | then |
| 28 | exit 0 |
| 29 | elif grep -q '0x01$' /proc/apm 2>/dev/null |
| 30 | then |
| 31 | exit 0 |
Miklos Vajna | 84ed4c5 | 2008-10-14 16:42:45 +0200 | [diff] [blame] | 32 | elif grep -q "AC Power \+: 1" /proc/pmu/info 2>/dev/null |
| 33 | then |
| 34 | exit 0 |
Jonathan del Strother | c33912a | 2008-09-30 00:36:28 +0100 | [diff] [blame] | 35 | elif test -x /usr/bin/pmset && /usr/bin/pmset -g batt | |
Panagiotis Astithas | c54c7b3 | 2015-06-11 17:37:25 +0300 | [diff] [blame] | 36 | grep -q "drawing from 'AC Power'" |
Jonathan del Strother | c33912a | 2008-09-30 00:36:28 +0100 | [diff] [blame] | 37 | then |
| 38 | exit 0 |
Miklos Vajna | f949844 | 2008-04-02 21:35:11 +0200 | [diff] [blame] | 39 | fi |
| 40 | |
| 41 | echo "Auto packing deferred; not on AC" |
| 42 | exit 1 |