Skip to content

Commit 1125ca0

Browse files
committed
Properly cover directory names with trailing newlines
This doesn't happen on Windows filesystems, but can happen elsewhere. It can happen on occasion by accident.
1 parent e4e128c commit 1125ca0

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

etc/copy-packetline.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,23 @@ function fail () {
1717
}
1818

1919
function chdir_toplevel() {
20-
local root
20+
local root_padded root
2121

22-
# NOTE: We get the wrong directory name, if the name ends in newline.
23-
root="$(git rev-parse --show-toplevel)" ||
22+
# Find the working tree's root. (Padding is for the trailing-newline case.)
23+
root_padded="$(git rev-parse --show-toplevel && echo -n .)" ||
2424
fail 'git-rev-parse failed to find top-level dir'
25+
root="${root_padded%$'\n.'}"
2526

2627
cd -- "$root"
2728
}
2829

2930
function merging () {
30-
local git_dir
31+
local git_dir_padded git_dir
3132

32-
# NOTE: We get the wrong directory name, if the name ends in newline.
33-
git_dir="$(git rev-parse --git-dir)" ||
33+
# Find the .git directory. (Padding is for the trailing-newline case.)
34+
git_dir_padded="$(git rev-parse --git-dir && echo -n .)" ||
3435
fail 'git-rev-parse failed to find git dir'
36+
git_dir="${git_dir_padded%$'\n.'}"
3537

3638
test -e "$git_dir/MERGE_HEAD"
3739
}

0 commit comments

Comments
 (0)