Skip to content

Commit

Permalink
Clone repo instead of init + fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
joao-p-marques committed Oct 5, 2021
1 parent 1047659 commit 465d84c
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions git_aggregator/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,40 @@ def aggregate(self):
self._execute_shell_command_after()
logger.info('End aggregation of %s', self.cwd)

def _use_autoshare(self):
"""Check wether `git-autoshare` is available or not"""
status, result = subprocess.getstatusoutput("git autoshare-clone")
if status == 1:
return False
logger.info("Git autoshare is installed. Taking advantage of it...")
return True

def init_repository(self, target_dir):
logger.info('Init empty git repository in %s', target_dir)
self.log_call(['git', 'init', target_dir])
# Clone from the 1st merge specified
merge = self.merges[0]
repository = None
for remote in self.remotes:
if remote["name"] == merge["remote"]:
repository = remote["url"]
branch = merge["ref"]
logger.info(
'Cloning git repository %s (branch %s) in %s',
repository,
branch,
target_dir,
)
cmd = ('git',)
if self._use_autoshare():
# Start with a prefetch to update the cache and then clone
logger.info('Updating cache for %s', repository)
self.log_call(['git', 'autoshare-prefetch', repository])
cmd += ('autoshare-clone',)
else:
cmd += ('clone',)
cmd += ('-b', branch)
cmd += self._fetch_options(merge)
cmd += (repository, target_dir)
self.log_call(cmd)

def fetch(self):
basecmd = ("git", "fetch")
Expand Down

0 comments on commit 465d84c

Please sign in to comment.