Skip to content

Commit

Permalink
Merge pull request #83 from akretion/fix-clone-in-empty-dr
Browse files Browse the repository at this point in the history
[fix] target_dir may be an empty directory
  • Loading branch information
sbidoul authored Oct 23, 2024
2 parents 63f2ca1 + d8ccdaf commit 8288ebf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion git_aggregator/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def aggregate(self):
logger.info('Start aggregation of %s', self.cwd)
target_dir = self.cwd

is_new = not os.path.exists(target_dir)
is_new = not os.path.exists(target_dir) or os.listdir(target_dir) == []
if is_new:
cloned = self.init_repository(target_dir)

Expand Down
22 changes: 22 additions & 0 deletions tests/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,28 @@ def test_minimal(self):
last_rev = git_get_last_rev(self.cwd)
self.assertEqual(last_rev, self.commit_1_sha)

def test_empty_dir(self):
# ensure git clone in empty directory works
remotes = [{
'name': 'r1',
'url': self.url_remote1
}]
merges = [{
'remote': 'r1',
'ref': 'tag1'
}]
target = {
'remote': 'r1',
'branch': 'agg1'
}
# self.cwd should not exist yet
self.assertFalse(os.path.exists(self.cwd))
os.mkdir(self.cwd)
repo = Repo(self.cwd, remotes, merges, target)
repo.aggregate()
last_rev = git_get_last_rev(self.cwd)
self.assertEqual(last_rev, self.commit_1_sha)

def test_annotated_tag(self):
remotes = [{
'name': 'r1',
Expand Down

0 comments on commit 8288ebf

Please sign in to comment.