repos: make sure the remote url is matching the kas file

Currently the the remote URL is only set during the initial clone.
This might lead to confusion with the user as changing the URL in the kas.yml
does not get reflected and thus errors about references not found show up.

This change makes sure the URL is always set to the value specified in the
kas.yml file.

For mercurial this currently prints a warning as there is no command to change
the default path.

Signed-off-by: Pascal Bach <pascal.bach@siemens.com>
[Jan: fix up style, adjust comment on hg's set_remote_url_cmd]
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
Pascal Bach 2019-06-19 10:49:44 +02:00 committed by Jan Kiszka
parent e9659cd19b
commit 66bd078e7f

View File

@ -175,6 +175,22 @@ class RepoImpl(Repo):
logging.info('Repository %s cloned', self.name)
return retc
# Make sure the remote origin is set to the value
# in the kas file to avoid suprises
try:
(retc, output) = yield from run_cmd_async(
self.set_remote_url_cmd(),
cwd=self.path,
fail=False,
liveupdate=False)
if retc != 0:
logging.info('Changing remote URL to %s failed with error: %s',
self.effective_url, output.strip())
return retc
except NotImplementedError:
logging.warning('Repo implementation does not support changing '
'the remote url.')
# take what came out of clone and stick to that forever
if self.refspec is None:
return 0
@ -312,6 +328,9 @@ class GitRepo(RepoImpl):
return ['git', 'quiltimport', '--author', 'kas <kas@example.com>',
'--patches', path]
def set_remote_url_cmd(self):
return ['git', 'remote', 'set-url', 'origin', self.effective_url]
class MercurialRepo(RepoImpl):
"""
@ -341,3 +360,7 @@ class MercurialRepo(RepoImpl):
def apply_patches_quilt_cmd(self, path):
raise NotImplementedError()
def set_remote_url_cmd(self, url):
# TODO
raise NotImplementedError()