mirror of
https://github.com/tj/git-extras.git
synced 2026-09-10 07:26:17 -04:00
Suggested fixes (iteration over arguments, pattern removal, editor handling, tmp file location, symlinked gitignore handling).
This commit is contained in:
parent
69124b91bf
commit
044f8e6b31
|
|
@ -30,17 +30,6 @@ cd_to_git_root() {
|
|||
fi
|
||||
}
|
||||
|
||||
get_tmp_file() {
|
||||
local tmpfile=
|
||||
if ! git rev-parse --git-dir &>/dev/null || [ -z "$GIT_DIR" ]; then
|
||||
tmpfile="$(mktemp -q "${TMPDIR:-/tmp}"/git-extras-ignore.XXXXXX 2>/dev/null)"
|
||||
else
|
||||
cd_to_git_root --warn &>/dev/null
|
||||
tmpfile="$(mktemp -q "$GIT_DIR"/git-extras-ignore.XXXXXX 2>/dev/null)"
|
||||
fi
|
||||
echo "${tmpfile:-$(mktemp -q)}"
|
||||
}
|
||||
|
||||
global_ignore() {
|
||||
if ! git config --global core.excludesFile 2>/dev/null; then
|
||||
if [ -f "$HOME/.gitignore" ]; then
|
||||
|
|
@ -110,7 +99,7 @@ add_patterns() {
|
|||
edit_file() {
|
||||
local file="${2/#~/$HOME}"
|
||||
if [ -f "$file" ]; then
|
||||
echo "Editing $1 gitignore ($2)..." && $(git var GIT_EDITOR) "$file"
|
||||
echo "Editing $1 gitignore ($2)..." && eval "$(git var GIT_EDITOR) $file"
|
||||
echo "Done."
|
||||
else
|
||||
echo "There is no $1 .gitignore yet." >&2
|
||||
|
|
@ -127,22 +116,23 @@ remove_patterns() {
|
|||
declare -a args
|
||||
local tmpfile
|
||||
args=( "${@:3}" )
|
||||
tmpfile="$(get_tmp_file)"
|
||||
tmpfile="$(mktemp -q "${TMPDIR:-/tmp}"/git-extras-ignore.XXXXXX 2>/dev/null)"
|
||||
local file="${2/#~/$HOME}"
|
||||
if [ -f "$file" ]; then
|
||||
echo "Removing patterns from $1 gitignore ($2)..."
|
||||
while read -r line; do
|
||||
while IFS= read -r line || [ -n "$line" ]; do
|
||||
local drop=
|
||||
for pattern in "${args[@]}"; do
|
||||
test "$pattern" = "$line" && drop="yes"
|
||||
done
|
||||
if [ -z "$drop" ]; then
|
||||
echo "$line" >> "$tmpfile"
|
||||
printf '%s\n' "$line" >> "$tmpfile"
|
||||
else
|
||||
echo "Removed $line pattern."
|
||||
fi
|
||||
done < "$file"
|
||||
mv "$tmpfile" "$file" # tmp file created in get_tmp_file 'deleted'
|
||||
cat "$tmpfile" > "$file"
|
||||
rm "$tmpfile"
|
||||
echo "Done."
|
||||
else
|
||||
echo "There is no $1 .gitignore yet"
|
||||
|
|
@ -165,7 +155,7 @@ else
|
|||
level="none"
|
||||
action="none"
|
||||
declare -a args
|
||||
while [ "$1" != "" ]; do
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
-h|--help)
|
||||
_usage
|
||||
|
|
|
|||
Loading…
Reference in a new issue