Modify gp/gp
Some checks failed
Build-Test-Publish / build (linux/arm64) (push) Failing after 9s
Build-Test-Publish / build (linux/amd64) (push) Successful in 26s
Build-Test-Publish / test-install-from-scratch (linux/amd64) (push) Has been skipped
Build-Test-Publish / test-install-from-scratch (linux/arm64) (push) Has been skipped

This commit is contained in:
Your Name 2025-06-25 18:09:27 +12:00
parent 95da0d28d4
commit e65b3a867a

86
gp/gp
View File

@ -101,7 +101,7 @@ generate_commit_message() {
local single_file local single_file
single_file=$(echo "$files_changed" | head -1) single_file=$(echo "$files_changed" | head -1)
local change_type local change_type
change_type=$(git diff --cached --name-status "$single_file" 2>/dev/null || git diff --name-status "$single_file") change_type=$(git diff --cached --name-status -- "$single_file" 2>/dev/null || git diff --name-status -- "$single_file")
case "${change_type:0:1}" in case "${change_type:0:1}" in
A) message="Add $single_file" ;; A) message="Add $single_file" ;;
M) message="Update $single_file" ;; M) message="Update $single_file" ;;
@ -137,19 +137,31 @@ check_git_repo() {
# Function to check for uncommitted changes and unpushed commits # Function to check for uncommitted changes and unpushed commits
check_for_changes() { check_for_changes() {
local has_staged local has_staged=false
has_staged=$(! git diff --cached --quiet && echo "true" || echo "false") local has_modified=false
local has_modified local has_untracked=false
has_modified=$(! git diff --quiet && echo "true" || echo "false")
local has_untracked # Check for staged changes
has_untracked=$([ -n "$(git ls-files --others --exclude-standard)" ] && echo "true" || echo "false") if ! git diff --cached --quiet; then
has_staged=true
fi
# Check for modified files
if ! git diff --quiet; then
has_modified=true
fi
# Check for untracked files
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
has_untracked=true
fi
# Check for unpushed commits # Check for unpushed commits
local current_branch local current_branch
current_branch=$(git branch --show-current) current_branch=$(git branch --show-current)
local unpushed_commits="" local unpushed_commits=""
if git rev-parse --verify "origin/$current_branch" >/dev/null 2>&1; then 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) unpushed_commits=$(git rev-list "origin/$current_branch..HEAD" -- 2>/dev/null || true)
fi 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
@ -214,7 +226,7 @@ show_status_and_confirm() {
# Show staged changes # Show staged changes
if ! git diff --cached --quiet; then if ! git diff --cached --quiet; then
print_info "Staged changes:" print_info "Staged changes:"
git diff --cached --name-only | while IFS= read -r line; do echo " $line"; done git diff --cached --name-only -- | while IFS= read -r line; do echo " $line"; done
has_staged_changes=true has_staged_changes=true
fi fi
@ -225,7 +237,7 @@ show_status_and_confirm() {
else else
print_info "Modified files (unstaged, will NOT be included):" print_info "Modified files (unstaged, will NOT be included):"
fi fi
git diff --name-only | while IFS= read -r line; do echo " $line"; done git diff --name-only -- | while IFS= read -r line; do echo " $line"; done
has_unstaged_changes=true has_unstaged_changes=true
fi fi
@ -283,21 +295,34 @@ do_commit_and_push() {
# Add files if requested # Add files if requested
if [ "$ADD_ALL" = true ]; then if [ "$ADD_ALL" = true ]; then
print_info "Adding all files..." print_info "Adding all files..."
git add . git add -A
fi fi
# Commit # Commit
print_info "Committing with message: '$commit_msg'" print_info "Committing with message: '$commit_msg'"
git commit -m "$commit_msg" git commit -m "$commit_msg" --
# Push # Push
print_info "Pushing to $target_branch..." print_info "Pushing to $target_branch..."
if git push origin "$target_branch"; then # Check if branch exists on remote to determine if we need -u flag
print_success "Successfully pushed to origin/$target_branch" if git ls-remote --exit-code --heads origin "$target_branch" >/dev/null 2>&1; then
# Branch exists on remote, normal push
if git push origin "$target_branch"; then
print_success "Successfully pushed 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
else else
print_error "Failed to push to origin/$target_branch" # Branch doesn't exist on remote, use -u to set upstream
print_info "You may need to pull first: git pull origin $target_branch" print_info "Setting upstream branch (first push to origin/$target_branch)"
exit 1 if git push -u origin "$target_branch"; then
print_success "Successfully pushed and set upstream to origin/$target_branch"
else
print_error "Failed to push to origin/$target_branch"
exit 1
fi
fi fi
} }
@ -354,6 +379,10 @@ while [[ $# -gt 0 ]]; do
shift shift
;; ;;
-b|--branch) -b|--branch)
if [ -z "${2:-}" ]; then
print_error "Option -b/--branch requires a branch name"
exit 1
fi
TARGET_BRANCH="$2" TARGET_BRANCH="$2"
shift 2 shift 2
;; ;;
@ -406,12 +435,25 @@ main() {
# Execute push only # Execute push only
print_info "Pushing existing commits to $TARGET_BRANCH..." print_info "Pushing existing commits to $TARGET_BRANCH..."
if git push origin "$TARGET_BRANCH"; then # Check if branch exists on remote to determine if we need -u flag
print_success "Successfully pushed existing commits to origin/$TARGET_BRANCH" if git ls-remote --exit-code --heads origin "$TARGET_BRANCH" >/dev/null 2>&1; then
# Branch exists on remote, normal push
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
else else
print_error "Failed to push to origin/$TARGET_BRANCH" # Branch doesn't exist on remote, use -u to set upstream
print_info "You may need to pull first: git pull origin $TARGET_BRANCH" print_info "Setting upstream branch (first push to origin/$TARGET_BRANCH)"
exit 1 if git push -u origin "$TARGET_BRANCH"; then
print_success "Successfully pushed existing commits and set upstream to origin/$TARGET_BRANCH"
else
print_error "Failed to push to origin/$TARGET_BRANCH"
exit 1
fi
fi fi
exit 0 exit 0
fi fi