Skip to content

Commit

Permalink
target_dir may be an empty directory
Browse files Browse the repository at this point in the history
git clone do not care if the dir exist or is empty

And an existing target_dir/.git is expected in the
rest of this function
  • Loading branch information
hparfr committed Oct 7, 2024
1 parent 63f2ca1 commit d8ccdaf
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 d8ccdaf

Please sign in to comment.