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
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:
parent
95da0d28d4
commit
e65b3a867a
66
gp/gp
66
gp/gp
@ -101,7 +101,7 @@ generate_commit_message() {
|
||||
local single_file
|
||||
single_file=$(echo "$files_changed" | head -1)
|
||||
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
|
||||
A) message="Add $single_file" ;;
|
||||
M) message="Update $single_file" ;;
|
||||
@ -137,19 +137,31 @@ check_git_repo() {
|
||||
|
||||
# Function to check for uncommitted changes and unpushed commits
|
||||
check_for_changes() {
|
||||
local has_staged
|
||||
has_staged=$(! git diff --cached --quiet && echo "true" || echo "false")
|
||||
local has_modified
|
||||
has_modified=$(! git diff --quiet && echo "true" || echo "false")
|
||||
local has_untracked
|
||||
has_untracked=$([ -n "$(git ls-files --others --exclude-standard)" ] && echo "true" || echo "false")
|
||||
local has_staged=false
|
||||
local has_modified=false
|
||||
local has_untracked=false
|
||||
|
||||
# Check for staged changes
|
||||
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
|
||||
local current_branch
|
||||
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)
|
||||
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
|
||||
@ -214,7 +226,7 @@ show_status_and_confirm() {
|
||||
# Show staged changes
|
||||
if ! git diff --cached --quiet; then
|
||||
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
|
||||
fi
|
||||
|
||||
@ -225,7 +237,7 @@ show_status_and_confirm() {
|
||||
else
|
||||
print_info "Modified files (unstaged, will NOT be included):"
|
||||
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
|
||||
fi
|
||||
|
||||
@ -283,15 +295,18 @@ do_commit_and_push() {
|
||||
# Add files if requested
|
||||
if [ "$ADD_ALL" = true ]; then
|
||||
print_info "Adding all files..."
|
||||
git add .
|
||||
git add -A
|
||||
fi
|
||||
|
||||
# Commit
|
||||
print_info "Committing with message: '$commit_msg'"
|
||||
git commit -m "$commit_msg"
|
||||
git commit -m "$commit_msg" --
|
||||
|
||||
# Push
|
||||
print_info "Pushing to $target_branch..."
|
||||
# Check if branch exists on remote to determine if we need -u flag
|
||||
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
|
||||
@ -299,6 +314,16 @@ do_commit_and_push() {
|
||||
print_info "You may need to pull first: git pull origin $target_branch"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
# Branch doesn't exist on remote, use -u to set upstream
|
||||
print_info "Setting upstream branch (first push to origin/$target_branch)"
|
||||
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
|
||||
}
|
||||
|
||||
# Autocomplete function for bash
|
||||
@ -354,6 +379,10 @@ while [[ $# -gt 0 ]]; do
|
||||
shift
|
||||
;;
|
||||
-b|--branch)
|
||||
if [ -z "${2:-}" ]; then
|
||||
print_error "Option -b/--branch requires a branch name"
|
||||
exit 1
|
||||
fi
|
||||
TARGET_BRANCH="$2"
|
||||
shift 2
|
||||
;;
|
||||
@ -406,6 +435,9 @@ main() {
|
||||
|
||||
# Execute push only
|
||||
print_info "Pushing existing commits to $TARGET_BRANCH..."
|
||||
# Check if branch exists on remote to determine if we need -u flag
|
||||
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
|
||||
@ -413,6 +445,16 @@ main() {
|
||||
print_info "You may need to pull first: git pull origin $TARGET_BRANCH"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
# Branch doesn't exist on remote, use -u to set upstream
|
||||
print_info "Setting upstream branch (first push to origin/$TARGET_BRANCH)"
|
||||
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
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user