shell

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 4edc4eca68d2671c43c1d9b59c2bc05cf03486e1
parent 25e12175337b5814ef8bf6dd1e556f45a2d248d2
Author: flupe <flupe@sbi.re>
Date:   Wed, 17 Nov 2021 17:14:00 +0100

added git-upload-archive cmd

Diffstat:
Mshell.py | 23++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/shell.py b/shell.py @@ -26,7 +26,7 @@ def do_git_receive_pack(user, cmd, args): if not os.path.isdir(path): if not policy.CREATE & perm: - die('error: sorry %s, you are not allowed to create new repo %s' % (user, repo)) + die('error: sorry %s, %s does not exist and you are not allowed to create it' % (user, repo)) subprocess.run(['git', 'init', '--bare', path], stdout=sys.stderr.buffer) sys.stderr.write('info: created new repo %s' % repo) @@ -43,19 +43,32 @@ def do_git_upload_pack(user, cmd, args): die('error: sorry %s, you are not allowed to pull from %s' % (user, repo)) if not os.path.isdir(path): - if not policy.CREATE & perm: - die('error: sorry %s, you are not allowed to create new repo %s' % (user, repo)) - subprocess.run(['git', 'init', '--bare', path], stdout=sys.stderr.buffer) - sys.stderr.write('info: created new repo %s' % repo) + die('error: sorry %s, %s does not exist' % (user, repo)) os.execvp('git-upload-pack', ['git-upload-pack', *args[:-1], path]) +def do_git_upload_archive(user, cmd, args): + if len(args) < 1: + die('error: git-upload-archive must be given an argument') + repo = args[-1] + path = os.path.join(policy.BASEDIR, repo) + perm = policy.get_perm(user, repo) + + if not policy.READ & perm: + die('error: sorry %s, you are not allowed to retrieve archive from %s' % (user, repo)) + + if not os.path.isdir(path): + die('error: sorry %s, %s does not exist' % (user, repo)) + + os.execvp('git-upload-archive', ['git-upload-archive', *args[:-1], path]) + def do_default(user, cmd, args): die('Hello there, %s!\nThis the SBIRE custom shell for git.' % user, status=0) COMMANDS = { 'git-receive-pack': do_git_receive_pack, 'git-upload-pack': do_git_upload_pack, + 'git-upload-archive': do_git_upload_archive, } def main():