Commit 8ce032de authored by William Kamp's avatar William Kamp

Add an update action to pull (fast forward) git modules.

parent 947c5452
...@@ -83,7 +83,7 @@ class ActionCore(Action): ...@@ -83,7 +83,7 @@ class ActionCore(Action):
logging.debug("Fetching module: %s", str(module)) logging.debug("Fetching module: %s", str(module))
if module.source == 'svn': if module.source == 'svn':
result = self.svn_backend.fetch(module) result = self.svn_backend.fetch(module)
elif module.source == 'git': elif module.source == 'git':
result = self.git_backend.fetch(module) result = self.git_backend.fetch(module)
else: else:
assert module.source == 'gitsm' assert module.source == 'gitsm'
...@@ -234,3 +234,14 @@ class ActionCore(Action): ...@@ -234,3 +234,14 @@ class ActionCore(Action):
self._print_file_list(mod_aux.files) self._print_file_list(mod_aux.files)
self._print_comment("# MODULE END -> %s" % mod_aux.url) self._print_comment("# MODULE END -> %s" % mod_aux.url)
self._print_comment("") self._print_comment("")
def update(self):
"""Pull updates to modules"""
for mod_aux in self.manifests:
if not mod_aux.isfetched:
logging.warning("Module not fetched: %s", mod_aux.url)
self._print_comment("# MODULE UNFETCHED! -> %s" % mod_aux.url)
else:
if mod_aux.source == 'git':
self.git_backend.update(mod_aux)
\ No newline at end of file
...@@ -66,6 +66,12 @@ class Git(Fetcher): ...@@ -66,6 +66,12 @@ class Git(Fetcher):
return None return None
def fetch(self, module): def fetch(self, module):
return self._fetch_or_fastforward(module, pull=False)
def update(self, module):
return self._fetch_or_fastforward(module, pull=True)
def _fetch_or_fastforward(self, module, pull):
"""Get the code from the remote Git repository""" """Get the code from the remote Git repository"""
fetchto = module.fetchto() fetchto = module.fetchto()
logging.debug("Fetchto = '{}'".format(fetchto)) logging.debug("Fetchto = '{}'".format(fetchto))
...@@ -73,9 +79,11 @@ class Git(Fetcher): ...@@ -73,9 +79,11 @@ class Git(Fetcher):
os.mkdir(fetchto) os.mkdir(fetchto)
basename = path_utils.url_basename(module.url) basename = path_utils.url_basename(module.url)
mod_path = os.path.join(fetchto, basename) mod_path = os.path.join(fetchto, basename)
assert not module.isfetched if not pull:
logging.info("Fetching git module %s", mod_path) assert not module.isfetched
shell.run("(cd {0} && git clone {1})".format(fetchto, module.url)) logging.info("Fetching git module %s", mod_path)
shell.run("(cd {0} && git clone {1})".format(fetchto, module.url))
checkout_id = None checkout_id = None
if module.branch is not None: if module.branch is not None:
checkout_id = module.branch checkout_id = module.branch
...@@ -94,6 +102,14 @@ class Git(Fetcher): ...@@ -94,6 +102,14 @@ class Git(Fetcher):
if os.system(cmd) != 0: if os.system(cmd) != 0:
return False return False
if pull:
logging.info("Fetching git module {}".format(mod_path))
cmd = "(cd {0} && git pull --ff-only)"
cmd = cmd.format(module.path, checkout_id)
logging.info(("Executing {}".format(cmd))
if os.system(cmd) != 0:
return False
if self.submodule and not module.isfetched: if self.submodule and not module.isfetched:
cmd = ("(cd {0} && git submodule init &&" cmd = ("(cd {0} && git submodule init &&"
"git submodule update --recursive)") "git submodule update --recursive)")
......
...@@ -75,6 +75,8 @@ def _action_runner(modules_pool): ...@@ -75,6 +75,8 @@ def _action_runner(modules_pool):
modules_pool.makefile() modules_pool.makefile()
elif options.command == "fetch": elif options.command == "fetch":
modules_pool.fetch() modules_pool.fetch()
elif options.command == "update":
modules_pool.update()
elif options.command == "clean": elif options.command == "clean":
modules_pool.clean() modules_pool.clean()
elif options.command == "list-mods": elif options.command == "list-mods":
...@@ -105,6 +107,9 @@ def _get_parser(): ...@@ -105,6 +107,9 @@ def _get_parser():
subparsers.add_parser( subparsers.add_parser(
"fetch", "fetch",
help="fetch and/or update all of the remote modules") help="fetch and/or update all of the remote modules")
subparsers.add_parser(
"update",
help="update all of the remote modules")
subparsers.add_parser( subparsers.add_parser(
"clean", "clean",
help="clean all of the already fetched remote modules") help="clean all of the already fetched remote modules")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment