From 055c00fa04fcfc4c8e3ac4d84a9944c8274e0434 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 22 Jun 2025 14:39:28 +1200 Subject: [PATCH] Improve gp script: fix autocomplete and enhance change detection logic --- gp/gp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/gp/gp b/gp/gp index 71ca32e..d3d32d2 100755 --- a/gp/gp +++ b/gp/gp @@ -131,10 +131,25 @@ check_git_repo() { # Function to check for uncommitted changes check_for_changes() { - if git diff --cached --quiet && git diff --quiet; then - if [ "$ADD_ALL" = false ]; then - print_warning "No staged changes found" - print_info "Use 'gp -a' to add all files, or stage changes first with 'git add'" + local has_staged=$(! git diff --cached --quiet && echo "true" || echo "false") + local has_modified=$(! git diff --quiet && echo "true" || echo "false") + local has_untracked=$([ -n "$(git ls-files --others --exclude-standard)" ] && echo "true" || echo "false") + + # If add-all is enabled, check if we have any changes at all + if [ "$ADD_ALL" = true ]; then + if [ "$has_staged" = false ] && [ "$has_modified" = false ] && [ "$has_untracked" = false ]; then + print_info "No changes to commit (working tree clean)" + exit 0 + fi + else + # If add-all is disabled, only check staged changes + if [ "$has_staged" = false ]; then + if [ "$has_modified" = true ] || [ "$has_untracked" = true ]; then + print_warning "No staged changes found" + print_info "Use 'gp -a' to add all files, or stage changes first with 'git add'" + else + print_info "No changes to commit (working tree clean)" + fi exit 0 fi fi