Skip to content

Commit 9a4ff16

Browse files
sandr01dcarlfriedrich
authored andcommitted
Fix: files in untracked directories are not shown in git add
Pass the value of git config status.showUntrackedFiles to the git status command we run in _forgit_add, defaulting to 'all' when unset. Additionally correctly handle directories in _forgit_add_preview for the case when status.showUntracked is explicitly set to 'normal'.
1 parent 8285d2e commit 9a4ff16

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

bin/git-forgit

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,10 @@ _forgit_show() {
430430

431431
_forgit_add_preview() {
432432
file=$(echo "$1" | _forgit_get_single_file_from_add_line)
433+
# $file can be a directory when status.showUntrackedFiles is explicitly set to 'normal'
434+
# In this case, show the content of the directory and return
435+
[ -d "$file" ] && eval "$_forgit_dir_view \"$file\"" && return 0
436+
433437
if (git status -s -- "$file" | grep '^??') &>/dev/null; then # diff with /dev/null for untracked files
434438
git diff --color=always --no-index -- /dev/null "$file" | _forgit_pager diff | sed '2 s/added:/untracked:/'
435439
else
@@ -460,7 +464,7 @@ _forgit_edit_add_file() {
460464
# git add selector
461465
_forgit_add() {
462466
_forgit_inside_work_tree || return 1
463-
local changed unmerged untracked files opts
467+
local changed unmerged untracked files opts show_untracked
464468
# Add files if passed as arguments
465469
_forgit_contains_non_flags "$@" && { _forgit_git_add "$@" && git status -s; return $?; }
466470

@@ -475,9 +479,10 @@ _forgit_add() {
475479
$FORGIT_ADD_FZF_OPTS
476480
"
477481
files=()
482+
show_untracked=$(git config status.showUntrackedFiles)
478483
while IFS='' read -r file; do
479484
files+=("$file")
480-
done < <(git -c color.status=always -c status.relativePaths=true -c core.quotePath=false status -s |
485+
done < <(git -c color.status=always -c status.relativePaths=true -c core.quotePath=false status -s --untracked="${show_untracked:-all}" |
481486
grep -F -e "$changed" -e "$unmerged" -e "$untracked" |
482487
sed -E 's/^(..[^[:space:]]*)[[:space:]]+(.*)$/[\1] \2/' |
483488
FZF_DEFAULT_OPTS="$opts" fzf |

0 commit comments

Comments
 (0)