add auto to gacp
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
: "${GIT_MAIN_BRANCH:=main}"
|
||||
: "${GIT_DEFAULT_REMOTE:=origin}"
|
||||
: "${GIT_WIP_PREFIX:=wip}"
|
||||
: "${GIT_GACP_AUTO_ADD:=1}"
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
@@ -231,7 +232,7 @@ export -f gsync
|
||||
gacp()
|
||||
{
|
||||
local PARSED
|
||||
PARSED=$(getopt -o hm: --long help,message: -n 'gacp' -- "$@")
|
||||
PARSED=$(getopt -o ham: --long help,auto,message: -n 'gacp' -- "$@")
|
||||
# shellcheck disable=SC2181 # getopt return code is checked immediately after
|
||||
if [[ $? -ne 0 ]]; then
|
||||
disp E "Invalid options, use \"gacp --help\" to display usage."
|
||||
@@ -239,20 +240,26 @@ gacp()
|
||||
fi
|
||||
|
||||
eval set -- "$PARSED"
|
||||
local msg=""
|
||||
local msg="" auto_add="$GIT_GACP_AUTO_ADD"
|
||||
while true; do
|
||||
case "$1" in
|
||||
-h|--help)
|
||||
printf "gacp: Run git add, git commit, and git push in one command.\n"
|
||||
printf "Usage: gacp -m \"message\" [file1 file2 ...]\n"
|
||||
printf "Usage: gacp [-a] -m \"message\" [file1 file2 ...]\n"
|
||||
printf "Options:\n"
|
||||
printf "\t-a, --auto\tAutomatically add all modified files (git add -A)\n"
|
||||
printf "\t-m, --message\tCommit message (mandatory)\n"
|
||||
printf "\n"
|
||||
printf "If files are provided, only those paths are added.\n"
|
||||
printf "If no file is provided, all changes are added with git add -A.\n"
|
||||
printf "If files are provided, only those paths are added (-a is ignored).\n"
|
||||
printf "If no file is provided and -a is active, all changes are added with git add -A.\n"
|
||||
printf "Default for -a can be set via GIT_GACP_AUTO_ADD in profile.conf.\n"
|
||||
printf "If the remote branch moved forward, gacp pulls with rebase before pushing.\n"
|
||||
return 0
|
||||
;;
|
||||
-a|--auto)
|
||||
auto_add=1
|
||||
shift
|
||||
;;
|
||||
-m|--message)
|
||||
msg="$2"
|
||||
shift 2
|
||||
@@ -275,16 +282,20 @@ gacp()
|
||||
return 1
|
||||
fi
|
||||
|
||||
local branch upstream remote tracking_branch ahead behind counts
|
||||
local branch upstream remote tracking_branch behind counts
|
||||
branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) || return 1
|
||||
upstream=$(git rev-parse --abbrev-ref --symbolic-full-name '@{u}' 2>/dev/null) || true
|
||||
|
||||
if [[ $# -gt 0 ]]; then
|
||||
auto_add=0
|
||||
disp I "Adding selected paths..."
|
||||
git add -- "$@" || return 1
|
||||
else
|
||||
elif [[ $auto_add -eq 1 ]]; then
|
||||
disp I "Adding all changes..."
|
||||
git add -A || return 1
|
||||
else
|
||||
disp E "No files specified. Use -a/--auto or provide file paths."
|
||||
return 1
|
||||
fi
|
||||
|
||||
if git diff --cached --quiet; then
|
||||
@@ -308,7 +319,7 @@ gacp()
|
||||
|
||||
if git rev-parse --verify --quiet "refs/remotes/${remote}/${tracking_branch}" >/dev/null; then
|
||||
counts=$(git rev-list --left-right --count HEAD..."${remote}/${tracking_branch}" 2>/dev/null) || return 1
|
||||
read -r ahead behind <<< "$counts"
|
||||
read -r _ behind <<< "$counts"
|
||||
if [[ ${behind:-0} -gt 0 ]]; then
|
||||
disp I "Remote branch is ahead, rebasing before push..."
|
||||
git pull --rebase "$remote" "$tracking_branch" || return 1
|
||||
|
||||
Reference in New Issue
Block a user