A console script that allows you to easily update multiple git repositories at once
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

script.py 3.8 KiB

há 9 anos
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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, Fore, 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. 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. group_u.add_argument(
  35. '-f', '--fetch-only', action="store_true",
  36. help="only fetch remotes, don't try to fast-forward any branches")
  37. group_b.add_argument(
  38. '-a', '--add', dest="bookmarks_to_add", nargs="+", metavar="path",
  39. help="add directory(s) as bookmarks")
  40. group_b.add_argument(
  41. '-d', '--delete', dest="bookmarks_to_del", nargs="+", metavar="path",
  42. help="delete bookmark(s) (leaves actual directories alone)")
  43. group_b.add_argument(
  44. '-l', '--list', dest="list_bookmarks", action="store_true",
  45. help="list current bookmarks")
  46. group_m.add_argument(
  47. '-h', '--help', action="help", help="show this help message and exit")
  48. group_m.add_argument(
  49. '-v', '--version', action="version",
  50. version="gitup " + __version__)
  51. # TODO: deprecated arguments, for removal in v1.0:
  52. parser.add_argument(
  53. '-m', '--merge', action="store_true", help=argparse.SUPPRESS)
  54. parser.add_argument(
  55. '-r', '--rebase', action="store_true", help=argparse.SUPPRESS)
  56. color_init(autoreset=True)
  57. args = parser.parse_args()
  58. update_args = args.current_only, args.fetch_only
  59. print(Style.BRIGHT + "gitup" + Style.RESET_ALL + ": the git-repo-updater")
  60. print()
  61. # TODO: remove in v1.0
  62. if args.merge or args.rebase:
  63. print(Style.BRIGHT + Fore.YELLOW + "Warning:", "--merge and --rebase "
  64. "are deprecated. Branches are only updated if they\ntrack an "
  65. "upstream branch and can be safely fast-forwarded. Use "
  66. "--fetch-only to\navoid updating any branches.\n")
  67. acted = False
  68. if args.bookmarks_to_add:
  69. add_bookmarks(args.bookmarks_to_add)
  70. acted = True
  71. if args.bookmarks_to_del:
  72. delete_bookmarks(args.bookmarks_to_del)
  73. acted = True
  74. if args.list_bookmarks:
  75. list_bookmarks()
  76. acted = True
  77. if args.directories_to_update:
  78. update_directories(args.directories_to_update, update_args)
  79. acted = True
  80. if args.update or not acted:
  81. update_bookmarks(get_bookmarks(), update_args)
  82. def run():
  83. """Thin wrapper for main() that catches KeyboardInterrupts."""
  84. try:
  85. main()
  86. except KeyboardInterrupt:
  87. print("Stopped by user.")