From c855387dc4a5582d00ad3319193628ba68bf9d36 Mon Sep 17 00:00:00 2001 From: Matthew Thompson Date: Wed, 15 Jul 2020 16:45:26 -0400 Subject: [PATCH] Fixes #70. Add mepo pull, pull-all, fetch-all --- mepo | 8 ++------ mepo.d/cmdline/parser.py | 25 ++++++++++++++++++++++++- mepo.d/command/fetch-all/fetch-all.py | 11 +++++++++++ mepo.d/command/pull-all/pull-all.py | 22 ++++++++++++++++++++++ mepo.d/command/pull/pull.py | 16 ++++++++++++++++ 5 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 mepo.d/command/fetch-all/fetch-all.py create mode 100644 mepo.d/command/pull-all/pull-all.py create mode 100644 mepo.d/command/pull/pull.py diff --git a/mepo b/mepo index 0bcf725..c53176f 100755 --- a/mepo +++ b/mepo @@ -12,10 +12,6 @@ if sys.version_info < (3, 6, 0): MEPO_D = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mepo.d') sys.path.insert(0, MEPO_D) -# Call top level function -from main import main -try: +if __name__ == '__main__': + from main import main main() -except Exception as e: - traceback.print_exc() - sys.exit(1) diff --git a/mepo.d/cmdline/parser.py b/mepo.d/cmdline/parser.py index 86917aa..01d1ff9 100644 --- a/mepo.d/cmdline/parser.py +++ b/mepo.d/cmdline/parser.py @@ -22,11 +22,14 @@ def parse(self): self.__status() self.__diff() self.__fetch() + self.__fetch_all() self.__checkout() self.__checkout_if_exists() self.__branch() self.__stash() self.__develop() + self.__pull() + self.__pull_all() self.__compare() self.__whereis() self.__stage() @@ -118,6 +121,15 @@ def __fetch(self): fetch.add_argument('--prune','-p', action = 'store_true', help = 'Prune remote branches.') fetch.add_argument('--tags','-t', action = 'store_true', help = 'Fetch tags.') + def __fetch_all(self): + fetch_all = self.subparsers.add_parser( + 'fetch-all', + description = 'Download objects and refs from all components. ' + 'Specifying --all causes all remotes to be fetched.') + fetch_all.add_argument('--all', action = 'store_true', help = 'Fetch all remotes.') + fetch_all.add_argument('--prune','-p', action = 'store_true', help = 'Prune remote branches.') + fetch_all.add_argument('--tags','-t', action = 'store_true', help = 'Fetch tags.') + def __branch(self): branch = self.subparsers.add_parser('branch') MepoBranchArgParser(branch) @@ -133,7 +145,18 @@ def __develop(self): 'develop', description = "Checkout current version of 'develop' branches of specified components") develop.add_argument('comp_name', metavar = 'comp-name', nargs = '+', default = None) - + + def __pull(self): + pull = self.subparsers.add_parser( + 'pull', + description = "Pull branches of specified components") + pull.add_argument('comp_name', metavar = 'comp-name', nargs = '+', default = None) + + def __pull_all(self): + pull_all = self.subparsers.add_parser( + 'pull-all', + description = "Pull branches of all components (only those in non-detached HEAD state)") + def __compare(self): compare = self.subparsers.add_parser( 'compare', diff --git a/mepo.d/command/fetch-all/fetch-all.py b/mepo.d/command/fetch-all/fetch-all.py new file mode 100644 index 0000000..c718a95 --- /dev/null +++ b/mepo.d/command/fetch-all/fetch-all.py @@ -0,0 +1,11 @@ +from state.state import MepoState +from repository.git import GitRepository +from utilities import colors + +def run(args): + allcomps = MepoState.read_state() + for comp in allcomps: + git = GitRepository(comp.remote, comp.local) + print("Fetching %s" % + colors.YELLOW + comp.name + colors.RESET) + git.fetch(args) diff --git a/mepo.d/command/pull-all/pull-all.py b/mepo.d/command/pull-all/pull-all.py new file mode 100644 index 0000000..6900206 --- /dev/null +++ b/mepo.d/command/pull-all/pull-all.py @@ -0,0 +1,22 @@ +from state.state import MepoState +from repository.git import GitRepository +from state.component import MepoVersion +from utilities import colors +from pprint import pprint + +def run(args): + allcomps = MepoState.read_state() + detached_comps=[] + for comp in allcomps: + git = GitRepository(comp.remote, comp.local) + name, tYpe, detached = MepoVersion(*git.get_version()) + if detached: + detached_comps.append(comp.name) + else: + print("Pulling branch %s in %s " % + (colors.YELLOW + name + colors.RESET, + colors.RESET + comp.name + colors.RESET)) + git.pull() + if len(detached_comps) > 0: + print("The following repos were not pulled (detached HEAD): %s" % (', '.join(map(str, detached_comps)))) + diff --git a/mepo.d/command/pull/pull.py b/mepo.d/command/pull/pull.py new file mode 100644 index 0000000..fefd72b --- /dev/null +++ b/mepo.d/command/pull/pull.py @@ -0,0 +1,16 @@ +from state.state import MepoState +from utilities import verify +from repository.git import GitRepository +from state.component import MepoVersion + +def run(args): + allcomps = MepoState.read_state() + verify.valid_components(args.comp_name, allcomps) + comps2dev = [x for x in allcomps if x.name in args.comp_name] + for comp in comps2dev: + git = GitRepository(comp.remote, comp.local) + is_detached = MepoVersion(*git.get_version()).detached + if is_detached: + raise Exception('{} has detached head! Cannot stage.'.format(comp.name)) + else: + git.pull()