@@ -12,9 +12,18 @@ target_java_files=()
1212target_mode=" staged"
1313pre_format_snapshot=" "
1414
15+ canonicalize_path () {
16+ local input_path=" $1 "
17+ local dir_path
18+ local base_name
19+
20+ dir_path=" $( cd " $( dirname " $input_path " ) " && pwd -P) " || return 1
21+ base_name=" $( basename " $input_path " ) "
22+ printf ' %s/%s\n' " $dir_path " " $base_name "
23+ }
24+
1525resolve_target_java_file () {
1626 local input_file=" $1 "
17- local candidate_path=" "
1827 local resolved_file=" "
1928 local matched_files=" "
2029 local match_count
@@ -25,11 +34,20 @@ resolve_target_java_file() {
2534 esac
2635
2736 if [ -f " $input_file " ]; then
28- candidate_path=" $input_file "
37+ resolved_file=" $( canonicalize_path " $input_file " ) " || {
38+ echo " [오류] 파일 경로를 정규화할 수 없습니다: $input_file " >&2
39+ return 1
40+ }
2941 elif [ -f " $invocation_dir /$input_file " ]; then
30- candidate_path=" $invocation_dir /$input_file "
42+ resolved_file=" $( canonicalize_path " $invocation_dir /$input_file " ) " || {
43+ echo " [오류] 파일 경로를 정규화할 수 없습니다: $input_file " >&2
44+ return 1
45+ }
3146 elif [ -f " $repo_root /$input_file " ]; then
32- candidate_path=" $repo_root /$input_file "
47+ resolved_file=" $( canonicalize_path " $repo_root /$input_file " ) " || {
48+ echo " [오류] 파일 경로를 정규화할 수 없습니다: $input_file " >&2
49+ return 1
50+ }
3351 else
3452 matched_files=" $( git ls-files -- " $input_file " " */$input_file " 2> /dev/null || true) "
3553 if [ -z " $matched_files " ]; then
@@ -43,11 +61,10 @@ resolve_target_java_file() {
4361 return 1
4462 fi
4563
46- candidate_path=" $repo_root /$matched_files "
47- fi
48-
49- if [ -n " $candidate_path " ]; then
50- resolved_file=" $( cd " $( dirname " $candidate_path " ) " && pwd -P) /$( basename " $candidate_path " ) "
64+ resolved_file=" $( canonicalize_path " $repo_root /$matched_files " ) " || {
65+ echo " [오류] 파일 경로를 정규화할 수 없습니다: $input_file " >&2
66+ return 1
67+ }
5168 fi
5269
5370 case " $resolved_file " in
448465 echo " [완료] 지정된 Java 파일에 변경할 내용이 없습니다."
449466 fi
450467fi
468+
0 commit comments