check if file is tracked before adding

and tell user useful information in case they want to
hide a file that's tracked.
pull/156/head
joshr 7 years ago
parent ffa89ceaa2
commit 13170c313f

@ -351,6 +351,18 @@ function _is_inside_git_tree {
echo "$result"
}
function _is_tracked_in_git {
local filename="$1" # required
local result
result="$(git ls-files --error-unmatch "$filename" >/dev/null 2>&1; echo $?)"
if [[ "$result" -eq 0 ]]; then
echo "1"
else
echo "0"
fi
}
function _get_git_root_path {
# We need this function to get the location of the `.git` folder,

@ -33,8 +33,10 @@ function add {
path=$(_append_root_path "$normalized_path")
# check that the file is not tracked
if [[ $(git ls-files --error-unmatch "$item") ]]; then
_abort "file tracked in git, consider using 'git rm --cached $item'"
local in_git
in_git=$(_is_tracked_in_git "$item")
if [[ "$in_git" -ne 0 ]]; then
_abort "file tracked in git, consider using 'git rm --cached $item'"
fi
# Checking that file is valid:
@ -57,7 +59,7 @@ function add {
if [[ ! "${#not_ignored[@]}" -eq 0 ]]; then
# And show them all at once.
local message
message="these files are not in .gitignore: $* ;"
message="these files are not in .gitignore: $*"
if [[ "$auto_ignore" -eq 0 ]]; then
# This file is not ignored. user don't want it to be added automatically.

Loading…
Cancel
Save