Skip to content

Commit 301aed6

Browse files
committed
fix: open file from subdirectory
1 parent 46003ab commit 301aed6

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

git-open.zsh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ git_open_file() {
121121
fi
122122

123123
repo_path=$(git_get_repo_path $remote)
124-
file=$([[ -n "$2" ]] && echo "$2" || echo "")
124+
prefix=$(git rev-parse --show-prefix 2>/dev/null)
125+
file=$([[ -n "$2" ]] && echo "${prefix}$2" || echo "")
125126
branch=$([[ -n "$3" ]] && echo "$3" || git branch --show-current)
126127

127128
case "$remote_type" in

tests/test.zsh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ describe "git_open_file"
6868
assert_value "https://github.com/chenasraf/git-open/blob/$current_branch/test.zsh" $(git_open_file "" test.zsh)
6969
assert_value "https://github.com/chenasraf/git-open/blob/develop/test.zsh" $(git_open_file "" test.zsh develop)
7070

71+
describe "git_open_file from subdirectory"
72+
assert_value "https://github.com/chenasraf/git-open/blob/$current_branch/tests/test.zsh" $(cd "${0:A:h}" && git_open_file "" test.zsh)
73+
7174
describe "git_open_commit"
7275
assert_value "https://github.com/chenasraf/git-open/commit/1a4c2b6" $(git_open_commit "" 1a4c2b6)
7376
assert_value "https://github.com/chenasraf/git-open/commit/$current_ref" $(git_open_commit)

0 commit comments

Comments
 (0)