From 57c2ef09287c8520efe905b5964ed8e9d677baf6 Mon Sep 17 00:00:00 2001 From: Ramesh Padmanabhaiah <22363102+codeforester@users.noreply.github.com> Date: Sun, 9 Aug 2026 11:40:19 -0700 Subject: [PATCH] make git dirty-path inspection cwd independent --- lib/bash/git/lib_git.sh | 8 ++++---- lib/bash/git/tests/lib_git.bats | 12 +++++------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/bash/git/lib_git.sh b/lib/bash/git/lib_git.sh index 853e5a4..6f64250 100644 --- a/lib/bash/git/lib_git.sh +++ b/lib/bash/git/lib_git.sh @@ -214,13 +214,13 @@ __base_bash_libs_git_path_matches_allowed_path__() { } __base_bash_libs_git_only_path_dirty__() { - (($# == 1)) || return 1 + (($# == 2)) || return 1 - local allowed_path="$1" + local repo_dir="$1" allowed_path="$2" local status_file status_record status_code path related_path base_std_make_temp_file status_file base-git-status || return 1 - if ! git status --porcelain=v1 --untracked-files=no --ignore-submodules=none -z > "$status_file"; then + if ! git -C "$repo_dir" status --porcelain=v1 --untracked-files=no --ignore-submodules=none -z > "$status_file"; then base_std_unregister_cleanup_path "$status_file" rm -f -- "$status_file" return 1 @@ -400,7 +400,7 @@ base_git_update_repo() { dirty=true fi if [[ "$dirty" == true ]]; then - if [[ -n "$allowed_dirty_path" ]] && __base_bash_libs_git_only_path_dirty__ "$allowed_dirty_path"; then + if [[ -n "$allowed_dirty_path" ]] && __base_bash_libs_git_only_path_dirty__ "$git_repo" "$allowed_dirty_path"; then base_std_log_debug -l base_bash_libs.git "Repo '$git_repo' only has tracked changes in '$allowed_dirty_path'; attempting git pull." else base_std_log_debug -l base_bash_libs.git "Repo '$git_repo' has local changes; skipping auto-update. Commit or stash to enable git pull." diff --git a/lib/bash/git/tests/lib_git.bats b/lib/bash/git/tests/lib_git.bats index f97a043..7170696 100644 --- a/lib/bash/git/tests/lib_git.bats +++ b/lib/bash/git/tests/lib_git.bats @@ -658,10 +658,8 @@ EOF printf 'local one\n' > "$repo/shared/one.txt" printf 'local two\n' > "$repo/shared/two.txt" - pushd "$repo" >/dev/null - __base_bash_libs_git_only_path_dirty__ "shared" + __base_bash_libs_git_only_path_dirty__ "$repo" "shared" rc=$? - popd >/dev/null [ "$rc" -eq 0 ] } @@ -677,7 +675,7 @@ EOF printf 'local change\n' >> "$repo/shared/hello world.txt" pushd "$repo" >/dev/null - __base_bash_libs_git_only_path_dirty__ "shared" + __base_bash_libs_git_only_path_dirty__ "$repo" "shared" rc=$? popd >/dev/null @@ -698,7 +696,7 @@ EOF pushd "$repo" >/dev/null set +e - __base_bash_libs_git_only_path_dirty__ "shared" + __base_bash_libs_git_only_path_dirty__ "$repo" "shared" rc=$? set -e popd >/dev/null @@ -718,7 +716,7 @@ EOF pushd "$repo" >/dev/null set +e - __base_bash_libs_git_only_path_dirty__ "shared" + __base_bash_libs_git_only_path_dirty__ "$repo" "shared" rc=$? set -e popd >/dev/null @@ -737,7 +735,7 @@ EOF git -C "$repo" mv shared/one.txt shared/two.txt pushd "$repo" >/dev/null - __base_bash_libs_git_only_path_dirty__ "shared" + __base_bash_libs_git_only_path_dirty__ "$repo" "shared" rc=$? popd >/dev/null