pre-auto-gc 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/sh
  2. #
  3. # An example hook script to verify if you are on battery, in case you
  4. # are running Windows, Linux or OS X. Called by git-gc --auto with no
  5. # arguments. The hook should exit with non-zero status after issuing an
  6. # appropriate message if it wants to stop the auto repacking.
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. if uname -s | grep -q "_NT-"
  21. then
  22. if test -x $SYSTEMROOT/System32/Wbem/wmic
  23. then
  24. STATUS=$(wmic path win32_battery get batterystatus /format:list | tr -d '\r\n')
  25. [ "$STATUS" = "BatteryStatus=2" ] && exit 0 || exit 1
  26. fi
  27. exit 0
  28. fi
  29. if test -x /sbin/on_ac_power && /sbin/on_ac_power
  30. then
  31. exit 0
  32. elif test "$(cat /sys/class/power_supply/AC/online 2>/dev/null)" = 1
  33. then
  34. exit 0
  35. elif grep -q 'on-line' /proc/acpi/ac_adapter/AC/state 2>/dev/null
  36. then
  37. exit 0
  38. elif grep -q '0x01$' /proc/apm 2>/dev/null
  39. then
  40. exit 0
  41. elif grep -q "AC Power \+: 1" /proc/pmu/info 2>/dev/null
  42. then
  43. exit 0
  44. elif test -x /usr/bin/pmset && /usr/bin/pmset -g batt |
  45. grep -q "drawing from 'AC Power'"
  46. then
  47. exit 0
  48. elif test -d /sys/bus/acpi/drivers/battery && test 0 = \
  49. "$(find /sys/bus/acpi/drivers/battery/ -type l | wc -l)";
  50. then
  51. # No battery exists.
  52. exit 0
  53. fi
  54. echo "Auto packing deferred; not on AC"
  55. exit 1