From 57a3b49351d41073cc64b658440e56ecea7fa90d Mon Sep 17 00:00:00 2001 From: Yoann Fleury Date: Thu, 22 Oct 2026 11:54:20 +0200 Subject: [PATCH 1/2] feat: handle remote templating --- CHANGELOG.md | 15 ++ Cargo.lock | 1 + Cargo.toml | 1 + README.md | 52 ++++ src/lib.rs | 655 ++++++++++++++++++++++++++++++++++++++++++++---- src/template.rs | 78 ++++++ 6 files changed, 759 insertions(+), 43 deletions(-) create mode 100644 src/template.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 57653f5..a1c4d23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Added + +- URL templates in the git config (`gitweb..branch-template`, + `tag-template`, `commit-template` and `merge-request-template`) to open the + repositories of self-hosted forges like Bitbucket Server (#55) + +### Fixed + +- a repository with `.git` in its name, like `user.github.io`, is no longer + opened as `userhub.io` +- `--merge-request` on an unknown host exits with the code 7 instead of + panicking + ## 0.5.0 - 2026-10-21 ### Added diff --git a/Cargo.lock b/Cargo.lock index b4bb668..daa05b8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -325,6 +325,7 @@ dependencies = [ "git2", "log", "open", + "percent-encoding", "tempfile", "thiserror", ] diff --git a/Cargo.toml b/Cargo.toml index f3ed8d3..1640dbd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ git-url-parse = "0.6" git2 = { version = "0.21", features = ["vendored-openssl"] } log = "0.4" open = "5.4" +percent-encoding = "2.3" thiserror = "2.0" [dev-dependencies] diff --git a/README.md b/README.md index e9b3650..f59a0e0 100644 --- a/README.md +++ b/README.md @@ -107,3 +107,55 @@ custom branch or tag you want to open in the browser. `gitweb` will open the origin remote if it exists. You can override the behavior by giving the `--remote` flag with the custom remote you want to open. + +The remote is the name of one of the git remotes of the repository (`git remote` +lists them, usually `origin`, and `upstream` when working on a fork). It does +not change the shape of the URL that is opened, see [Custom URLs](#custom-urls) +for that. + +## Custom URLs + +`gitweb` knows the URLs of github.com, gitlab.com, bitbucket.org and gitea.io, +and opens GitHub-like URLs for every other host. For a self-hosted forge with +other URLs, set URL templates for its host in your git config: + +```shell +git config --global gitweb..branch-template '