diff options
author | Mark Powers <mark@marks.kitchen> | 2022-02-19 20:03:47 -0600 |
---|---|---|
committer | Mark Powers <mark@marks.kitchen> | 2022-02-19 20:03:47 -0600 |
commit | aae210b048d267159975fcd7f8817c62074738e7 (patch) | |
tree | 9295c1515635e67f7930cf3f3ebaab95d652dc44 | |
parent | e8f9e7b7642fc9095240f1ce9dc99937b7e6585c (diff) |
Add init to repo.py, remove repo.sh
-rw-r--r-- | README.md | 8 | ||||
-rwxr-xr-x | repo.py | 19 | ||||
-rwxr-xr-x | repo.sh | 48 |
3 files changed, 20 insertions, 55 deletions
@@ -1,8 +1,2 @@ # Git scripts -A collection of various scripts for git. - -## repo.sh -- ./repo.sh create [repo] - Create a repo on the server -- ./repo.sh list - List repos on the server -- ./repo.sh clone [repo] - Clone a repo from the server - +A script to interact with a basic git daemon @@ -3,6 +3,7 @@ import requests import argparse import subprocess +import os gitweb_url = "https://git.marks.kitchen" @@ -21,6 +22,21 @@ def clone_repo(args): if title == args["repo"]: subprocess.run(["git", "clone", remote]) +def init_repo(args): + name = os.path.basename(os.getcwd()) + git_dir = f"/srv/git/{name}.git" + r = subprocess.run(["ssh", "git@marks.kitchen", f"mkdir {git_dir}"]) + if r.returncode == 0: + subprocess.run(["ssh", "git@marks.kitchen", + f"cd \"{git_dir}\"; git init --bare; touch git-daemon-export-ok"]) + + subprocess.run(["git", "init"]) + subprocess.run(["git", "remote", "add", "origin", f"git@marks.kitchen:{git_dir}"]) + #subprocess.run(["git", "branch", "--set-upstream-to=origin/master", "master"]) + #subprocess.run(["git", "push", "--set-upstream", "origin", "master"]) + else: + print("Repo already exists") + def main(): parser = argparse.ArgumentParser("wikijscmd") parser.set_defaults(command=None) @@ -33,6 +49,9 @@ def main(): parser_clone.add_argument("repo", type=str, help="repo name") parser_clone.set_defaults(command=clone_repo) + parser_init = subparsers.add_parser("init", help="create repos") + parser_init.set_defaults(command=init_repo) + args = vars(parser.parse_args()) callback = args["command"] if callback is None: diff --git a/repo.sh b/repo.sh deleted file mode 100755 index abc3e04..0000000 --- a/repo.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/bash -set -e - -repo_location="/srv/git/" - -trimmed_repos="" -get_repos () { - trimmed_repos=() - repos=$(ssh marks.kitchen "ls -d $repo_location*.git") - for repo in $repos - do - repo_trim=$(basename $repo | cut -f 1 -d '.') - trimmed_repos+="$repo_trim " - done -} - -create_repo () { - dir="$repo_location$1.git" - ssh git@marks.kitchen "mkdir $dir" - ssh git@marks.kitchen "cd \"$dir\"; git init --bare; touch git-daemon-export-ok" -} - -case $1 in - create) # init a git repo here and create one on the server - create_repo $2 - dir="$repo_location$2.git" - printf "git init\n" - printf "git remote add origin git@marks.kitchen:$dir\n" - printf "git branch --set-upstream-to=origin/master master\n" - printf "git push\n" - ;; - list) # list repos on the server - get_repos - for repo in $trimmed_repos - do - printf "$repo\n" - done - ;; - clone) # clone a repo from the list - dir="$repo_location$2.git" - git clone git@marks.kitchen:$repo_location$dir - cd $dir - ;; - *) - printf "usage: ./repo [create|list|clone] args\n" - ;; -esac - |