From 35409f3fddf4079926b0a079e6d6fd1adfe13886 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Wed, 1 Jul 2026 20:14:41 +0200 Subject: pkgs/git-cgit: Init --- pkgs/by-name/gi/git-cgit/git-cgit.sh | 131 +++++++++++++++++++++++++++++++++++ pkgs/by-name/gi/git-cgit/package.nix | 28 ++++++++ 2 files changed, 159 insertions(+) create mode 100755 pkgs/by-name/gi/git-cgit/git-cgit.sh create mode 100644 pkgs/by-name/gi/git-cgit/package.nix (limited to 'pkgs/by-name/gi') diff --git a/pkgs/by-name/gi/git-cgit/git-cgit.sh b/pkgs/by-name/gi/git-cgit/git-cgit.sh new file mode 100755 index 00000000..d24fda15 --- /dev/null +++ b/pkgs/by-name/gi/git-cgit/git-cgit.sh @@ -0,0 +1,131 @@ +#!/usr/bin/env sh + +# nixos-config - My current NixOS configuration +# +# Copyright (C) 2025 Benedikt Peetz +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This file is part of my nixos-config. +# +# You should have received a copy of the License along with this program. +# If not, see . + +NAME="git-cgit" + +not_empty() { + arg="$1" + name="$2" + + if [ "$arg" = "" ]; then + echo 1>&2 "flag '$name' is empty" + exit 2 + fi +} + +help() { + cat </path/to/repo' + --desc DESC + Optional description (will be read from './.git/description' otherwise). + --defbranch + Optional default branch + --cgit-owner + Optional cgit owner +EOF +} + +git_url="" +ssh_url="" +url_path="" +desc="$(cat "$(git rev-parse --show-toplevel)/.git/description")" + +cgit_owner="$(id --name -u)" +defbranch="$(git branch --show-current)" + +while [ "$#" -ne 0 ]; do + case "$1" in + "--help" | "-h") + help + exit 0 + ;; + "--git") + shift 1 + git_url="$1" + ;; + "--desc") + shift 1 + desc="$1" + ;; + "--defbranch") + shift 1 + defbranch="$1" + ;; + "--cgit-owner") + shift 1 + cgit_owner="$1" + ;; + esac + shift 1 +done + +# In the form git@ +ssh_url="${git_url#ssh://}" +while [ "$(dirname "$ssh_url")" != "." ]; do + ssh_url="$(dirname "$ssh_url")" +done +url_path="${git_url#ssh://"$ssh_url"}" +url_path="${url_path#/}" + +not_empty "$git_url" "--git" +not_empty "$ssh_url" "--git " +not_empty "$url_path" "--git " + +not_empty "$desc" "--desc" +not_empty "$defbranch" "--defbranch" +not_empty "$cgit_owner" "--cgit-owner" + +cat < '$git_url' + -> '$ssh_url' + -> '$url_path' + + --desc -> '$desc' + --defbranch -> '$defbranch' + --cgit-owner -> '$cgit_owner' + +EOF + +printf "Continue [y/N]? " +read -r continue +if [ "$continue" != "y" ]; then + echo 1>&2 "Not continuing.." + exit 1 +fi + +set -x + +git remote remove origin +git remote add origin "$git_url" + +git push --set-upstream origin "$defbranch" + +ssh "$ssh_url" -- perms "$url_path" + READERS @all +ssh "$ssh_url" -- desc "$url_path" "$desc" + +ssh "$ssh_url" -- config "$url_path" --add cgit.defbranch "$defbranch" +ssh "$ssh_url" -- config "$url_path" --add cgit.owner "$cgit_owner" + +ssh "$ssh_url" -- info +# vim: ft=sh diff --git a/pkgs/by-name/gi/git-cgit/package.nix b/pkgs/by-name/gi/git-cgit/package.nix new file mode 100644 index 00000000..2d3fe469 --- /dev/null +++ b/pkgs/by-name/gi/git-cgit/package.nix @@ -0,0 +1,28 @@ +# nixos-config - My current NixOS configuration +# +# Copyright (C) 2025 Benedikt Peetz +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This file is part of my nixos-config. +# +# You should have received a copy of the License along with this program. +# If not, see . +{ + writeShellApplication, + # Dependencies + coreutils, + git, + ssh, +}: +writeShellApplication { + name = "git-cgit"; + text = builtins.readFile ./git-cgit.sh; + + inheritPath = false; + + runtimeInputs = [ + coreutils + git + ssh + ]; +} -- cgit v1.3.1