From 165fa5f3cec2b760f8dd84d02e55abdbb8295bfa Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Wed, 11 Dec 2024 16:56:19 +0000 Subject: [PATCH] Update roles/home/scripts/commits.sh --- roles/home/scripts/commits.sh | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/roles/home/scripts/commits.sh b/roles/home/scripts/commits.sh index 46e7fdb..94e7c18 100644 --- a/roles/home/scripts/commits.sh +++ b/roles/home/scripts/commits.sh @@ -3,13 +3,13 @@ create_pr_from_files() { local temp_branch="pr-${TIMESTAMP}-temp" local pr_branch="pr-${TIMESTAMP}" local base_branch="development" - local current_branch=$(git rev-parse --abbrev-ref HEAD) + local working_branch=$(git rev-parse --abbrev-ref HEAD) local files=() local expanded_files=() local temp_branch_created=false cleanup() { - git checkout "${current_branch}" + git checkout "${working_branch}" if [ "$temp_branch_created" = true ]; then git checkout "${temp_branch}" -- "${expanded_files[@]}" @@ -59,9 +59,6 @@ create_pr_from_files() { fi done - echo "Original files: ${files[@]}" - echo "Expanded files: ${expanded_files[@]}" - # Check if there are any uncommitted changes if [ -n "$(git status -s)" ]; then # Only create temp branch and backup if there are uncommitted changes @@ -77,7 +74,8 @@ create_pr_from_files() { temp_branch_created=true fi - # Switch to base branch and create temporary branch + # Get current branch and switch to base branch if needed + current_branch=$(git rev-parse --abbrev-ref HEAD) if [ "$current_branch" != "$base_branch" ]; then git checkout "$base_branch" || ( handle_error "Failed to checkout base branch" @@ -101,19 +99,14 @@ create_pr_from_files() { return $? ) else - git checkout "$current_branch" -- "${expanded_files[@]}" || ( + git checkout "$working_branch" -- "${expanded_files[@]}" || ( handle_error "Failed to restore specified files" return $? ) fi - git add "${expanded_files[@]}" || ( - handle_error "Failed to stage specified files" - return $? - ) - # Verify files were staged - if [ -z "$(git diff --cached --name-only)" ]; then + if [ -z "$(git diff --staged)" ]; then handle_error "No files were staged. Aborting PR creation." return $? fi @@ -145,6 +138,7 @@ create_pr_from_files() { } + create_pr_from_commit() { local commit_hash="$1" local base_branch="${2:-development}"