Browse Source

Add some new arguments.

tags/v0.2
Ben Kurtovic 10 years ago
parent
commit
48ebdf0264
2 changed files with 32 additions and 13 deletions
  1. +26
    -9
      gitup/script.py
  2. +6
    -4
      gitup/update.py

+ 26
- 9
gitup/script.py View File

@@ -17,7 +17,7 @@ from .update import update_bookmarks, update_directories
def main():
"""Parse arguments and then call the appropriate function(s)."""
parser = argparse.ArgumentParser(
description="""Easily pull to multiple git repositories at once.""",
description="""Easily update multiple git repositories at once.""",
epilog="""
Both relative and absolute paths are accepted by all arguments.
Questions? Comments? Email the author at {0}.""".format(__email__),
@@ -26,6 +26,7 @@ def main():
group_u = parser.add_argument_group("updating repositories")
group_b = parser.add_argument_group("bookmarking")
group_m = parser.add_argument_group("miscellaneous")
rebase_or_merge = group_u.add_mutually_exclusive_group()

group_u.add_argument(
'directories_to_update', nargs="*", metavar="path",
@@ -34,6 +35,20 @@ def main():
group_u.add_argument(
'-u', '--update', action="store_true", help="""update all bookmarks
(default behavior when called without arguments)""")
group_u.add_argument(
'-c', '--current-only', action="store_true", help="""only pull the
remote tracked by the current branch instead of all remotes""")
rebase_or_merge.add_argument(
'-r', '--rebase', action="store_true", help="""always rebase upstream
branches instead of following `pull.rebase` and `branch.<name>.rebase`
in git config (like `git pull --rebase`)""")
rebase_or_merge.add_argument(
'-m', '--merge', action="store_true", help="""like --rebase, but merge
instead""")
group_u.add_argument(
'-v', '--verbose', action="store_true", help="""show more detailed
information while updating""")

group_b.add_argument(
'-a', '--add', dest="bookmarks_to_add", nargs="+", metavar="path",
help="add directory(s) as bookmarks")
@@ -46,29 +61,31 @@ def main():
group_m.add_argument(
'-h', '--help', action="help", help="show this help message and exit")
group_m.add_argument(
'-v', '--version', action="version",
'-V', '--version', action="version",
version="gitup version " + __version__)

color_init(autoreset=True)
args = parser.parse_args()
update_args = args.current_only, args.rebase, args.merge, args.verbose

print(Style.BRIGHT + "gitup" + Style.RESET_ALL + ": the git-repo-updater")
print()

acted = False
if args.bookmarks_to_add:
add_bookmarks(args.bookmarks_to_add)
acted = True
if args.bookmarks_to_del:
delete_bookmarks(args.bookmarks_to_del)
acted = True
if args.list_bookmarks:
list_bookmarks()
acted = True
if args.directories_to_update:
update_directories(args.directories_to_update)
if args.update:
update_bookmarks(get_bookmarks())

# If they did not tell us to do anything, automatically update bookmarks:
if not any(vars(args).values()):
update_bookmarks(get_bookmarks())
update_directories(args.directories_to_update, *update_args)
acted = True
if args.update or not acted:
update_bookmarks(get_bookmarks(), *update_args)

def run():
"""Thin wrapper for main() that catches KeyboardInterrupts."""


+ 6
- 4
gitup/update.py View File

@@ -21,7 +21,7 @@ RESET = Style.RESET_ALL
INDENT1 = " " * 3
INDENT2 = " " * 7

def _update_repository(repo):
def _update_repository(repo, rebase=True):
"""Update a single git repository by fetching remotes and rebasing/merging.

The specific actions depends on ...
@@ -31,7 +31,7 @@ def _update_repository(repo):
ref = repo.head.ref.tracking_branch()
if ref:
remote = repo.remotes[ref.remote_name]
else:
# else:
###

remote.fetch()
@@ -129,7 +129,8 @@ def _update_directory(path, is_bookmark=False):
print(long_name, "is a git repository:")
_update_repository(repo)

def update_bookmarks(bookmarks):
def update_bookmarks(bookmarks, current_only=False, rebase=False, merge=False,
verbose=False):
"""Loop through and update all bookmarks."""
if bookmarks:
for path, name in bookmarks:
@@ -137,7 +138,8 @@ def update_bookmarks(bookmarks):
else:
print("You don't have any bookmarks configured! Get help with 'gitup -h'.")

def update_directories(paths):
def update_directories(paths, current_only=False, rebase=False, merge=False,
verbose=False):
"""Update a list of directories supplied by command arguments."""
for path in paths:
_update_directory(os.path.abspath(path), is_bookmark=False)

Loading…
Cancel
Save