diff options
Diffstat (limited to '')
-rw-r--r-- | cgitize/cgit.py | 12 | ||||
-rw-r--r-- | cgitize/main.py | 4 |
2 files changed, 14 insertions, 2 deletions
diff --git a/cgitize/cgit.py b/cgitize/cgit.py index 7c6e6f6..7c867bc 100644 --- a/cgitize/cgit.py +++ b/cgitize/cgit.py @@ -52,9 +52,10 @@ class CGitRCWriter: class CGitRepositories: - def __init__(self, dir, cgit_server): + def __init__(self, dir, cgit_server, force=False): self.dir = self._make_dir(dir) self.cgitrc = CGitRCWriter(cgit_server) + self.force = force @staticmethod def _make_dir(rel_path): @@ -100,6 +101,10 @@ class CGitRepositories: # directory already with a different upstream; something's # wrong, fix it manually. logging.warning("Existing repository '%s' doesn't match the specified clone URL: %s", repo.repo_id, repo.clone_url) + if self.force: + # Unless --force was specified, in which case we overwrite + # the repository. + return self._fix_upstream_url(repo) and self._update_existing(repo) return False # The local directory contains the local version of the upstream, @@ -118,6 +123,11 @@ class CGitRepositories: with Git.setup_auth(repo): return Git.check('clone', '--mirror', '--quiet', repo.clone_url, repo_dir) + def _fix_upstream_url(self, repo): + repo_dir = self.get_repo_dir(repo) + with chdir(repo_dir): + return Git.check('remote', 'set-url', 'origin', repo.clone_url) + def _update_existing(self, repo): logging.info("Updating repository '%s'", repo.repo_id) repo_dir = self.get_repo_dir(repo) diff --git a/cgitize/main.py b/cgitize/main.py index 60a5e70..7d2632d 100644 --- a/cgitize/main.py +++ b/cgitize/main.py @@ -22,6 +22,8 @@ def parse_args(argv=None): parser.add_argument('--repo', metavar='REPO_ID', nargs='*', dest='repos', help='repos to pull') + parser.add_argument('--force', '-f', action='store_true', + help='overwrite existing repositories') parser.add_argument('--verbose', '-v', action='store_true', help='verbose log output') return parser.parse_args(argv) @@ -33,7 +35,7 @@ def main(args=None): config = Config.read(args.config) my_repos = config.import_my_repos() cgit_server = CGitServer(config.clone_url) - output = CGitRepositories(config.output, cgit_server) + output = CGitRepositories(config.output, cgit_server, force=args.force) success = True for repo in my_repos: if args.repos is None or repo.repo_id in args.repos: |