##directly.
#gbp-user = gbpservice
#gbp-group = gbpservice
+
+## Git-fetch refs hack
+## Allows fetching/cloning remote repositories that have refs/heads/* pointing
+## to a tag object. Gerrit allows branches pointing to tag objects. However,
+## git disallows this which causes fetch to fail in repocache if such branches
+## exist in the remote repository. This setting activates a hack to workaround
+## the problem with such remote repositories.
+#repo-cache-refs-hack = yes
from gbp.scripts.buildpackage_rpm import main as gbp_rpm
from obs_service_gbp import LOGGER, gbplog
-from obs_service_gbp_utils import GbpServiceError, GbpChildBTError, fork_call
-from obs_service_gbp_utils import sanitize_uid_gid, write_treeish_meta
+from obs_service_gbp_utils import (GbpServiceError, GbpChildBTError, fork_call,
+ sanitize_uid_gid, write_treeish_meta, str_to_bool)
from gbp_repocache import CachedRepo, CachedRepoError
import gbp_repocache
defaults = {'repo-cache-dir': '/var/cache/obs/git-buildpackage-repos/',
'gbp-tmp-dir': '/tmp/obs-service-gbp/',
'gbp-user': None,
- 'gbp-group': None}
+ 'gbp-group': None,
+ 'repo-cache-refs-hack': 'no'}
filenames = [os.path.expanduser(fname) for fname in filenames]
LOGGER.debug('Trying %s config files: %s', len(filenames), filenames)
config = read_config(args.config)
# Create / update cached repository
+ refs_hack = str_to_bool(config['repo-cache-refs-hack'])
try:
- repo = CachedRepo(config['repo-cache-dir'], args.url)
+ repo = CachedRepo(config['repo-cache-dir'], args.url,
+ refs_hack=refs_hack)
args.revision = repo.update_working_copy(args.revision)
except CachedRepoError as err:
LOGGER.error('RepoCache: %s', str(err))
except IOError as err:
raise GbpServiceError("Failed to write '%s': %s" % (filename, err))
+
+def str_to_bool(string, default=False):
+ """Convert (config value) string to boolean. Returns default if unable to
+ determine.
+
+ >>> str_to_bool('true')
+ True
+ >>> str_to_bool('0')
+ False
+ >>> str_to_bool('foo', True)
+ True
+ """
+ value = string.strip().lower()
+ if value in ['1', 'yes', 'on', 'true', 'enabled']:
+ return True
+ elif value in ['0', 'no', 'off', 'false', 'disabled']:
+ return False
+ else:
+ return default
# MA 02110-1301, USA.
"""Tests for the git-buildpackage OBS source service"""
+import glob
import grp
import json
import mock
# Return env
del os.environ['OBS_GIT_BUILDPACKAGE_GBP_USER']
+ def test_refs_hack_config(self):
+ """Test enabling the repocache refs hack through config"""
+ # Try with hack disabled (default)
+ eq_(service(['--url', self.orig_repo.path, '--revision=rpm']), 0)
+ refs = glob.glob(self.cachedir + '/*/*/.git/refs')
+ eq_(len(refs), 1)
+ ok_(not os.path.islink(refs[0]))
+
+ # Enable hack -> refs should be a symlink
+ os.environ['OBS_GIT_BUILDPACKAGE_REPO_CACHE_REFS_HACK'] = 'yes'
+ eq_(service(['--url', self.orig_repo.path, '--revision=rpm']), 0)
+ ok_(os.path.islink(refs[0]))
+
+ # Restore env
+ del os.environ['OBS_GIT_BUILDPACKAGE_REPO_CACHE_REFS_HACK']