From 3a687d7628bd0211388a70f4bcde116a85d97679 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Fri, 26 Sep 2025 19:48:40 -0700 Subject: [PATCH] Remove the ".git" suffix on the web view Symlinks are necessary to retain the original ".git" folder so the clone URLs keep working. The bare non-".git" folder is just for the web view. This behavior matches GitHub and other git forges (i.e., no ".git" in the web URL, but include ".git" in the clone URL). --- etc/caddy/Caddyfile | 4 ++-- etc/gitweb.conf | 2 ++ srv/git/git-shell-commands/init | 5 +++++ srv/git/git-shell-commands/rm | 2 ++ srv/git/projects_list.txt | 0 5 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 srv/git/projects_list.txt diff --git a/etc/caddy/Caddyfile b/etc/caddy/Caddyfile index e659f86..fe227b8 100644 --- a/etc/caddy/Caddyfile +++ b/etc/caddy/Caddyfile @@ -15,9 +15,9 @@ git.ardis.lu { } } - # For /[name] and /[name].git WITHOUT additional paths, redirect to /?p=[name].git for human-friendly browsing + # For /[name] and /[name].git WITHOUT additional paths, redirect to /?p=[name] for human-friendly browsing @git_bare path_regexp ^(\/)([A-Za-z0-9_.-]+?)(\.git)?$ - redir @git_bare /?p={re.2}.git + redir @git_bare /?p={re.2} # For /[name].git WITH additional paths, serve git-http-backend to support git operations # {method}, {path}, {query} are magic Caddy variables which correspond to the URL diff --git a/etc/gitweb.conf b/etc/gitweb.conf index 734420a..7aefdfe 100644 --- a/etc/gitweb.conf +++ b/etc/gitweb.conf @@ -1,5 +1,7 @@ $projectroot = '/srv/git'; $git_temp = '/tmp'; +$strict_export = 1; # Repo MUST be listed on $projects_list to be displayed +$projects_list = $projectroot.'/projects_list.txt'; # https://git-scm.com/docs/gitweb.conf#_links_and_their_targets $home_link_str = 'git.ardis.lu'; diff --git a/srv/git/git-shell-commands/init b/srv/git/git-shell-commands/init index a52cc56..3ebdec2 100644 --- a/srv/git/git-shell-commands/init +++ b/srv/git/git-shell-commands/init @@ -75,4 +75,9 @@ if [ -n "$description" ]; then echo "$description" >"$path/description" fi +# Set up symlink so /$name --> /$name.git +# This is needed to drop the ".git" suffix on the web view +ln -s "$path" "$HOME/$name" +echo "$name" >>"$HOME/projects_list.txt" + echo "Repository '$name' created" diff --git a/srv/git/git-shell-commands/rm b/srv/git/git-shell-commands/rm index a614989..480b6b8 100644 --- a/srv/git/git-shell-commands/rm +++ b/srv/git/git-shell-commands/rm @@ -21,6 +21,8 @@ fi # git maintenance unregister --force # cd "$HOME" +sed -i "/^$name\$/d" "$HOME/projects_list.txt" +rm "$HOME/$name" rm -r "$path" echo "Repository '$name' deleted" diff --git a/srv/git/projects_list.txt b/srv/git/projects_list.txt new file mode 100644 index 0000000..e69de29 -- 2.47.3