mirror of
https://github.com/wfxr/forgit.git
synced 2026-09-10 07:16:23 -04:00
fix: forgit add shows dir view for submodules (#484)
This commit is contained in:
parent
024389f799
commit
151d61daff
|
|
@ -166,6 +166,10 @@ _forgit_list_files() {
|
|||
git ls-files -z "$@" "$rootdir" | tr '\0' '\n' | uniq
|
||||
}
|
||||
|
||||
_forgit_is_submodule() {
|
||||
git submodule --quiet status "$1"
|
||||
}
|
||||
|
||||
_forgit_log_preview() {
|
||||
local sha
|
||||
sha=$(echo "$1" | _forgit_extract_sha)
|
||||
|
|
@ -418,10 +422,12 @@ _forgit_show() {
|
|||
|
||||
_forgit_add_preview() {
|
||||
file=$(echo "$1" | _forgit_get_single_file_from_add_line)
|
||||
# $file can be a directory when status.showUntrackedFiles is explicitly set to 'normal'
|
||||
# In this case, show the content of the directory and return
|
||||
[ -d "$file" ] && eval "$_forgit_dir_view \"$file\"" && return 0
|
||||
|
||||
# $file can be a directory when status.showUntrackedFiles is set to 'normal'
|
||||
# When this is the case and the directory is not a submodule show the content of the directory and return
|
||||
if [[ -d "$file" ]] && ! _forgit_is_submodule "$file"; then
|
||||
eval "$_forgit_dir_view \"$file\""
|
||||
return 0
|
||||
fi
|
||||
if (git status -s -- "$file" | grep '^??') &>/dev/null; then # diff with /dev/null for untracked files
|
||||
git diff --color=always --no-index -- /dev/null "$file" | _forgit_pager diff | sed '2 s/added:/untracked:/'
|
||||
else
|
||||
|
|
|
|||
63
tests/is-submodule.test.sh
Normal file
63
tests/is-submodule.test.sh
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
function set_up_before_script() {
|
||||
local submod submod1
|
||||
source bin/git-forgit
|
||||
|
||||
# Ignore global git config files
|
||||
export GIT_CONFIG_SYSTEM=/dev/null
|
||||
export GIT_CONFIG_GLOBAL=/dev/null
|
||||
|
||||
# create repositories for submodule usage
|
||||
submod=$(create_submodule)
|
||||
submod1=$(create_submodule)
|
||||
|
||||
# create a new git repository in a temp directory
|
||||
create_repo
|
||||
|
||||
# create submodules to test against
|
||||
git -c protocol.file.allow=always submodule add "$submod" submodule
|
||||
git -c protocol.file.allow=always submodule add "$submod1" 'submodule with spaces'
|
||||
|
||||
# create regular directories
|
||||
mkdir regular-directory
|
||||
mkdir 'directory with spaces'
|
||||
}
|
||||
|
||||
function create_submodule() {
|
||||
create_repo
|
||||
touch file
|
||||
git add file
|
||||
git commit -q -m "initial commit"
|
||||
}
|
||||
|
||||
function create_repo() {
|
||||
cd "$(bashunit::temp_dir)" || return 1
|
||||
git init --quiet
|
||||
git config user.email "test@example.com"
|
||||
git config user.name "Test User"
|
||||
pwd
|
||||
}
|
||||
|
||||
# @data_provider provider_is_submodule
|
||||
function test_forgit_is_submodule() {
|
||||
_forgit_is_submodule "$1"
|
||||
assert_exit_code "0"
|
||||
}
|
||||
|
||||
function provider_is_submodule() {
|
||||
bashunit::data_set submodule
|
||||
bashunit::data_set 'submodule with spaces'
|
||||
}
|
||||
|
||||
# @data_provider provider_is_no_submodule
|
||||
function test_forgit_is_no_submodule() {
|
||||
_forgit_is_submodule "$1"
|
||||
assert_exit_code "1"
|
||||
}
|
||||
|
||||
function provider_is_no_submodule() {
|
||||
bashunit::data_set regular-directory
|
||||
bashunit::data_set 'directory with spaces'
|
||||
bashunit::data_set unknown
|
||||
}
|
||||
Loading…
Reference in a new issue