You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by da...@apache.org on 2026/08/18 19:24:00 UTC
(allura) branch dc/686 updated (7d25e7173 -> b4592b9d5)
This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a change to branch dc/686
in repository https://gitbox.apache.org/repos/asf/allura.git
from 7d25e7173 Added scm.force_push.git.enabled flag
new d1326815a Fix for force push on new repos
new b4592b9d5 New script to backfill allow forcepush flag
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
Allura/allura/lib/repository.py | 11 ++-
Allura/allura/model/repository.py | 9 +++
Allura/allura/tasks/repo_tasks.py | 5 +-
ForgeGit/forgegit/git_main.py | 7 +-
ForgeGit/forgegit/model/git_repo.py | 31 +++++++-
.../forgegit/tests/functional/test_controllers.py | 45 +++++++++++
ForgeGit/forgegit/tests/model/test_repository.py | 91 ++++++++++++++++++++++
.../migrations/force-push-sync-from-repo-config.py | 77 ++++++++++++++++++
8 files changed, 264 insertions(+), 12 deletions(-)
create mode 100644 scripts/migrations/force-push-sync-from-repo-config.py
(allura) 02/02: New script to backfill allow forcepush flag
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch dc/686
in repository https://gitbox.apache.org/repos/asf/allura.git
commit b4592b9d5be30fbe439be1845fdcc25d1f8315fc
Author: Daniel Castillo <da...@slashdotmedia.com>
AuthorDate: Tue Aug 18 19:23:13 2026 +0000
New script to backfill allow forcepush flag
---
Allura/allura/tasks/repo_tasks.py | 5 +-
ForgeGit/forgegit/model/git_repo.py | 22 ++++---
.../forgegit/tests/functional/test_controllers.py | 41 +++++++++---
ForgeGit/forgegit/tests/model/test_repository.py | 46 ++++++++++++-
.../migrations/force-push-sync-from-repo-config.py | 77 ++++++++++++++++++++++
5 files changed, 167 insertions(+), 24 deletions(-)
diff --git a/Allura/allura/tasks/repo_tasks.py b/Allura/allura/tasks/repo_tasks.py
index d2ca6accd..cb6d76edf 100644
--- a/Allura/allura/tasks/repo_tasks.py
+++ b/Allura/allura/tasks/repo_tasks.py
@@ -201,6 +201,7 @@ def update_head_reference(fs_path, branch_name):
@task
def update_force_push_config(fs_path: str, allowed: bool):
+ # git's own config writer rather than GitPython's: it edits in place so comments and
+ # formatting survive, and matches the key case-insensitively so a legacy spelling is replaced
repo = git.Repo(fs_path, odbt=git.GitCmdObjectDB)
- with repo.config_writer() as cw: # config_level defaults to 'repository'
- cw.set_value('receive', 'denyNonFastForwards', 'false' if allowed else 'true')
+ repo.git.config('--replace-all', 'receive.denyNonFastForwards', 'false' if allowed else 'true')
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index 971c6c998..8159f01ec 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -209,20 +209,25 @@ def force_push_allowed_on_disk(self):
if self._git is None:
return None
try:
- with self._git.config_reader('repository') as cr:
- return not asbool(cr.get_value('receive', 'denyNonFastForwards', False))
+ denied = self._git.git.config('--bool', '--get', 'receive.denyNonFastForwards')
+ except git.exc.GitCommandError as err:
+ if err.status == 1:
+ return True # unset, and git does not deny non-fast-forwards by default
+ log.exception('Could not read receive.denyNonFastForwards for %r', self._repo)
+ return None
except Exception:
log.exception('Could not read receive.denyNonFastForwards for %r', self._repo)
return None
+ return not asbool(denied)
def _apply_force_push_config(self):
- # keep the repo's on-disk setting in step with force_push_allowed; a repo Allura has
- # never written is left alone entirely, so this is a no-op when the feature is off
+ # `git init --shared=all` denies non-fast-forwards but `git clone --bare` does not, so
+ # clones need this to match a fresh repo; no-op when the feature is off
+ # http://git-scm.com/docs/git-init#Documentation/git-init.txt---sharedltpermissionsgt
if not asbool(tg.config.get(f'scm.force_push.{self._repo.tool}.enabled')):
return
- with self._git.config_writer() as cw:
- cw.set_value('receive', 'denyNonFastForwards',
- 'false' if self._repo.force_push_allowed else 'true')
+ self._git.git.config('--replace-all', 'receive.denyNonFastForwards',
+ 'false' if self._repo.force_push_allowed else 'true')
def can_hotcopy(self, source_url):
enabled = asbool(tg.config.get('scm.git.hotcopy', True))
@@ -246,9 +251,6 @@ def clone_from(self, source_url):
if os.path.exists(post_receive):
os.rename(post_receive, post_receive + '-user')
repo = git.Repo(fullname)
- # a hotcopy inherits the parent's config verbatim; force push is not inherited
- with repo.config_writer() as cw:
- cw.remove_section('receive')
else:
repo = git.Repo.clone_from(
source_url,
diff --git a/ForgeGit/forgegit/tests/functional/test_controllers.py b/ForgeGit/forgegit/tests/functional/test_controllers.py
index ff4aa1dfe..11c305952 100644
--- a/ForgeGit/forgegit/tests/functional/test_controllers.py
+++ b/ForgeGit/forgegit/tests/functional/test_controllers.py
@@ -18,6 +18,7 @@
import re
import os
import shutil
+import subprocess
import tempfile
import textwrap
@@ -585,17 +586,37 @@ def test_force_push_save_writes_even_when_unchanged(self):
def test_force_push_hidden_until_repo_ready(self):
with h.push_config(tg.config, **{'scm.force_push.git.enabled': 'true'}):
- for status in ('initializing', 'cloning'):
- c.app.repo.status = status
+ for status, ready in (('initializing', False), ('cloning', False),
+ ('analyzing', True), ('ready', True)):
+ # re-query: c.app.repo detaches from the session after the first request, so
+ # assigning to it would silently not persist
+ repo = GM.Repository.query.get(_id=c.app.repo._id)
+ repo.status = status
ThreadLocalODMSession.flush_all()
- assert not any(l.label.startswith('Force push') for l in c.app.admin_menu())
- self.app.get('/p/test/admin/src-git/force_push', status=404)
- self.app.post('/p/test/admin/src-git/force_push',
- params={'allowed': 'on'}, status=404)
- c.app.repo.status = 'analyzing'
- ThreadLocalODMSession.flush_all()
- assert any(l.label.startswith('Force push') for l in c.app.admin_menu())
- self.app.get('/p/test/admin/src-git/force_push', status=200)
+ c.app.repo.status = status # the in-process copy admin_menu() reads
+ assert any(l.label.startswith('Force push')
+ for l in c.app.admin_menu()) is ready
+ self.app.get('/p/test/admin/src-git/force_push', status=200 if ready else 404)
+ if not ready:
+ self.app.post('/p/test/admin/src-git/force_push',
+ params={'allowed': 'on'}, status=404)
+
+ def test_force_push_checkbox_reflects_repo_state(self):
+ # the form must show what the repo really permits, not just the stored field: a repo
+ # predating this feature has no receive setting and does accept force pushes
+ R = c.app.repo.full_fs_path
+ assert c.app.repo.force_push_allowed is False
+ with h.push_config(tg.config, **{'scm.force_push.git.enabled': 'true'}):
+ try:
+ r = self.app.get('/p/test/admin/src-git/force_push')
+ assert 'name="allowed" checked' in squish_spaces(r.text)
+ subprocess.run(['git', '--git-dir', R, 'config',
+ 'receive.denyNonFastForwards', 'true'], check=True)
+ r = self.app.get('/p/test/admin/src-git/force_push')
+ assert 'name="allowed" checked' not in squish_spaces(r.text)
+ finally:
+ subprocess.run(['git', '--git-dir', R, 'config',
+ '--remove-section', 'receive'], check=False)
def test_force_push_requires_admin(self):
with h.push_config(tg.config, **{'scm.force_push.git.enabled': 'true'}):
diff --git a/ForgeGit/forgegit/tests/model/test_repository.py b/ForgeGit/forgegit/tests/model/test_repository.py
index 919a58a62..b1580def3 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -724,6 +724,33 @@ def test_force_push_allowed_effective_falls_back(self):
self.repo.force_push_allowed = True
assert self.repo.force_push_allowed_effective() is True
+ def test_update_force_push_config_preserves_other_settings(self):
+ # a real repo's config holds unrelated settings and comments; only our key may change
+ path = os.path.join(g.tmpdir, 'cfgtest.git')
+ shutil.rmtree(path, ignore_errors=True)
+ git.Repo.init(path=path, mkdir=True, quiet=True, bare=True)
+ try:
+ with open(os.path.join(path, 'config'), 'a') as f:
+ f.write('# keep me\n'
+ '[receive]\n\tdenyDeletes = true\n\tdenyNonFastforwards = true\n'
+ '; keep me too\n'
+ '[remote "origin"]\n\turl = /srv/git/p/foo/code.git\n'
+ '\tfetch = +refs/heads/*:refs/remotes/origin/*\n'
+ '\tfetch = +refs/tags/*:refs/tags/*\n')
+ update_force_push_config(path, True)
+ update_force_push_config(path, False)
+ repo = git.Repo(path)
+ text = open(os.path.join(path, 'config')).read()
+ assert '# keep me' in text
+ assert '; keep me too' in text
+ # the legacy lower-case spelling is replaced in place, not duplicated alongside ours
+ assert text.lower().count('denynonfastforwards') == 1
+ assert repo.git.config('--get', 'receive.denyDeletes') == 'true'
+ assert repo.git.config('--bool', '--get', 'receive.denyNonFastForwards') == 'true'
+ assert len(repo.git.config('--get-all', 'remote.origin.fetch').splitlines()) == 2
+ finally:
+ shutil.rmtree(path, ignore_errors=True)
+
def _init_scratch_repo(self):
repo = GM.Repository(name='testgit.git', fs_path=g.tmpdir + '/', url_path='/test/',
tool='git', status='creating')
@@ -746,8 +773,23 @@ def test_init_leaves_config_alone_when_disabled(self):
repo, dirname = self._init_scratch_repo()
try:
repo.init()
- with git.Repo(dirname).config_reader('repository') as cr:
- assert not cr.has_section('receive')
+ # git init --shared=all writes this itself, in its own lower-case spelling;
+ # with the feature off Allura must not rewrite it
+ text = open(os.path.join(dirname, 'config')).read()
+ assert 'denyNonFastforwards = true' in text
+ finally:
+ shutil.rmtree(dirname, ignore_errors=True)
+
+ def test_clone_denies_force_push_when_enabled(self):
+ # git clone --bare does NOT inherit the deny that git init --shared=all sets, so without
+ # this a fork would accept force pushes while its checkbox showed unticked
+ repo, dirname = self._init_scratch_repo()
+ try:
+ with h.push_config(tg.config, **{'scm.force_push.git.enabled': 'true'}):
+ repo.init()
+ repo._impl.clone_from(pkg_file('forgegit', 'tests/data/testgit.git'))
+ cloned = git.Repo(dirname)
+ assert cloned.git.config('--bool', '--get', 'receive.denyNonFastForwards') == 'true'
finally:
shutil.rmtree(dirname, ignore_errors=True)
diff --git a/scripts/migrations/force-push-sync-from-repo-config.py b/scripts/migrations/force-push-sync-from-repo-config.py
new file mode 100644
index 000000000..94b6381fa
--- /dev/null
+++ b/scripts/migrations/force-push-sync-from-repo-config.py
@@ -0,0 +1,77 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+One-time sync of Repository.force_push_allowed from each git repo's own config.
+
+Repos predating the force-push toggle have no force_push_allowed recorded, while their
+receive.denyNonFastForwards may already be true, false, or unset. This reads each repo and
+stores what it actually permits, so the admin UI and menu label agree with reality.
+
+Reads git; writes only Mongo. No repo's behaviour changes.
+
+ paster script /var/local/config/production.ini \
+ ../scripts/migrations/force-push-sync-from-repo-config.py -- --dry-run
+"""
+
+import argparse
+import logging
+import sys
+
+from ming.odm import session, ThreadLocalODMSession
+
+from allura.lib.utils import chunked_find
+from forgegit import model as GM
+
+log = logging.getLogger(__name__)
+
+
+def parse_options():
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument('--dry-run', action='store_true',
+ help='report what would change without writing to Mongo')
+ return parser.parse_args(sys.argv[sys.argv.index('--') + 1:] if '--' in sys.argv else [])
+
+
+def main():
+ opts = parse_options()
+ counts = dict(seen=0, changed=0, unreadable=0)
+ for chunk in chunked_find(GM.Repository):
+ for repo in chunk:
+ counts['seen'] += 1
+ on_disk = repo._impl.force_push_allowed_on_disk()
+ if on_disk is None:
+ counts['unreadable'] += 1
+ log.warning('unreadable, leaving alone: %s', repo.full_fs_path)
+ continue
+ if on_disk == repo.force_push_allowed:
+ continue
+ counts['changed'] += 1
+ log.info('%s: force_push_allowed %s => %s',
+ repo.full_fs_path, repo.force_push_allowed, on_disk)
+ if not opts.dry_run:
+ repo.force_push_allowed = on_disk
+ session(repo).flush(repo)
+ if not opts.dry_run:
+ ThreadLocalODMSession.flush_all()
+ log.info('%s %d git repos: %d updated, %d unreadable',
+ 'would update' if opts.dry_run else 'synced', counts['seen'],
+ counts['changed'], counts['unreadable'])
+
+
+if __name__ == '__main__':
+ main()
(allura) 01/02: Fix for force push on new repos
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch dc/686
in repository https://gitbox.apache.org/repos/asf/allura.git
commit d1326815a385f385848e6c4d5663f3569233333e
Author: Daniel Castillo <da...@slashdotmedia.com>
AuthorDate: Mon Aug 17 22:02:06 2026 +0000
Fix for force push on new repos
---
Allura/allura/lib/repository.py | 11 +++--
Allura/allura/model/repository.py | 9 ++++
ForgeGit/forgegit/git_main.py | 7 ++--
ForgeGit/forgegit/model/git_repo.py | 23 ++++++++++
.../forgegit/tests/functional/test_controllers.py | 24 +++++++++++
ForgeGit/forgegit/tests/model/test_repository.py | 49 ++++++++++++++++++++++
6 files changed, 116 insertions(+), 7 deletions(-)
diff --git a/Allura/allura/lib/repository.py b/Allura/allura/lib/repository.py
index 83c91f7c7..12651e250 100644
--- a/Allura/allura/lib/repository.py
+++ b/Allura/allura/lib/repository.py
@@ -304,8 +304,8 @@ def set_default_branch_name(self, branch_name=None, **kw):
def force_push(self, allowed=None, **kw):
if not asbool(config.get(f'scm.force_push.{self.app.config.tool_name}.enabled')):
raise exc.HTTPNotFound()
- if not self.repo:
- # repo is still being created
+ if not self.repo or self.repo.status not in ('ready', 'analyzing'):
+ # init/clone/import recreate the repo dir, discarding config written before they finish
raise exc.HTTPNotFound()
if request.method == 'POST':
allowed = bool(allowed)
@@ -313,9 +313,12 @@ def force_push(self, allowed=None, **kw):
M.AuditLog.log('{}: set "{}" {} => {}'.format(
self.app.config.options['mount_point'], 'force_push_allowed',
self.repo.force_push_allowed, allowed))
- self.repo.set_force_push_allowed(allowed)
+ # written even when unchanged, so repos predating this feature get the value applied
+ self.repo.set_force_push_allowed(allowed)
redirect(six.ensure_text(c.app.url))
- return dict(app=self.app, force_push_allowed=self.repo.force_push_allowed)
+ # shown from the repo itself, not the stored field, so a repo predating this feature
+ # that still accepts force pushes is not displayed as if it refused them
+ return dict(app=self.app, force_push_allowed=self.repo.force_push_allowed_effective())
@without_trailing_slash
@expose('jinja:allura:templates/repo/checkout_url.html')
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 4ba241c8c..136fd968a 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -149,6 +149,9 @@ def _setup_hooks(self, source_path=None): # pragma no cover
def set_force_push_allowed(self, allowed): # pragma no cover
raise NotImplementedError('set_force_push_allowed')
+ def force_push_allowed_on_disk(self): # pragma no cover
+ raise NotImplementedError('force_push_allowed_on_disk')
+
# pragma no cover
def log(self, revs=None, path=None, exclude=None, id_only=True, **kw):
"""
@@ -557,6 +560,12 @@ def set_default_branch(self, name):
def set_force_push_allowed(self, allowed: bool):
return self._impl.set_force_push_allowed(allowed)
+ def force_push_allowed_effective(self) -> bool:
+ # repos predating this feature have no receive setting, so the stored field can understate
+ # what they actually permit; trust the repo itself when it can be read
+ on_disk = self._impl.force_push_allowed_on_disk()
+ return self.force_push_allowed if on_disk is None else on_disk
+
def paged_diffs(self, commit_id, start=0, end=None, onlyChangedFiles=False):
return self._impl.paged_diffs(commit_id, start, end, onlyChangedFiles)
diff --git a/ForgeGit/forgegit/git_main.py b/ForgeGit/forgegit/git_main.py
index 516924155..e4c4354bb 100644
--- a/ForgeGit/forgegit/git_main.py
+++ b/ForgeGit/forgegit/git_main.py
@@ -77,9 +77,10 @@ def admin_menu(self):
c.project.url() + 'admin/' + self.config.options.mount_point +
'/' + 'set_default_branch_name',
className='admin_modal'))
- if asbool(config.get(f'scm.force_push.{self.config.tool_name}.enabled')):
- # self.repo is None while a repo is still being created
- label = 'Force push (enabled)' if (self.repo and self.repo.force_push_allowed) else 'Force push'
+ if (asbool(config.get(f'scm.force_push.{self.config.tool_name}.enabled'))
+ and self.repo and self.repo.status in ('ready', 'analyzing')):
+ # hidden until ready: init/clone recreate the repo dir and would discard the setting
+ label = 'Force push (enabled)' if self.repo.force_push_allowed else 'Force push'
links.append(SitemapEntry(
label,
c.project.url() + 'admin/' + self.config.options.mount_point +
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index 4ba1faf0c..971c6c998 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -200,8 +200,30 @@ def init(self):
shared='all')
self.__dict__['_git'] = repo
self._setup_special_files()
+ self._apply_force_push_config()
self._repo.set_status('ready')
+ def force_push_allowed_on_disk(self):
+ # what the repo itself currently permits, regardless of what Mongo records;
+ # None if that can't be determined, so callers fall back to the stored field
+ if self._git is None:
+ return None
+ try:
+ with self._git.config_reader('repository') as cr:
+ return not asbool(cr.get_value('receive', 'denyNonFastForwards', False))
+ except Exception:
+ log.exception('Could not read receive.denyNonFastForwards for %r', self._repo)
+ return None
+
+ def _apply_force_push_config(self):
+ # keep the repo's on-disk setting in step with force_push_allowed; a repo Allura has
+ # never written is left alone entirely, so this is a no-op when the feature is off
+ if not asbool(tg.config.get(f'scm.force_push.{self._repo.tool}.enabled')):
+ return
+ with self._git.config_writer() as cw:
+ cw.set_value('receive', 'denyNonFastForwards',
+ 'false' if self._repo.force_push_allowed else 'true')
+
def can_hotcopy(self, source_url):
enabled = asbool(tg.config.get('scm.git.hotcopy', True))
is_local = os.path.exists(source_url)
@@ -234,6 +256,7 @@ def clone_from(self, source_url):
bare=True)
self.__dict__['_git'] = repo
self._setup_special_files(source_url)
+ self._apply_force_push_config()
except Exception:
self._repo.set_status('ready')
raise
diff --git a/ForgeGit/forgegit/tests/functional/test_controllers.py b/ForgeGit/forgegit/tests/functional/test_controllers.py
index a190f4acb..ff4aa1dfe 100644
--- a/ForgeGit/forgegit/tests/functional/test_controllers.py
+++ b/ForgeGit/forgegit/tests/functional/test_controllers.py
@@ -573,6 +573,30 @@ def test_force_push_disabled_by_default(self):
self.app.post('/p/test/admin/src-git/force_push',
params={'allowed': 'on'}, status=404)
+ def test_force_push_save_writes_even_when_unchanged(self):
+ # repos predating the feature have no receive section; saving must still apply the value
+ with h.push_config(tg.config, **{'scm.force_push.git.enabled': 'true'}):
+ with patch('allura.tasks.repo_tasks.update_force_push_config.post') as post:
+ self.app.post('/p/test/admin/src-git/force_push', params={})
+ assert GM.Repository.query.get(_id=c.app.repo._id).force_push_allowed is False
+ post.assert_called_once_with(c.app.repo.full_fs_path, False)
+ assert M.AuditLog.query.find(
+ {'message': 'src-git: set "force_push_allowed" False => False'}).count() == 0
+
+ def test_force_push_hidden_until_repo_ready(self):
+ with h.push_config(tg.config, **{'scm.force_push.git.enabled': 'true'}):
+ for status in ('initializing', 'cloning'):
+ c.app.repo.status = status
+ ThreadLocalODMSession.flush_all()
+ assert not any(l.label.startswith('Force push') for l in c.app.admin_menu())
+ self.app.get('/p/test/admin/src-git/force_push', status=404)
+ self.app.post('/p/test/admin/src-git/force_push',
+ params={'allowed': 'on'}, status=404)
+ c.app.repo.status = 'analyzing'
+ ThreadLocalODMSession.flush_all()
+ assert any(l.label.startswith('Force push') for l in c.app.admin_menu())
+ self.app.get('/p/test/admin/src-git/force_push', status=200)
+
def test_force_push_requires_admin(self):
with h.push_config(tg.config, **{'scm.force_push.git.enabled': 'true'}):
self.app.get('/p/test/admin/src-git/force_push',
diff --git a/ForgeGit/forgegit/tests/model/test_repository.py b/ForgeGit/forgegit/tests/model/test_repository.py
index 451fd4c1a..919a58a62 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -702,6 +702,55 @@ def test_set_force_push_allowed(self):
def test_force_push_allowed_defaults_false(self):
assert self.repo.force_push_allowed is False
+ def test_force_push_allowed_effective(self):
+ git_repo = git.Repo(self.repo.full_fs_path)
+ try:
+ # no receive setting at all: the repo accepts force pushes even though the field is False
+ assert self.repo.force_push_allowed is False
+ assert self.repo.force_push_allowed_effective() is True
+ with git_repo.config_writer() as cw:
+ cw.set_value('receive', 'denyNonFastForwards', 'true')
+ assert self.repo.force_push_allowed_effective() is False
+ with git_repo.config_writer() as cw:
+ cw.set_value('receive', 'denyNonFastForwards', 'false')
+ assert self.repo.force_push_allowed_effective() is True
+ finally:
+ with git_repo.config_writer() as cw:
+ cw.remove_section('receive')
+
+ def test_force_push_allowed_effective_falls_back(self):
+ with mock.patch.object(GM.git_repo.GitImplementation, 'force_push_allowed_on_disk') as on_disk:
+ on_disk.return_value = None
+ self.repo.force_push_allowed = True
+ assert self.repo.force_push_allowed_effective() is True
+
+ def _init_scratch_repo(self):
+ repo = GM.Repository(name='testgit.git', fs_path=g.tmpdir + '/', url_path='/test/',
+ tool='git', status='creating')
+ dirname = os.path.join(repo.fs_path, repo.name)
+ if os.path.exists(dirname):
+ shutil.rmtree(dirname)
+ return repo, dirname
+
+ def test_init_denies_force_push_when_enabled(self):
+ repo, dirname = self._init_scratch_repo()
+ try:
+ with h.push_config(tg.config, **{'scm.force_push.git.enabled': 'true'}):
+ repo.init()
+ with git.Repo(dirname).config_reader('repository') as cr:
+ assert cr.get_value('receive', 'denyNonFastForwards') is True
+ finally:
+ shutil.rmtree(dirname, ignore_errors=True)
+
+ def test_init_leaves_config_alone_when_disabled(self):
+ repo, dirname = self._init_scratch_repo()
+ try:
+ repo.init()
+ with git.Repo(dirname).config_reader('repository') as cr:
+ assert not cr.has_section('receive')
+ finally:
+ shutil.rmtree(dirname, ignore_errors=True)
+
def test_default_branch_non_standard_unset(self):
with mock.patch.object(self.repo, 'get_branches') as gb, \
mock.patch.object(self.repo, 'set_default_branch') as set_db: