A console script that allows you to easily update multiple git repositories at once
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

script.py 4.4 KiB

9 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. # -*- coding: utf-8 -*-
  2. #
  3. # Copyright (C) 2011-2016 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. import os
  8. from colorama import init as color_init, Fore, Style
  9. from . import __version__
  10. from .config import (get_default_config_path, get_bookmarks, add_bookmarks,
  11. delete_bookmarks, list_bookmarks)
  12. from .update import update_bookmarks, update_directories
  13. def main():
  14. """Parse arguments and then call the appropriate function(s)."""
  15. parser = argparse.ArgumentParser(
  16. description="Easily update multiple git repositories at once.",
  17. epilog="""
  18. Both relative and absolute paths are accepted by all arguments.
  19. Direct bug reports and feature requests to
  20. https://github.com/earwig/git-repo-updater.""",
  21. add_help=False)
  22. group_u = parser.add_argument_group("updating repositories")
  23. group_b = parser.add_argument_group("bookmarking")
  24. group_m = parser.add_argument_group("miscellaneous")
  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. group_u.add_argument(
  36. '-f', '--fetch-only', action="store_true",
  37. help="only fetch remotes, don't try to fast-forward any branches")
  38. group_u.add_argument(
  39. '-p', '--prune', action="store_true", help="""after fetching, delete
  40. remote-tracking branches that no longer exist on their remote""")
  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_b.add_argument(
  51. '-b', '--bookmark-file', nargs="?", metavar="path",
  52. help="use a specific bookmark config file (default: {0})".format(
  53. get_default_config_path()))
  54. group_m.add_argument(
  55. '-h', '--help', action="help", help="show this help message and exit")
  56. group_m.add_argument(
  57. '-v', '--version', action="version",
  58. version="gitup " + __version__)
  59. # TODO: deprecated arguments, for removal in v1.0:
  60. parser.add_argument(
  61. '-m', '--merge', action="store_true", help=argparse.SUPPRESS)
  62. parser.add_argument(
  63. '-r', '--rebase', action="store_true", help=argparse.SUPPRESS)
  64. color_init(autoreset=True)
  65. args = parser.parse_args()
  66. update_args = args.current_only, args.fetch_only, args.prune
  67. print(Style.BRIGHT + "gitup" + Style.RESET_ALL + ": the git-repo-updater")
  68. print()
  69. # TODO: remove in v1.0
  70. if args.merge or args.rebase:
  71. print(Style.BRIGHT + Fore.YELLOW + "Warning:", "--merge and --rebase "
  72. "are deprecated. Branches are only updated if they\ntrack an "
  73. "upstream branch and can be safely fast-forwarded. Use "
  74. "--fetch-only to\navoid updating any branches.\n")
  75. if args.bookmark_file:
  76. args.bookmark_file = os.path.expanduser(args.bookmark_file)
  77. acted = False
  78. if args.bookmarks_to_add:
  79. add_bookmarks(args.bookmarks_to_add, args.bookmark_file)
  80. acted = True
  81. if args.bookmarks_to_del:
  82. delete_bookmarks(args.bookmarks_to_del, args.bookmark_file)
  83. acted = True
  84. if args.list_bookmarks:
  85. list_bookmarks(args.bookmark_file)
  86. acted = True
  87. if args.directories_to_update:
  88. update_directories(args.directories_to_update, update_args)
  89. acted = True
  90. if args.update or not acted:
  91. update_bookmarks(get_bookmarks(args.bookmark_file), update_args)
  92. def run():
  93. """Thin wrapper for main() that catches KeyboardInterrupts."""
  94. try:
  95. main()
  96. except KeyboardInterrupt:
  97. print("Stopped by user.")