unixorn/git-extra-commands

View on GitHub
bin/git-comma

Summary

Maintainability
Test Coverage
#!/usr/bin/env zsh
#
# git comma - like git commit, but adds unknown files automatically
#
# Source: https://leahneukirchen.org/blog/archive/2013/01/a-grab-bag-of-git-tricks.html

added=()

# add unknown files...
for arg; do
  if [[ -f "$arg" && -n $(git ls-files -o "$arg") ]]; then
    git add "$arg"
    added+=($arg)
  fi
done

# ...reset them when commit is aborted
git commit ${@:+-o} "$@" || git reset -q -- "$added"