A console script that allows you to easily update multiple git repositories at once
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

script.py 3.6 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # -*- coding: utf-8 -*-
  2. #
  3. # Copyright (C) 2011-2014 Ben Kurtovic <ben.kurtovic@gmail.com>
  4. # See the LICENSE file for details.
  5. from __future__ import print_function
  6. import argparse
  7. from colorama import init as color_init, Style
  8. from . import __version__, __email__
  9. from .config import (get_bookmarks, add_bookmarks, delete_bookmarks,
  10. list_bookmarks)
  11. from .update import update_bookmarks, update_directories
  12. def main():
  13. """Parse arguments and then call the appropriate function(s)."""
  14. parser = argparse.ArgumentParser(
  15. description="""Easily update multiple git repositories at once.""",
  16. epilog="""
  17. Both relative and absolute paths are accepted by all arguments.
  18. Questions? Comments? Email the author at {0}.""".format(__email__),
  19. add_help=False)
  20. group_u = parser.add_argument_group("updating repositories")
  21. group_b = parser.add_argument_group("bookmarking")
  22. group_m = parser.add_argument_group("miscellaneous")
  23. rebase_or_merge = group_u.add_mutually_exclusive_group()
  24. group_u.add_argument(
  25. 'directories_to_update', nargs="*", metavar="path",
  26. help="""update all repositories in this directory (or the directory
  27. itself, if it is a repo)""")
  28. group_u.add_argument(
  29. '-u', '--update', action="store_true", help="""update all bookmarks
  30. (default behavior when called without arguments)""")
  31. group_u.add_argument(
  32. '-c', '--current-only', action="store_true", help="""only pull the
  33. remote tracked by the current branch instead of all remotes""")
  34. rebase_or_merge.add_argument(
  35. '-r', '--rebase', action="store_true", help="""always rebase upstream
  36. branches instead of following `pull.rebase` and `branch.<name>.rebase`
  37. in git config (like `git pull --rebase=preserve`)""")
  38. rebase_or_merge.add_argument(
  39. '-m', '--merge', action="store_true", help="""like --rebase, but merge
  40. instead""")
  41. group_u.add_argument(
  42. '-v', '--verbose', action="store_true", help="""show more detailed
  43. information while updating""")
  44. group_b.add_argument(
  45. '-a', '--add', dest="bookmarks_to_add", nargs="+", metavar="path",
  46. help="add directory(s) as bookmarks")
  47. group_b.add_argument(
  48. '-d', '--delete', dest="bookmarks_to_del", nargs="+", metavar="path",
  49. help="delete bookmark(s) (leaves actual directories alone)")
  50. group_b.add_argument(
  51. '-l', '--list', dest="list_bookmarks", action="store_true",
  52. help="list current bookmarks")
  53. group_m.add_argument(
  54. '-h', '--help', action="help", help="show this help message and exit")
  55. group_m.add_argument(
  56. '-V', '--version', action="version",
  57. version="gitup version " + __version__)
  58. color_init(autoreset=True)
  59. args = parser.parse_args()
  60. update_args = args.current_only, args.rebase, args.merge, args.verbose
  61. print(Style.BRIGHT + "gitup" + Style.RESET_ALL + ": the git-repo-updater")
  62. print()
  63. acted = False
  64. if args.bookmarks_to_add:
  65. add_bookmarks(args.bookmarks_to_add)
  66. acted = True
  67. if args.bookmarks_to_del:
  68. delete_bookmarks(args.bookmarks_to_del)
  69. acted = True
  70. if args.list_bookmarks:
  71. list_bookmarks()
  72. acted = True
  73. if args.directories_to_update:
  74. update_directories(args.directories_to_update, update_args)
  75. acted = True
  76. if args.update or not acted:
  77. update_bookmarks(get_bookmarks(), update_args)
  78. def run():
  79. """Thin wrapper for main() that catches KeyboardInterrupts."""
  80. try:
  81. main()
  82. except KeyboardInterrupt:
  83. print("Stopped by user.")