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 6, 2021
1 parent 1047659 commit d99b6b9
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions git_aggregator/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ def aggregate(self):
is_new = not os.path.exists(target_dir)
if is_new:
self.init_repository(target_dir)

self._switch_to_branch(self.target['branch'])
for r in self.remotes:
self._set_remote(**r)
Expand All @@ -192,9 +191,45 @@ 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])
repository = None
for remote in self.remotes:
# If a target is defined, use it as the base repository
# If not, choose the first merge
if remote["name"] == self.target["remote"]:
repository = remote["url"]
break
elif remote["name"] == self.merges[0]["remote"]:
repository = remote["url"]
branch = self.target["branch"]
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 git-autoshare cache for %s', repository)
self.log_call(['git', 'autoshare-prefetch', repository])
cmd += ('autoshare-clone',)
else:
cmd += ('clone',)
if branch != "_git_aggregated":
cmd += ('-b', branch)
# Emtpy fetch options to use global default for 1st clone
cmd += self._fetch_options({})
cmd += (repository, target_dir)
self.log_call(cmd)

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

0 comments on commit d99b6b9

Please sign in to comment.