unixorn/git-extra-commands

View on GitHub
bin/git-sp

Summary

Maintainability
Test Coverage
#!/usr/bin/env bash
#
# Author: A. Schwarz
# Usage: git sp [-a] <message>
#
# "Simple push": commit with message and push. Use -a flag to add changed files
#    to commit.
#
# See https://github.com/Schwarzy1/git-sp for more information.
#

usage(){
  echo "usage: git sp [-a] <message>

  Commits and pushes to current working branch.
  -a  Run 'git add -A' prior to committing."
  exit 1
}

# -a should trigger `git add -A`
while getopts 'a' flag; do
  aflag='true'
done

if test "$#" -lt 1
then
  usage
else
  if test $aflag
  then
    git add -A
    git commit -m "$2"
  else
    git commit -m "$1"
  fi
  git push
fi