From b0424aa6d866819499b377833dbc1629c045a880 Mon Sep 17 00:00:00 2001 From: chroe Date: Thu, 9 Jul 2026 21:41:29 +0800 Subject: [PATCH] fix(api): restore API path polluted by MSYS2/Git Bash on Windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在 Windows Git Bash (MSYS2) 环境下,gitlink-cli api GET /v1/owner/repo 的路径参数会被 MSYS2 自动改写为类似 C:/Program Files/Git/v1/owner/repo 的 Windows 路径(MSYS2 把 /v1 当成 Unix 路径转换为 Git 安装目录),导致 API 调用 404。 修复:在 runAPI 中检测路径首部是否为盘符(^[A-Za-z]:/), 若是则按常见 API 前缀(/v1/ /v2/ /api/ /users/ /projects/) 定位并还原原始 API 路径。 影响所有 Windows Git Bash 用户,跨平台兼容性修复。 --- cmd/api/api.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cmd/api/api.go b/cmd/api/api.go index cae531a..ec3d076 100644 --- a/cmd/api/api.go +++ b/cmd/api/api.go @@ -7,6 +7,7 @@ import ( "io" "net/url" "os" + "regexp" "strings" "github.com/spf13/cobra" @@ -60,6 +61,10 @@ func validateAPIArgs(c *cobra.Command, args []string) error { return cobra.ExactArgs(2)(c, args) } +// msysPathRe matches Windows drive-letter prefixes produced by MSYS2/Git Bash +// path conversion, e.g. "C:/Program Files/Git/v1/owner/repo" for input "/v1/owner/repo". +var msysPathRe = regexp.MustCompile(`^[A-Za-z]:/`) + func runAPI(c *cobra.Command, args []string) error { batchFile, _ := c.Flags().GetString("batch-file") if batchFile != "" { @@ -69,6 +74,18 @@ func runAPI(c *cobra.Command, args []string) error { method := strings.ToUpper(args[0]) path := args[1] + // Fix MSYS2/Git Bash path auto-conversion on Windows: + // "/v1/owner/repo" is rewritten to "C:/Program Files/Git/v1/owner/repo". + // Detect the drive-letter prefix and restore the original API path. + if msysPathRe.MatchString(path) { + for _, prefix := range []string{"/v1/", "/v2/", "/api/", "/users/", "/projects/"} { + if idx := strings.Index(path, prefix); idx >= 0 { + path = path[idx:] + break + } + } + } + if !strings.HasPrefix(path, "/") { path = "/" + path }