Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,6 @@ docs/_build/

# PyBuilder
target/

# jetbrain solutions
/.idea/
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ Contributors
* Jairo Llopis (Tecnativa_)
* Stéphane Bidoul (ACSONE_)
* Dave Lasley (LasLabs_)
* Jordi Riera

.. _ACSONE: https://www.acsone.eu
.. _Tecnativa: https://www.tecnativa.com
Expand Down
4 changes: 2 additions & 2 deletions git_aggregator/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ def get_repos(config):
raise ConfigException(
'%s: You should at least define one merge.' % directory)
else:
raise ConfigException(
'%s: merges is not defined.' % directory)
repo_dict['merges'] = []

# Only fetch required remotes by default
repo_dict["fetch_all"] = repo_data.get("fetch_all", False)
if isinstance(repo_dict["fetch_all"], string_types):
Expand Down
47 changes: 24 additions & 23 deletions git_aggregator/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,29 +163,30 @@ def aggregate(self):
If the target_dir doesn't exist, create an empty git repo otherwise
clean it, add all remotes , and merge all merges.
"""
logger.info('Start aggregation of %s', self.cwd)
target_dir = self.cwd

with working_directory_keeper:
is_new = not os.path.exists(target_dir)
if is_new:
self.init_repository(target_dir)

os.chdir(target_dir)
self._switch_to_branch(self.target['branch'])
for r in self.remotes:
self._set_remote(**r)
self.fetch()
merges = self.merges
if not is_new:
# reset to the first merge
origin = merges[0]
merges = merges[1:]
self._reset_to(origin["remote"], origin["ref"])
for merge in merges:
self._merge(merge)
self._execute_shell_command_after()
logger.info('End aggregation of %s', self.cwd)
if self.merges:
logger.info('Start aggregation of %s', self.cwd)
target_dir = self.cwd

with working_directory_keeper:
is_new = not os.path.exists(target_dir)
if is_new:
self.init_repository(target_dir)

os.chdir(target_dir)
self._switch_to_branch(self.target['branch'])
for r in self.remotes:
self._set_remote(**r)
self.fetch()
merges = self.merges
if not is_new:
# reset to the first merge
origin = merges[0]
merges = merges[1:]
self._reset_to(origin["remote"], origin["ref"])
for merge in merges:
self._merge(merge)
self._execute_shell_command_after()
logger.info('End aggregation of %s', self.cwd)

def init_repository(self, target_dir):
logger.info('Init empty git repository in %s', target_dir)
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@
entry_points=dict(
console_scripts=['gitaggregate=git_aggregator.main:main']),
test_suite='tests',
tests_require=['mock']
)
13 changes: 7 additions & 6 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,20 @@ def test_load_remotes_exception(self):
ex.exception.args[0],
'/product_attribute: No url defined for remote oca.')

def test_load_merges_exception(self):
def test_no_merges(self):
"""When there is no merge given in the config,
then it is exported as empty list.
"""
config_yaml = """
/product_attribute:
remotes:
oca: https://github.com/OCA/product-attribute.git
target: oca aggregated_branch
"""
with self.assertRaises(ConfigException) as ex:
config.get_repos(self._parse_config(config_yaml))
self.assertEquals(
ex.exception.args[0],
'/product_attribute: merges is not defined.')
repos = config.get_repos(self._parse_config(config_yaml))
self.assertEquals(repos[0]['shell_command_after'], [])

def test_load_merges_exception(self):
config_yaml = """
/product_attribute:
remotes:
Expand Down
21 changes: 21 additions & 0 deletions tests/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import shutil
import unittest
import subprocess

from mock import mock

try:
# Py 2
from urlparse import urljoin
Expand Down Expand Up @@ -117,6 +120,24 @@ def test_minimal(self):
last_rev = git_get_last_rev(self.cwd)
self.assertEqual(last_rev, self.commit_1_sha)

def test_no_merge(self):
"""When the list of merges is empty,
then the aggregate runs but no merge are proceeded.
"""
remotes = [{
'name': 'r1',
'url': self.url_remote1
}]
merges = []
target = {
'remote': 'r1',
'branch': 'agg1'
}
repo = Repo(self.cwd, remotes, merges, target)
with mock.patch.object(Repo, '_merge') as mock_merge:
repo.aggregate()
self.assertEqual(0, mock_merge.call_count)

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