fix: open file from subdirectory using GIT_PREFIX var

This commit is contained in:
2026-02-17 12:41:25 +02:00
parent e185d99fc6
commit 443ebeb9c8
2 changed files with 4 additions and 1 deletions

View File

@@ -121,7 +121,7 @@ git_open_file() {
fi
repo_path=$(git_get_repo_path $remote)
prefix=$(git rev-parse --show-prefix 2>/dev/null)
prefix=${GIT_PREFIX:-$(git rev-parse --show-prefix 2>/dev/null)}
file=$([[ -n "$2" ]] && echo "${prefix}$2" || echo "")
branch=$([[ -n "$3" ]] && echo "$3" || git branch --show-current)

View File

@@ -71,6 +71,9 @@ assert_value "https://github.com/chenasraf/git-open/blob/develop/test.zsh" $(git
describe "git_open_file from subdirectory"
assert_value "https://github.com/chenasraf/git-open/blob/$current_branch/tests/test.zsh" $(cd "${0:A:h}" && git_open_file "" test.zsh)
describe "git_open_file from subdirectory (via git alias)"
assert_value "https://github.com/chenasraf/git-open/blob/$current_branch/tests/test.zsh" $(GIT_PREFIX=tests/ git_open_file "" test.zsh)
describe "git_open_commit"
assert_value "https://github.com/chenasraf/git-open/commit/1a4c2b6" $(git_open_commit "" 1a4c2b6)
assert_value "https://github.com/chenasraf/git-open/commit/$current_ref" $(git_open_commit)