A console script that allows you to easily update multiple git repositories at once
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

94 Zeilen
3.5 KiB

  1. # -*- coding: utf-8 -*-
  2. #
  3. # Copyright (C) 2011-2015 Ben Kurtovic <ben.kurtovic@gmail.com>
  4. # Released under the terms of the MIT License. See LICENSE for details.
  5. from __future__ import print_function
  6. import argparse
  7. from colorama import init as color_init, Style
  8. from . import __version__
  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. Direct bug reports and feature requests to:
  19. https://github.com/earwig/git-repo-updater.""",
  20. add_help=False)
  21. group_u = parser.add_argument_group("updating repositories")
  22. group_b = parser.add_argument_group("bookmarking")
  23. group_m = parser.add_argument_group("miscellaneous")
  24. rebase_or_merge = group_u.add_mutually_exclusive_group()
  25. group_u.add_argument(
  26. 'directories_to_update', nargs="*", metavar="path",
  27. help="""update all repositories in this directory (or the directory
  28. itself, if it is a repo)""")
  29. group_u.add_argument(
  30. '-u', '--update', action="store_true", help="""update all bookmarks
  31. (default behavior when called without arguments)""")
  32. group_u.add_argument(
  33. '-c', '--current-only', action="store_true", help="""only fetch the
  34. remote tracked by the current branch instead of all remotes""")
  35. rebase_or_merge.add_argument(
  36. '-r', '--rebase', action="store_true", help="""always rebase upstream
  37. branches instead of following `pull.rebase` and `branch.<name>.rebase`
  38. in git config (behaves like `git pull --rebase=preserve`)""")
  39. rebase_or_merge.add_argument(
  40. '-m', '--merge', action="store_true", help="""like --rebase, but merge
  41. instead""")
  42. group_b.add_argument(
  43. '-a', '--add', dest="bookmarks_to_add", nargs="+", metavar="path",
  44. help="add directory(s) as bookmarks")
  45. group_b.add_argument(
  46. '-d', '--delete', dest="bookmarks_to_del", nargs="+", metavar="path",
  47. help="delete bookmark(s) (leaves actual directories alone)")
  48. group_b.add_argument(
  49. '-l', '--list', dest="list_bookmarks", action="store_true",
  50. help="list current bookmarks")
  51. group_m.add_argument(
  52. '-h', '--help', action="help", help="show this help message and exit")
  53. group_m.add_argument(
  54. '-v', '--version', action="version",
  55. version="gitup " + __version__)
  56. color_init(autoreset=True)
  57. args = parser.parse_args()
  58. update_args = args.current_only, args.rebase, args.merge
  59. print(Style.BRIGHT + "gitup" + Style.RESET_ALL + ": the git-repo-updater")
  60. print()
  61. acted = False
  62. if args.bookmarks_to_add:
  63. add_bookmarks(args.bookmarks_to_add)
  64. acted = True
  65. if args.bookmarks_to_del:
  66. delete_bookmarks(args.bookmarks_to_del)
  67. acted = True
  68. if args.list_bookmarks:
  69. list_bookmarks()
  70. acted = True
  71. if args.directories_to_update:
  72. update_directories(args.directories_to_update, update_args)
  73. acted = True
  74. if args.update or not acted:
  75. update_bookmarks(get_bookmarks(), update_args)
  76. def run():
  77. """Thin wrapper for main() that catches KeyboardInterrupts."""
  78. try:
  79. main()
  80. except KeyboardInterrupt:
  81. print("Stopped by user.")