Fix all shellcheck errors in gp script
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 23s
Build-Test-Publish / build (linux/arm64) (push) Successful in 26s
Build-Test-Publish / test-install-from-scratch (linux/amd64) (push) Successful in 8s
Build-Test-Publish / test-install-from-scratch (linux/arm64) (push) Successful in 8s
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 23s
Build-Test-Publish / build (linux/arm64) (push) Successful in 26s
Build-Test-Publish / test-install-from-scratch (linux/amd64) (push) Successful in 8s
Build-Test-Publish / test-install-from-scratch (linux/arm64) (push) Successful in 8s
This commit is contained in:
parent
511979315d
commit
cadfd6c3e3
47
gp/gp
47
gp/gp
@ -49,8 +49,10 @@ EOF
|
||||
|
||||
# Function to generate commit message based on changes
|
||||
generate_commit_message() {
|
||||
local files_changed=$(git diff --cached --name-only)
|
||||
local files_count=$(echo "$files_changed" | wc -l)
|
||||
local files_changed
|
||||
files_changed=$(git diff --cached --name-only)
|
||||
local files_count
|
||||
files_count=$(echo "$files_changed" | wc -l)
|
||||
|
||||
if [ -z "$files_changed" ]; then
|
||||
files_changed=$(git diff --name-only)
|
||||
@ -88,7 +90,7 @@ generate_commit_message() {
|
||||
*.md|*.txt|*.rst|docs/*|README*)
|
||||
has_docs=true
|
||||
;;
|
||||
*test*|*spec*|test/*|tests/*)
|
||||
test/*|tests/*|*test*|*spec*)
|
||||
has_tests=true
|
||||
;;
|
||||
esac
|
||||
@ -96,8 +98,10 @@ generate_commit_message() {
|
||||
|
||||
# Create descriptive commit message
|
||||
if [ "$files_count" -eq 1 ]; then
|
||||
local single_file=$(echo "$files_changed" | head -1)
|
||||
local change_type=$(git diff --cached --name-status "$single_file" 2>/dev/null || git diff --name-status "$single_file")
|
||||
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")
|
||||
case "${change_type:0:1}" in
|
||||
A) message="Add $single_file" ;;
|
||||
M) message="Update $single_file" ;;
|
||||
@ -133,12 +137,16 @@ check_git_repo() {
|
||||
|
||||
# Function to check for uncommitted changes and unpushed commits
|
||||
check_for_changes() {
|
||||
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")
|
||||
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")
|
||||
|
||||
# Check for unpushed commits
|
||||
local current_branch=$(git branch --show-current)
|
||||
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)
|
||||
@ -149,7 +157,8 @@ check_for_changes() {
|
||||
if [ "$has_staged" = false ] && [ "$has_modified" = false ] && [ "$has_untracked" = false ]; then
|
||||
# No working tree changes, but check for unpushed commits
|
||||
if [ -n "$unpushed_commits" ]; then
|
||||
local commit_count=$(echo "$unpushed_commits" | wc -l)
|
||||
local commit_count
|
||||
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)"
|
||||
|
||||
@ -166,7 +175,8 @@ check_for_changes() {
|
||||
if [ "$has_staged" = false ]; then
|
||||
# No staged changes, but check for unpushed commits
|
||||
if [ -n "$unpushed_commits" ]; then
|
||||
local commit_count=$(echo "$unpushed_commits" | wc -l)
|
||||
local commit_count
|
||||
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)"
|
||||
|
||||
@ -204,7 +214,7 @@ show_status_and_confirm() {
|
||||
# Show staged changes
|
||||
if ! git diff --cached --quiet; then
|
||||
print_info "Staged changes:"
|
||||
git diff --cached --name-only | sed 's/^/ /'
|
||||
git diff --cached --name-only | while IFS= read -r line; do echo " $line"; done
|
||||
has_staged_changes=true
|
||||
fi
|
||||
|
||||
@ -215,16 +225,20 @@ show_status_and_confirm() {
|
||||
else
|
||||
print_info "Modified files (unstaged, will NOT be included):"
|
||||
fi
|
||||
git diff --name-only | sed 's/^/ /'
|
||||
git diff --name-only | while IFS= read -r line; do echo " $line"; done
|
||||
has_unstaged_changes=true
|
||||
fi
|
||||
|
||||
# Show untracked files
|
||||
if [ "$ADD_ALL" = true ]; then
|
||||
local untracked=$(git ls-files --others --exclude-standard)
|
||||
local untracked
|
||||
untracked=$(git ls-files --others --exclude-standard)
|
||||
if [ -n "$untracked" ]; then
|
||||
print_info "Untracked files (will be added):"
|
||||
echo "$untracked" | sed 's/^/ /'
|
||||
# Use while loop to add indent without sed
|
||||
while IFS= read -r line; do
|
||||
echo " $line"
|
||||
done <<< "$untracked"
|
||||
has_untracked_files=true
|
||||
fi
|
||||
fi
|
||||
@ -411,8 +425,7 @@ main() {
|
||||
print_info "Using custom commit message: '$commit_message'"
|
||||
else
|
||||
print_info "Generating commit message..."
|
||||
commit_message=$(generate_commit_message)
|
||||
if [ $? -ne 0 ]; then
|
||||
if ! commit_message=$(generate_commit_message); then
|
||||
print_error "Failed to generate commit message"
|
||||
exit 1
|
||||
fi
|
||||
|
Loading…
x
Reference in New Issue
Block a user