From e629825a7a9b82332fc7a4e7d8bb7ce207d35059 Mon Sep 17 00:00:00 2001 From: jinil-ha Date: Tue, 1 Dec 2026 01:22:47 +0900 Subject: [PATCH 1/3] Support per-language document roots --- README.jp.md | 7 ++-- README.kr.md | 7 ++-- README.md | 7 ++-- cmd/tgrep/main_test.go | 50 +++++++++++++++++++++++++++- internal/cli/cli.go | 8 ++--- internal/config/config.go | 58 ++++++++++++++++++++++----------- internal/config/config_test.go | 12 ++++++- internal/documents/tree.go | 30 ++++++++++++----- internal/documents/tree_test.go | 44 +++++++++++++++++++++++++ internal/editor/editor.go | 4 ++- internal/search/preview.go | 2 +- 11 files changed, 187 insertions(+), 42 deletions(-) diff --git a/README.jp.md b/README.jp.md index 789cb14..bb94e51 100644 --- a/README.jp.md +++ b/README.jp.md @@ -80,14 +80,17 @@ TGREP_ENTER_ACTION=edit | 設定項目 | 既定値 | 説明 | | --- | --- | --- | | `TGREP_DOCS_DIR` | `.` | 言語別ディレクトリを格納する親ディレクトリ。相対パスは現在の作業ディレクトリを基準に解決されます。 | -| `TGREP_ORIGIN_LANG` | `en` | 検索対象となる原文の言語ディレクトリ。 | -| `TGREP_TARGET_LANGS` | `ko,ja` | プレビューする翻訳の言語ディレクトリ。複数指定する場合はコンマで区切ります。 | +| `DOCS_{LANGCODE}_ROOT` | `TGREP_DOCS_DIR/` | 原文または翻訳の言語別ディレクトリ。相対パスは `TGREP_DOCS_DIR` が基準です。`pt-BR` には `DOCS_PT_BR_ROOT` を使います。 | +| `TGREP_ORIGIN_LANG` | `en` | 検索対象となる原文の言語。 | +| `TGREP_TARGET_LANGS` | `ko,ja` | プレビューする翻訳の言語。複数指定する場合はコンマで区切ります。 | | `TGREP_ENTER_ACTION` | `edit` | Enter キーの動作。`edit` は最初に見つかった翻訳ファイルを `$EDITOR`(既定は `vi`)で開きます。`print` は原文のパス、行番号、一致した行の内容を出力します。 | | `TGREP_BEFORE_LINES` | `3` | 該当行の前に表示する行数(0 以上)。 | | `TGREP_AFTER_LINES` | `3` | 該当行の後に表示する行数(0 以上)。 | | `TGREP_BEFORE_LINES_{LANGCODE}` | `TGREP_BEFORE_LINES` の値 | 言語別の前の行数。たとえば `pt-BR` では `TGREP_BEFORE_LINES_PT_BR=1` で前の 1 行を表示します。 | | `TGREP_AFTER_LINES_{LANGCODE}` | `TGREP_AFTER_LINES` の値 | 言語別に後ろの行数を指定します。例:`TGREP_AFTER_LINES_KO=5` で韓国語の後ろ 5 行を表示。 | +たとえば、韓国語訳が別のリポジトリにある場合は `DOCS_KO_ROOT="$HOME/website-ko/content"` を設定します。英語の原文 `en/guide/setup.md` に対応する韓国語訳は `$HOME/website-ko/content/guide/setup.md` から読み込まれます。 + 環境変数に空でない値を指定すると、その実行時は設定ファイルの値よりも優先されます。たとえば、親ディレクトリと原文の言語には設定ファイルの値を使い、日本語訳だけを表示するには、次のように実行します。 ```sh diff --git a/README.kr.md b/README.kr.md index 192f8f9..2b29bdc 100644 --- a/README.kr.md +++ b/README.kr.md @@ -80,14 +80,17 @@ TGREP_ENTER_ACTION=edit | 설정 | 기본값 | 설명 | | --- | --- | --- | | `TGREP_DOCS_DIR` | `.` | 언어별 디렉터리를 담고 있는 상위 디렉터리입니다. 상대 경로는 현재 작업 디렉터리를 기준으로 합니다. | -| `TGREP_ORIGIN_LANG` | `en` | 검색할 원문의 언어 디렉터리입니다. | -| `TGREP_TARGET_LANGS` | `ko,ja` | 미리 볼 번역의 언어 디렉터리 목록입니다. 여러 개는 쉼표로 구분합니다. | +| `DOCS_{LANGCODE}_ROOT` | `TGREP_DOCS_DIR/` | 원문 또는 번역의 언어별 디렉터리입니다. 상대 경로는 `TGREP_DOCS_DIR` 기준입니다. `pt-BR`에는 `DOCS_PT_BR_ROOT`를 사용합니다. | +| `TGREP_ORIGIN_LANG` | `en` | 검색할 원문의 언어입니다. | +| `TGREP_TARGET_LANGS` | `ko,ja` | 미리 볼 번역 언어 목록입니다. 여러 개는 쉼표로 구분합니다. | | `TGREP_ENTER_ACTION` | `edit` | Enter 키의 동작입니다. `edit`는 첫 번째 번역 파일을 `$EDITOR`(기본값 `vi`)로 엽니다. `print`는 원문 경로, 줄 번호, 일치한 내용을 출력합니다. | | `TGREP_BEFORE_LINES` | `3` | 일치한 줄 앞에 표시할 줄 수(0 이상)입니다. | | `TGREP_AFTER_LINES` | `3` | 일치한 줄 뒤에 표시할 줄 수(0 이상)입니다. | | `TGREP_BEFORE_LINES_{LANGCODE}` | `TGREP_BEFORE_LINES` 값 | 언어별 앞 문맥입니다. `TGREP_BEFORE_LINES_PT_BR=1`이면 `pt-BR`에서 앞 1줄을 표시합니다. | | `TGREP_AFTER_LINES_{LANGCODE}` | `TGREP_AFTER_LINES` 값 | 언어별 뒤 문맥입니다. `TGREP_AFTER_LINES_KO=5`이면 한국어 번역에서 뒤 5줄을 표시합니다. | +예를 들어 한국어 번역이 별도 저장소에 있다면 `DOCS_KO_ROOT="$HOME/website-ko/content"`로 설정합니다. 그러면 영어 원문 `en/guide/setup.md`에 대응하는 한국어 번역을 `$HOME/website-ko/content/guide/setup.md`에서 찾습니다. + 환경변수에 비어 있지 않은 값이 있으면 해당 실행에서는 설정 파일보다 그 값이 우선합니다. 예를 들어 상위 디렉터리와 원문 언어는 설정 파일에서 읽고 일본어 번역만 보려면 다음과 같이 실행합니다. ```sh diff --git a/README.md b/README.md index da1589d..bad0749 100644 --- a/README.md +++ b/README.md @@ -80,14 +80,17 @@ TGREP_ENTER_ACTION=edit | Setting | Default | Meaning | | --- | --- | --- | | `TGREP_DOCS_DIR` | `.` | Directory containing the language directories. Relative paths start at the current working directory. | -| `TGREP_ORIGIN_LANG` | `en` | Source-language directory to search. | -| `TGREP_TARGET_LANGS` | `ko,ja` | Comma-separated target-language directories to preview. | +| `DOCS_{LANGCODE}_ROOT` | `TGREP_DOCS_DIR/` | Source or translation directory for one language. Relative paths start at `TGREP_DOCS_DIR`. Use `DOCS_PT_BR_ROOT` for `pt-BR`. | +| `TGREP_ORIGIN_LANG` | `en` | Source language to search. | +| `TGREP_TARGET_LANGS` | `ko,ja` | Comma-separated target languages to preview. | | `TGREP_ENTER_ACTION` | `edit` | Enter action. `edit` opens the first available translation in `$EDITOR` (default: `vi`). `print` outputs the source path, line number, and matching text. | | `TGREP_BEFORE_LINES` | `3` | Number of lines before the match (0 or more). | | `TGREP_AFTER_LINES` | `3` | Number of lines after the match (0 or more). | | `TGREP_BEFORE_LINES_{LANGCODE}` | Value of `TGREP_BEFORE_LINES` | Leading context by language. For example, `TGREP_BEFORE_LINES_PT_BR=1` shows one preceding line for `pt-BR`. | | `TGREP_AFTER_LINES_{LANGCODE}` | Value of `TGREP_AFTER_LINES` | Trailing context for one language. For example, `TGREP_AFTER_LINES_KO=5` shows five following lines in Korean. | +For example, set `DOCS_KO_ROOT="$HOME/website-ko/content"` if your Korean translation is in a separate checkout. The Korean translation of `en/guide/setup.md` is then read from `$HOME/website-ko/content/guide/setup.md`. + A nonempty environment variable overrides the corresponding file setting for that invocation. For example, to preview only Japanese with the root and source language from your config: ```sh diff --git a/cmd/tgrep/main_test.go b/cmd/tgrep/main_test.go index 6c9509a..c4bd876 100644 --- a/cmd/tgrep/main_test.go +++ b/cmd/tgrep/main_test.go @@ -93,7 +93,7 @@ func TestZshConfig(t *testing.T) { } root := t.TempDir() writeFile(t, filepath.Join(root, "src/en/doc"), "HIT\n", 0644) - writeFile(t, filepath.Join(root, "src/ko/doc"), "번역\n", 0644) + writeFile(t, filepath.Join(root, "src/korean/docs/doc"), "번역\n", 0644) if err := os.MkdirAll(filepath.Join(root, "bin"), 0755); err != nil { t.Fatal(err) } @@ -104,6 +104,7 @@ func TestZshConfig(t *testing.T) { langs=(ko ja) TGREP_TARGET_LANGS=${(j:,:)langs} TGREP_DOCS_DIR="$HOME/src" +DOCS_KO_ROOT=korean/docs TGREP_ENTER_ACTION=edit `, 0644) out, log, code := invoke(t, root, []string{"TGREP_ENTER_ACTION=print", "FZF_DEFAULT_OPTS=--filter=doc"}, []string{"hit"}) @@ -112,6 +113,53 @@ TGREP_ENTER_ACTION=edit } } +func TestPerLanguageRoots(t *testing.T) { + root, err := filepath.EvalSymlinks(t.TempDir()) + if err != nil { + t.Fatal(err) + } + const rel = "guide/setup.md" + source := filepath.Join(root, "docs/source pages", rel) + japanese := filepath.Join(root, "japanese checkout") + writeFile(t, source, "Sign\nin here\n", 0644) + writeFile(t, filepath.Join(japanese, rel), "ログイン\n", 0644) + writeFile(t, filepath.Join(root, "docs/ko", rel), "여기에서\n로그인\n", 0644) + writeFile(t, filepath.Join(root, ".config/tgrep/config"), `TGREP_DOCS_DIR=docs +TGREP_TARGET_LANGS=ja,ko +DOCS_EN_ROOT='source pages' +DOCS_JA_ROOT=other +`, 0644) + env := []string{"DOCS_JA_ROOT=" + japanese, "FZF_DEFAULT_OPTS=--filter=setup"} + out, log, code := invoke(t, root, append(env, "TGREP_ENTER_ACTION=print"), []string{"here"}) + if code != 0 || out != "docs/source pages/"+rel+":2:in here\n" { + t.Fatalf("print: %d %q %q", code, out, log) + } + writeFile(t, filepath.Join(root, "bin/vi"), "#!/bin/sh\nprintf '%s\\n' \"$@\"\n", 0755) + out, log, code = invoke(t, root, append(env, "EDITOR=vi"), []string{"here"}) + if code != 0 || out != "+2\n"+filepath.Join(japanese, rel)+"\n" { + t.Fatalf("edit: %d %q %q", code, out, log) + } + + // Picker callbacks inherit the values already resolved by the shell config. + callback := []string{"TGREP_DOCS_DIR=docs", "TGREP_TARGET_LANGS=ja,ko", "DOCS_EN_ROOT=source pages", "DOCS_JA_ROOT=" + japanese, + "TGREP_BEFORE_LINES=0", "TGREP_AFTER_LINES=0", "TGREP_QUERY=here"} + out, log, code = invoke(t, root, callback, []string{"--_preview", rel, "2"}) + want := "=== EN (source pages/" + rel + ":2) ===\n> 2 | in \x1b[1;31mhere\x1b[0m\n\n" + + "=== JA (" + filepath.Join(japanese, rel) + ":1) ===\n\x1b[1;33m> 1 | ログイン\x1b[0m\n\n" + + "=== KO (ko/" + rel + ":2) ===\n\x1b[1;33m> 2 | 로그인\x1b[0m\n" + if code != 0 || out != want { + t.Fatalf("preview: %d %q %q, want %q", code, out, log, want) + } + t.Run("compare", func(t *testing.T) { + checkComparison(t, root, `call assert_equal('source pages/guide/setup.md', bufname()) +call assert_equal(2, line('.')) +wincmd l +call assert_equal($DOCS_JA_ROOT . '/guide/setup.md', expand('%:p')) +call assert_equal(1, line('.')) +`, callback, []string{"--_compare", "1", rel, "2"}) + }) +} + func checkComparison(t *testing.T, root, check string, env, args []string) { t.Helper() vim, err := exec.LookPath("vim") diff --git a/internal/cli/cli.go b/internal/cli/cli.go index 0fea9f9..03993bd 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -70,13 +70,13 @@ func runSearch(self, query string, tree documents.Tree) error { } defer p.Close() c := tree.Config - matches, err := picker.Select(self, query, c.OriginDir(), files, p, c.Action == "edit") + matches, err := picker.Select(self, query, tree.Path(c.Origin, ""), files, p, c.Action == "edit") if err != nil { return err } for _, m := range matches { if c.Action == "print" { - if _, err := fmt.Fprintf(os.Stdout, "%s/%s:%d:%s\n", c.OriginDir(), m.Path, m.Line, m.Text); err != nil { + if _, err := fmt.Fprintf(os.Stdout, "%s:%d:%s\n", tree.Path(c.Origin, m.Path), m.Line, m.Text); err != nil { return err } continue @@ -118,11 +118,11 @@ func view(tree documents.Tree, args []string) (int, error) { } lang := c.Targets[n-1] if !tree.Has(lang, path) { - return picker.Message(fmt.Sprintf("No translation available for %s/%s.", lang, path)) + return picker.Message(fmt.Sprintf("No translation available for %s.", c.DocumentPath(lang, path))) } targetLine, err := tree.ComparisonLine(lang, path, line) if err != nil { return 1, err } - return 0, editor.Compare(c.Root, filepath.Join(c.Origin, path), filepath.Join(lang, path), line, targetLine) + return 0, editor.Compare(c.Root, c.DocumentPath(c.Origin, path), c.DocumentPath(lang, path), line, targetLine) } diff --git a/internal/config/config.go b/internal/config/config.go index f43c898..e109abe 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -16,12 +16,13 @@ import ( type Context struct{ Before, After int } type Config struct { - Root string - Origin string - TargetList string - Action string - Targets []string - Context map[string]Context + Root string + Origin string + TargetList string + Action string + Targets []string + Context map[string]Context + LanguageRoots map[string]string } // Source re-enters the binary with settings from the user's shell config. @@ -41,7 +42,7 @@ func Source(self string, args []string) error { shell, err := exec.LookPath("zsh") setup := "set -euo pipefail" - exports := "typeset -gx -m 'TGREP_*' || true" + exports := "typeset -gx -m 'TGREP_*' 'DOCS_*_ROOT' || true" if err != nil { shell = "/bin/sh" setup = "set -aeu" @@ -64,7 +65,8 @@ exec "$@" argv := []string{shell, "-c", script, "tgrep"} for _, item := range os.Environ() { key, value, _ := strings.Cut(item, "=") - if strings.HasPrefix(key, "TGREP_") && value != "" { + languageRoot := strings.HasPrefix(key, "DOCS_") && strings.HasSuffix(key, "_ROOT") + if value != "" && (strings.HasPrefix(key, "TGREP_") || languageRoot) { argv = append(argv, item) } } @@ -74,6 +76,17 @@ exec "$@" var nonKey = regexp.MustCompile(`[^A-Z0-9_]`) +func languageKey(lang string) string { + return nonKey.ReplaceAllString(strings.ToUpper(lang), "_") +} + +func expandHome(path string) string { + if strings.HasPrefix(path, "~") { + return os.Getenv("HOME") + path[1:] + } + return path +} + func setting(key, fallback string) string { if value := os.Getenv(key); value != "" { return value @@ -83,14 +96,12 @@ func setting(key, fallback string) string { func Load() (Config, error) { c := Config{ - Root: setting("TGREP_DOCS_DIR", "."), - Origin: setting("TGREP_ORIGIN_LANG", "en"), - TargetList: setting("TGREP_TARGET_LANGS", "ko,ja"), - Action: setting("TGREP_ENTER_ACTION", "edit"), - Context: make(map[string]Context), - } - if strings.HasPrefix(c.Root, "~") { - c.Root = os.Getenv("HOME") + c.Root[1:] + Root: expandHome(setting("TGREP_DOCS_DIR", ".")), + Origin: setting("TGREP_ORIGIN_LANG", "en"), + TargetList: setting("TGREP_TARGET_LANGS", "ko,ja"), + Action: setting("TGREP_ENTER_ACTION", "edit"), + Context: make(map[string]Context), + LanguageRoots: make(map[string]string), } if c.Action != "edit" && c.Action != "print" { return c, fmt.Errorf("TGREP_ENTER_ACTION must be 'edit' or 'print' (got '%s').", c.Action) @@ -107,6 +118,9 @@ func Load() (Config, error) { } } for _, lang := range append([]string{c.Origin}, c.Targets...) { + if root := os.Getenv("DOCS_" + languageKey(lang) + "_ROOT"); root != "" { + c.LanguageRoots[lang] = expandHome(root) + } before, err := lineCount(lang, "BEFORE") if err != nil { return c, err @@ -122,7 +136,7 @@ func Load() (Config, error) { func lineCount(lang, side string) (int, error) { base := "TGREP_" + side + "_LINES" - key := base + "_" + nonKey.ReplaceAllString(strings.ToUpper(lang), "_") + key := base + "_" + languageKey(lang) value := setting(key, setting(base, "3")) n, err := strconv.ParseUint(value, 10, strconv.IntSize-1) if err != nil { @@ -131,5 +145,11 @@ func lineCount(lang, side string) (int, error) { return int(n), nil } -// OriginDir retains the spelling of relative roots in print output. -func (c Config) OriginDir() string { return strings.TrimSuffix(c.Root, "/") + "/" + c.Origin } +// DocumentPath returns an absolute path or a path relative to Root. +func (c Config) DocumentPath(lang, rel string) string { + dir := c.LanguageRoots[lang] + if dir == "" { + dir = lang + } + return filepath.Join(dir, rel) +} diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 7d1e8a9..1695870 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -14,16 +14,26 @@ func TestLanguageSettings(t *testing.T) { t.Setenv("TGREP_BEFORE_LINES", "2") t.Setenv("TGREP_AFTER_LINES", "") t.Setenv("TGREP_AFTER_LINES_PT_BR", "0") + t.Setenv("DOCS_EN_ROOT", "") + t.Setenv("DOCS_KO_ROOT", "locales/korean") + t.Setenv("DOCS_PT_BR_ROOT", "~/pt-BR docs") c, err := Load() if err != nil { t.Fatal(err) } - if c.OriginDir() != "/home/example/docs/en" || c.Action != "edit" || !slices.Equal(c.Targets, []string{"ko", "pt-BR"}) { + if c.Root != "/home/example/docs" || c.Action != "edit" || !slices.Equal(c.Targets, []string{"ko", "pt-BR"}) { t.Fatalf("unexpected config: %+v", c) } if c.Context["pt-BR"] != (Context{2, 0}) || c.Context["ko"] != (Context{2, 3}) { t.Fatalf("context: %+v", c.Context) } + for lang, want := range map[string]string{ + "en": "en/guide", "ko": "locales/korean/guide", "pt-BR": "/home/example/pt-BR docs/guide", + } { + if got := c.DocumentPath(lang, "guide"); got != want { + t.Errorf("%s document path = %q, want %q", lang, got, want) + } + } } func TestInvalidSettings(t *testing.T) { diff --git a/internal/documents/tree.go b/internal/documents/tree.go index cd8ec75..773e44d 100644 --- a/internal/documents/tree.go +++ b/internal/documents/tree.go @@ -15,12 +15,16 @@ import ( type Tree struct { Config config.Config - git bool + git map[string]bool } func Open(c config.Config) Tree { - out, _ := exec.Command("git", "-C", c.Root, "rev-parse", "--is-inside-work-tree").Output() - return Tree{Config: c, git: strings.TrimSpace(string(out)) == "true"} + t := Tree{Config: c, git: make(map[string]bool)} + for _, lang := range append([]string{c.Origin}, c.Targets...) { + out, _ := exec.Command("git", "-C", t.Path(lang, ""), "rev-parse", "--is-inside-work-tree").Output() + t.git[lang] = strings.TrimSpace(string(out)) == "true" + } + return t } func regular(path string) bool { @@ -28,22 +32,29 @@ func regular(path string) bool { return err == nil && info.Mode().IsRegular() } -func (t Tree) Path(lang, rel string) string { return filepath.Join(t.Config.Root, lang, rel) } +func (t Tree) Path(lang, rel string) string { + path := t.Config.DocumentPath(lang, rel) + if filepath.IsAbs(path) || t.Config.Root == "" { + return path + } + // Preserve relative roots such as "./en" in printed search results. + return strings.TrimSuffix(t.Config.Root, "/") + "/" + path +} func (t Tree) Has(lang, rel string) bool { if !regular(t.Path(lang, rel)) { return false } - if !t.git { + if !t.git[lang] { return true } // A tracked file remains available even if a later ignore rule matches it. - return exec.Command("git", "-C", t.Config.Root, "check-ignore", "-q", "--", filepath.Join(lang, rel)).Run() != nil + return exec.Command("git", "-C", t.Path(lang, ""), "check-ignore", "-q", "--", "./"+rel).Run() != nil } func (t Tree) files(lang string) ([]string, error) { dir := t.Path(lang, "") - if t.git { + if t.git[lang] { raw, err := exec.Command("git", "-C", dir, "ls-files", "-z", "--cached", "--others", "--exclude-standard", "--", ".").Output() if err != nil { return nil, err @@ -81,8 +92,9 @@ func (t Tree) files(lang string) ([]string, error) { func (t Tree) PairedFiles() ([]string, error) { c := t.Config - if info, err := os.Stat(c.OriginDir()); err != nil || !info.IsDir() { - return nil, fmt.Errorf("Origin directory not found: %s", c.OriginDir()) + originDir := t.Path(c.Origin, "") + if info, err := os.Stat(originDir); err != nil || !info.IsDir() { + return nil, fmt.Errorf("Origin directory not found: %s", originDir) } translated := make(map[string]bool) for _, lang := range c.Targets { diff --git a/internal/documents/tree_test.go b/internal/documents/tree_test.go index dd868bf..8b66669 100644 --- a/internal/documents/tree_test.go +++ b/internal/documents/tree_test.go @@ -78,3 +78,47 @@ func TestPairedFiles(t *testing.T) { }) } } + +func TestPairedFilesAcrossRepositories(t *testing.T) { + if _, err := exec.LookPath("git"); err != nil { + t.Skip("git unavailable") + } + base, korean, japanese := t.TempDir(), t.TempDir(), t.TempDir() + source := filepath.Join(base, "en") + for dir, names := range map[string][]string{ + source: {"keep", "source-ignored", "target-ignored", "plain"}, + korean: {"keep", "source-ignored", "target-ignored"}, + japanese: {"plain"}, + } { + if err := os.MkdirAll(filepath.Join(dir, "guide"), 0755); err != nil { + t.Fatal(err) + } + for _, name := range names { + if err := os.WriteFile(filepath.Join(dir, "guide", name), nil, 0644); err != nil { + t.Fatal(err) + } + } + } + for dir, ignored := range map[string]string{source: "source-ignored", korean: "target-ignored", japanese: "plain"} { + if err := os.WriteFile(filepath.Join(dir, ".gitignore"), []byte(ignored+"\n"), 0644); err != nil { + t.Fatal(err) + } + } + for _, dir := range []string{source, korean} { + if out, err := exec.Command("git", "-C", dir, "init", "-q").CombinedOutput(); err != nil { + t.Fatalf("git init: %v: %s", err, out) + } + } + tree := Open(config.Config{Root: base, Origin: "en", Targets: []string{"ko", "ja"}, + LanguageRoots: map[string]string{"ko": korean, "ja": japanese}}) + got, err := tree.PairedFiles() + if err != nil { + t.Fatal(err) + } + if !slices.Equal(got, []string{"guide/keep", "guide/plain"}) { + t.Errorf("paired files = %q", got) + } + if tree.Has("ko", "guide/target-ignored") || !tree.Has("ja", "guide/plain") { + t.Error("translation availability disagrees with per-root Git rules") + } +} diff --git a/internal/editor/editor.go b/internal/editor/editor.go index 1c962d9..6e74066 100644 --- a/internal/editor/editor.go +++ b/internal/editor/editor.go @@ -76,7 +76,9 @@ func Compare(root, origin, target string, sourceLine, targetLine int) error { cmd := exec.Command("vim", "-u", "NONE", "-i", "NONE", "-n", "-m", "-O", "--cmd", "set nocompatible nomodeline ttimeout ttimeoutlen=80 shortmess+=F", "-S", script.Name(), "-c", fmt.Sprintf("call OpenComparison(%d, %d)", sourceLine, targetLine), "--", origin, target) - cmd.Dir = root + if !filepath.IsAbs(origin) || !filepath.IsAbs(target) { + cmd.Dir = root + } cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr return cmd.Run() } diff --git a/internal/search/preview.go b/internal/search/preview.go index e8a580b..e428395 100644 --- a/internal/search/preview.go +++ b/internal/search/preview.go @@ -29,7 +29,7 @@ func (p *Pattern) Preview(w io.Writer, tree documents.Tree, m Match) error { if i != 0 { fmt.Fprintln(out) } - fmt.Fprintf(out, "=== %s (%s/%s:%d) ===\n", strings.ToUpper(lang), lang, m.Path, line) + fmt.Fprintf(out, "=== %s (%s:%d) ===\n", strings.ToUpper(lang), c.DocumentPath(lang, m.Path), line) err = p.snippet(out, f, c.Context[lang], line, i == 0) f.Close() if err != nil { From 3f3babbef6f254664b465212faa7a99bb2c7a8f5 Mon Sep 17 00:00:00 2001 From: jinil-ha Date: Tue, 1 Dec 2026 01:33:17 +0900 Subject: [PATCH 2/3] Remove Test workflow triggers and keep its job definition --- .github/workflows/{test.yml => test.yml.disabled} | 5 ----- 1 file changed, 5 deletions(-) rename .github/workflows/{test.yml => test.yml.disabled} (87%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml.disabled similarity index 87% rename from .github/workflows/test.yml rename to .github/workflows/test.yml.disabled index 75ed402..13c70eb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml.disabled @@ -1,10 +1,5 @@ name: Test -on: - pull_request: - push: - branches: [main] - permissions: contents: read From 1ec6cd51b8a18763af1d91ffb956be26efa6cd4a Mon Sep 17 00:00:00 2001 From: jinil-ha Date: Tue, 1 Dec 2026 01:35:02 +0900 Subject: [PATCH 3/3] Run the Test workflow on manual dispatch only --- .github/workflows/{test.yml.disabled => test.yml} | 3 +++ 1 file changed, 3 insertions(+) rename .github/workflows/{test.yml.disabled => test.yml} (92%) diff --git a/.github/workflows/test.yml.disabled b/.github/workflows/test.yml similarity index 92% rename from .github/workflows/test.yml.disabled rename to .github/workflows/test.yml index 13c70eb..4324815 100644 --- a/.github/workflows/test.yml.disabled +++ b/.github/workflows/test.yml @@ -1,5 +1,8 @@ name: Test +on: + workflow_dispatch: + permissions: contents: read