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):
logging.debug("Fetching module: %s", str(module))
if module.source == 'svn':
result = self.svn_backend.fetch(module)
elif module.source == 'git':
elif module.source == 'git':
result = self.git_backend.fetch(module)
else:
assert module.source == 'gitsm'
......@@ -234,3 +234,14 @@ class ActionCore(Action):
self._print_file_list(mod_aux.files)
self._print_comment("# MODULE END -> %s" % mod_aux.url)
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):
return None
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"""
fetchto = module.fetchto()
logging.debug("Fetchto = '{}'".format(fetchto))
......@@ -73,9 +79,11 @@ class Git(Fetcher):
os.mkdir(fetchto)
basename = path_utils.url_basename(module.url)
mod_path = os.path.join(fetchto, basename)
assert not module.isfetched
logging.info("Fetching git module %s", mod_path)
shell.run("(cd {0} && git clone {1})".format(fetchto, module.url))
if not pull:
assert not module.isfetched
logging.info("Fetching git module %s", mod_path)
shell.run("(cd {0} && git clone {1})".format(fetchto, module.url))
checkout_id = None
if module.branch is not None:
checkout_id = module.branch
......@@ -94,6 +102,14 @@ class Git(Fetcher):
if os.system(cmd) != 0:
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:
cmd = ("(cd {0} && git submodule init &&"
"git submodule update --recursive)")
......
......@@ -75,6 +75,8 @@ def _action_runner(modules_pool):
modules_pool.makefile()
elif options.command == "fetch":
modules_pool.fetch()
elif options.command == "update":
modules_pool.update()
elif options.command == "clean":
modules_pool.clean()
elif options.command == "list-mods":
......@@ -105,6 +107,9 @@ def _get_parser():
subparsers.add_parser(
"fetch",
help="fetch and/or update all of the remote modules")
subparsers.add_parser(
"update",
help="update all of the remote modules")
subparsers.add_parser(
"clean",
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