Add unpushed commits detection to gp script
Some checks failed
Build-Test-Publish / test-install-from-scratch (linux/amd64) (push) Has been cancelled
Build-Test-Publish / test-install-from-scratch (linux/arm64) (push) Has been cancelled
Build-Test-Publish / build (linux/amd64) (push) Has been cancelled
Build-Test-Publish / build (linux/arm64) (push) Has been cancelled
Some checks failed
Build-Test-Publish / test-install-from-scratch (linux/amd64) (push) Has been cancelled
Build-Test-Publish / test-install-from-scratch (linux/arm64) (push) Has been cancelled
Build-Test-Publish / build (linux/amd64) (push) Has been cancelled
Build-Test-Publish / build (linux/arm64) (push) Has been cancelled
This commit is contained in:
parent
7dc2ed1e99
commit
551b062b71
85
gp/gp
85
gp/gp
@ -129,28 +129,62 @@ check_git_repo() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to check for uncommitted changes
|
# Function to check for uncommitted changes and unpushed commits
|
||||||
check_for_changes() {
|
check_for_changes() {
|
||||||
local has_staged=$(! git diff --cached --quiet && echo "true" || echo "false")
|
local has_staged=$(! git diff --cached --quiet && echo "true" || echo "false")
|
||||||
local has_modified=$(! git diff --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")
|
local has_untracked=$([ -n "$(git ls-files --others --exclude-standard)" ] && echo "true" || echo "false")
|
||||||
|
|
||||||
|
# Check for unpushed commits
|
||||||
|
local current_branch=$(git branch --show-current)
|
||||||
|
local unpushed_commits=""
|
||||||
|
if git rev-parse --verify "origin/$current_branch" >/dev/null 2>&1; then
|
||||||
|
unpushed_commits=$(git rev-list "origin/$current_branch..HEAD" 2>/dev/null || true)
|
||||||
|
fi
|
||||||
|
|
||||||
# If add-all is enabled, check if we have any changes at all
|
# If add-all is enabled, check if we have any changes at all
|
||||||
if [ "$ADD_ALL" = true ]; then
|
if [ "$ADD_ALL" = true ]; then
|
||||||
if [ "$has_staged" = false ] && [ "$has_modified" = false ] && [ "$has_untracked" = false ]; then
|
if [ "$has_staged" = false ] && [ "$has_modified" = false ] && [ "$has_untracked" = false ]; then
|
||||||
print_info "No changes to commit (working tree clean)"
|
# No working tree changes, but check for unpushed commits
|
||||||
exit 0
|
if [ -n "$unpushed_commits" ]; then
|
||||||
|
local commit_count=$(echo "$unpushed_commits" | wc -l)
|
||||||
|
print_info "No working tree changes, but found $commit_count unpushed commit(s)"
|
||||||
|
print_info "Latest unpushed commit: $(git log --oneline -1)"
|
||||||
|
|
||||||
|
# Set a flag to indicate we should only push, not commit
|
||||||
|
PUSH_ONLY=true
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
print_info "No changes to commit (working tree clean)"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# If add-all is disabled, only check staged changes
|
# If add-all is disabled, only check staged changes
|
||||||
if [ "$has_staged" = false ]; then
|
if [ "$has_staged" = false ]; then
|
||||||
if [ "$has_modified" = true ] || [ "$has_untracked" = true ]; then
|
# No staged changes, but check for unpushed commits
|
||||||
print_warning "No staged changes found"
|
if [ -n "$unpushed_commits" ]; then
|
||||||
print_info "Use 'gp -a' to add all files, or stage changes first with 'git add'"
|
local commit_count=$(echo "$unpushed_commits" | wc -l)
|
||||||
|
print_info "No staged changes, but found $commit_count unpushed commit(s)"
|
||||||
|
print_info "Latest unpushed commit: $(git log --oneline -1)"
|
||||||
|
|
||||||
|
if [ "$has_modified" = true ] || [ "$has_untracked" = true ]; then
|
||||||
|
print_warning "You have unstaged changes that won't be included"
|
||||||
|
print_info "Use 'gp -a' to include all changes, or stage them first with 'git add'"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set a flag to indicate we should only push, not commit
|
||||||
|
PUSH_ONLY=true
|
||||||
|
return 0
|
||||||
else
|
else
|
||||||
print_info "No changes to commit (working tree clean)"
|
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
|
||||||
exit 0
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -221,6 +255,7 @@ FORCE=false
|
|||||||
ADD_ALL=false
|
ADD_ALL=false
|
||||||
CUSTOM_MESSAGE=""
|
CUSTOM_MESSAGE=""
|
||||||
TARGET_BRANCH=""
|
TARGET_BRANCH=""
|
||||||
|
PUSH_ONLY=false
|
||||||
|
|
||||||
# Handle special commands first
|
# Handle special commands first
|
||||||
case "${1:-}" in
|
case "${1:-}" in
|
||||||
@ -283,6 +318,40 @@ main() {
|
|||||||
# Check for changes
|
# Check for changes
|
||||||
check_for_changes
|
check_for_changes
|
||||||
|
|
||||||
|
# Handle push-only case (unpushed commits but no working tree changes)
|
||||||
|
if [ "$PUSH_ONLY" = true ]; then
|
||||||
|
echo
|
||||||
|
|
||||||
|
# Dry run mode for push-only
|
||||||
|
if [ "$DRY_RUN" = true ]; then
|
||||||
|
print_warning "DRY RUN MODE - No changes will be made"
|
||||||
|
print_info "Would push existing commits to: origin/$TARGET_BRANCH"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Safety confirmation for push-only (unless forced)
|
||||||
|
if [ "$FORCE" = false ]; then
|
||||||
|
echo
|
||||||
|
read -p "Push existing commits to origin/$TARGET_BRANCH? [y/N] " -n 1 -r
|
||||||
|
echo
|
||||||
|
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||||
|
print_info "Aborted by user"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Execute push only
|
||||||
|
print_info "Pushing existing commits to $TARGET_BRANCH..."
|
||||||
|
if git push origin "$TARGET_BRANCH"; then
|
||||||
|
print_success "Successfully pushed existing commits to origin/$TARGET_BRANCH"
|
||||||
|
else
|
||||||
|
print_error "Failed to push to origin/$TARGET_BRANCH"
|
||||||
|
print_info "You may need to pull first: git pull origin $TARGET_BRANCH"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
# Show current status
|
# Show current status
|
||||||
show_status
|
show_status
|
||||||
echo
|
echo
|
||||||
|
Loading…
x
Reference in New Issue
Block a user