Update gp/gp
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 54s
Build-Test-Publish / build (linux/arm64) (push) Successful in 1m21s
Build-Test-Publish / test-install-from-scratch (linux/amd64) (push) Successful in 6s
Build-Test-Publish / test-install-from-scratch (linux/arm64) (push) Successful in 7s
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 54s
Build-Test-Publish / build (linux/arm64) (push) Successful in 1m21s
Build-Test-Publish / test-install-from-scratch (linux/amd64) (push) Successful in 6s
Build-Test-Publish / test-install-from-scratch (linux/arm64) (push) Successful in 7s
This commit is contained in:
115
gp/gp
115
gp/gp
@ -49,27 +49,43 @@ EOF
|
|||||||
|
|
||||||
# Function to generate commit message based on changes
|
# Function to generate commit message based on changes
|
||||||
generate_commit_message() {
|
generate_commit_message() {
|
||||||
local files_changed
|
# First check if we have staged changes
|
||||||
files_changed=$(git diff --cached --name-only)
|
local has_staged_changes=false
|
||||||
local files_count
|
if ! git diff --cached --quiet; then
|
||||||
files_count=$(echo "$files_changed" | wc -l)
|
has_staged_changes=true
|
||||||
|
|
||||||
if [ -z "$files_changed" ]; then
|
|
||||||
files_changed=$(git diff --name-only)
|
|
||||||
files_count=$(echo "$files_changed" | wc -l)
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If add-all is enabled, also include untracked files
|
# Determine which changes to analyze based on staging status and ADD_ALL setting
|
||||||
if [ "$ADD_ALL" = true ] && [ -z "$files_changed" ]; then
|
local status_command=""
|
||||||
files_changed=$(git ls-files --others --exclude-standard)
|
if [ "$has_staged_changes" = true ]; then
|
||||||
files_count=$(echo "$files_changed" | wc -l)
|
status_command="git diff --cached --name-status"
|
||||||
|
else
|
||||||
|
status_command="git diff --name-status"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$files_changed" ]; then
|
# Get all changes (staged or unstaged depending on context)
|
||||||
|
local all_changes
|
||||||
|
all_changes=$($status_command)
|
||||||
|
|
||||||
|
# If no changes from diff, check for untracked files when add-all is enabled
|
||||||
|
if [ -z "$all_changes" ] && [ "$ADD_ALL" = true ]; then
|
||||||
|
local untracked_files
|
||||||
|
untracked_files=$(git ls-files --others --exclude-standard)
|
||||||
|
if [ -n "$untracked_files" ]; then
|
||||||
|
# Convert untracked files to "A" (added) status format
|
||||||
|
all_changes=$(echo "$untracked_files" | sed 's/^/A\t/')
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$all_changes" ]; then
|
||||||
echo "No changes to commit"
|
echo "No changes to commit"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Count total files
|
||||||
|
local files_count
|
||||||
|
files_count=$(echo "$all_changes" | wc -l)
|
||||||
|
|
||||||
# Generate smart commit message based on file types and changes
|
# Generate smart commit message based on file types and changes
|
||||||
local has_source_files=false
|
local has_source_files=false
|
||||||
local has_config_files=false
|
local has_config_files=false
|
||||||
@ -77,7 +93,8 @@ generate_commit_message() {
|
|||||||
local has_tests=false
|
local has_tests=false
|
||||||
local message=""
|
local message=""
|
||||||
|
|
||||||
while IFS= read -r file; do
|
# Extract just the filenames for type detection
|
||||||
|
while IFS=$'\t' read -r status file; do
|
||||||
[ -z "$file" ] && continue
|
[ -z "$file" ] && continue
|
||||||
|
|
||||||
case "$file" in
|
case "$file" in
|
||||||
@ -94,15 +111,18 @@ generate_commit_message() {
|
|||||||
has_tests=true
|
has_tests=true
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done <<< "$files_changed"
|
done <<< "$all_changes"
|
||||||
|
|
||||||
# Create descriptive commit message
|
# Create descriptive commit message
|
||||||
if [ "$files_count" -eq 1 ]; then
|
if [ "$files_count" -eq 1 ]; then
|
||||||
|
local change_line
|
||||||
|
change_line=$(echo "$all_changes" | head -1)
|
||||||
|
local status
|
||||||
local single_file
|
local single_file
|
||||||
single_file=$(echo "$files_changed" | head -1)
|
status=$(echo "$change_line" | cut -f1)
|
||||||
local change_type
|
single_file=$(echo "$change_line" | cut -f2)
|
||||||
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 "${status:0:1}" in
|
||||||
A) message="Add $single_file" ;;
|
A) message="Add $single_file" ;;
|
||||||
M) message="Update $single_file" ;;
|
M) message="Update $single_file" ;;
|
||||||
D) message="Remove $single_file" ;;
|
D) message="Remove $single_file" ;;
|
||||||
@ -110,6 +130,58 @@ generate_commit_message() {
|
|||||||
*) message="Modify $single_file" ;;
|
*) message="Modify $single_file" ;;
|
||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
|
# For multiple files, analyze the types of changes
|
||||||
|
local added_count=0
|
||||||
|
local modified_count=0
|
||||||
|
local deleted_count=0
|
||||||
|
local renamed_count=0
|
||||||
|
|
||||||
|
# Use the all_changes variable we already have
|
||||||
|
|
||||||
|
# Count different types of changes
|
||||||
|
while IFS=$'\t' read -r status file; do
|
||||||
|
[ -z "$status" ] && continue
|
||||||
|
case "${status:0:1}" in
|
||||||
|
A) ((added_count++)) ;;
|
||||||
|
M) ((modified_count++)) ;;
|
||||||
|
D) ((deleted_count++)) ;;
|
||||||
|
R) ((renamed_count++)) ;;
|
||||||
|
esac
|
||||||
|
done <<< "$all_changes"
|
||||||
|
|
||||||
|
# Also count untracked files if add-all is enabled
|
||||||
|
if [ "$ADD_ALL" = true ]; then
|
||||||
|
local untracked_files
|
||||||
|
untracked_files=$(git ls-files --others --exclude-standard)
|
||||||
|
if [ -n "$untracked_files" ]; then
|
||||||
|
local untracked_count
|
||||||
|
untracked_count=$(echo "$untracked_files" | wc -l)
|
||||||
|
((added_count += untracked_count))
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Generate message based on change types
|
||||||
|
local change_parts=()
|
||||||
|
[ $added_count -gt 0 ] && change_parts+=("add $added_count")
|
||||||
|
[ $modified_count -gt 0 ] && change_parts+=("update $modified_count")
|
||||||
|
[ $deleted_count -gt 0 ] && change_parts+=("remove $deleted_count")
|
||||||
|
[ $renamed_count -gt 0 ] && change_parts+=("rename $renamed_count")
|
||||||
|
|
||||||
|
local change_desc=""
|
||||||
|
if [ ${#change_parts[@]} -eq 1 ]; then
|
||||||
|
change_desc="${change_parts[0]}"
|
||||||
|
elif [ ${#change_parts[@]} -eq 2 ]; then
|
||||||
|
change_desc="${change_parts[0]} and ${change_parts[1]}"
|
||||||
|
else
|
||||||
|
# Join all but last with commas, last with "and"
|
||||||
|
local last_idx=$((${#change_parts[@]} - 1))
|
||||||
|
for i in $(seq 0 $((last_idx - 1))); do
|
||||||
|
[ $i -gt 0 ] && change_desc+=", "
|
||||||
|
change_desc+="${change_parts[i]}"
|
||||||
|
done
|
||||||
|
change_desc+=" and ${change_parts[last_idx]}"
|
||||||
|
fi
|
||||||
|
|
||||||
local prefix=""
|
local prefix=""
|
||||||
if $has_tests; then
|
if $has_tests; then
|
||||||
prefix="test: "
|
prefix="test: "
|
||||||
@ -121,7 +193,10 @@ generate_commit_message() {
|
|||||||
prefix="feat: "
|
prefix="feat: "
|
||||||
fi
|
fi
|
||||||
|
|
||||||
message="${prefix}Update $files_count files"
|
# Capitalize first letter of change description
|
||||||
|
change_desc="$(echo "${change_desc:0:1}" | tr '[:lower:]' '[:upper:]')${change_desc:1}"
|
||||||
|
|
||||||
|
message="${prefix}${change_desc} files"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "$message"
|
echo "$message"
|
||||||
|
Reference in New Issue
Block a user