A console script that allows you to easily update multiple git repositories at once
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

script.py 3.5 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 fetch 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_b.add_argument(
  42. '-a', '--add', dest="bookmarks_to_add", nargs="+", metavar="path",
  43. help="add directory(s) as bookmarks")
  44. group_b.add_argument(
  45. '-d', '--delete', dest="bookmarks_to_del", nargs="+", metavar="path",
  46. help="delete bookmark(s) (leaves actual directories alone)")
  47. group_b.add_argument(
  48. '-l', '--list', dest="list_bookmarks", action="store_true",
  49. help="list current bookmarks")
  50. group_m.add_argument(
  51. '-h', '--help', action="help", help="show this help message and exit")
  52. group_m.add_argument(
  53. '-v', '--version', action="version",
  54. version="gitup version " + __version__)
  55. color_init(autoreset=True)
  56. args = parser.parse_args()
  57. update_args = args.current_only, args.rebase, args.merge
  58. print(Style.BRIGHT + "gitup" + Style.RESET_ALL + ": the git-repo-updater")
  59. print()
  60. acted = False
  61. if args.bookmarks_to_add:
  62. add_bookmarks(args.bookmarks_to_add)
  63. acted = True
  64. if args.bookmarks_to_del:
  65. delete_bookmarks(args.bookmarks_to_del)
  66. acted = True
  67. if args.list_bookmarks:
  68. list_bookmarks()
  69. acted = True
  70. if args.directories_to_update:
  71. update_directories(args.directories_to_update, update_args)
  72. acted = True
  73. if args.update or not acted:
  74. update_bookmarks(get_bookmarks(), update_args)
  75. def run():
  76. """Thin wrapper for main() that catches KeyboardInterrupts."""
  77. try:
  78. main()
  79. except KeyboardInterrupt:
  80. print("Stopped by user.")