Skip to content
Snippets Groups Projects
Commit 6ef5de19 authored by Georges Racinet's avatar Georges Racinet
Browse files

file_context: Git file modes

The `file_context.git_perms` function will be useful in Blob
related service methods, is easily testable outside of gRPC,
and was the occasion to start a new Python module dealing
with `filecontext` instances.
parent 949fcc78
No related branches found
Tags 0.8.1
1 merge request!57Blob and Tree related service methods
# Copyright 2020-2021 Georges Racinet <georges.racinet@octobus.net>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
#
# SPDX-License-Identifier: GPL-2.0-or-later
from .git import (
OBJECT_MODE_EXECUTABLE,
OBJECT_MODE_LINK,
OBJECT_MODE_NON_EXECUTABLE,
)
def git_perms(filectx):
"""Return Git representation for file permissions (aka mode).
Reference: https://git-scm.com/book/en/v2/Git-Internals-Git-Objects
"""
if filectx.islink():
return OBJECT_MODE_LINK
elif filectx.isexec():
return OBJECT_MODE_EXECUTABLE
else:
return OBJECT_MODE_NON_EXECUTABLE
# Copyright 2021 Georges Racinet <georges.racinet@octobus.net>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
#
# SPDX-License-Identifier: GPL-2.0-or-later
from heptapod.testhelpers import (
LocalRepoWrapper,
)
from ..file_context import (
git_perms
)
from .. import git
def make_repo(path):
return LocalRepoWrapper.init(path,
config=dict(
extensions=dict(topic='', evolve=''),
))
def test_git_perms(tmpdir):
wrapper = make_repo(tmpdir)
regular = (tmpdir / 'regular')
regular.write('foo')
script = tmpdir / 'script'
script.write('#!/usr/bin/env python2\n'
'print "Hello, world"\n')
script.chmod(0o755)
(tmpdir / 'link_exe').mksymlinkto(script)
(tmpdir / 'link_regular').mksymlinkto(regular)
changeset = wrapper.commit([], add_remove=True)
assert git_perms(changeset[b'script']) == git.OBJECT_MODE_EXECUTABLE
assert git_perms(changeset[b'regular']) == git.OBJECT_MODE_NON_EXECUTABLE
assert git_perms(changeset[b'link_regular']) == git.OBJECT_MODE_LINK
# gracinet: I checked manually with a local repo that symlinks to
# executable and non executable files have the same Git file mode.
assert git_perms(changeset[b'link_exe']) == git.OBJECT_MODE_LINK
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment