Skip to content

Commit b8f91c0

Browse files
committed
Update bump_ag_pr.sh
1 parent 1f0d577 commit b8f91c0

File tree

1 file changed

+35
-11
lines changed

1 file changed

+35
-11
lines changed

Scripts/bump_ag_pr.sh

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ Usage: $SCRIPT_NAME [branch] [--force] [--help]
1818
Automated script to update DarwinPrivateFrameworks with AttributeGraph changes.
1919
2020
Arguments:
21-
branch Target branch to generate from (default: main)
21+
branch Target branch to generate from (default: current branch)
2222
2323
Options:
2424
--force Force push the branch when creating PR
2525
--help Show this help message
2626
2727
Examples:
28-
$SCRIPT_NAME # Update from main branch
28+
$SCRIPT_NAME # Update from current branch
2929
$SCRIPT_NAME develop # Update from develop branch
3030
$SCRIPT_NAME main --force # Update from main with force push
3131
$SCRIPT_NAME --help # Show this help
3232
3333
Description:
3434
This script automates the process of updating DarwinPrivateFrameworks
3535
with the latest AttributeGraph changes by:
36-
1. Setting up a git worktree for the target branch
36+
1. Setting up a git worktree for the target branch (if not current branch)
3737
2. Cloning DarwinPrivateFrameworks repository
3838
3. Generating AG template from OpenAttributeGraph
3939
4. Updating headers and Swift interface templates
@@ -42,7 +42,7 @@ EOF
4242
}
4343

4444
# Parse command line arguments
45-
TARGET_BRANCH="main"
45+
TARGET_BRANCH=""
4646
FORCE_PUSH=""
4747

4848
# Parse arguments
@@ -64,10 +64,30 @@ while [[ $# -gt 0 ]]; do
6464
done
6565

6666
SCRIPT_ROOT="$(dirname $(dirname $(filepath $0)))"
67+
68+
# Get current branch if no target branch specified
69+
if [[ -z "$TARGET_BRANCH" ]]; then
70+
cd "$SCRIPT_ROOT"
71+
TARGET_BRANCH="$(git branch --show-current)"
72+
if [[ -z "$TARGET_BRANCH" ]]; then
73+
echo "Error: Could not determine current branch and no branch specified"
74+
exit 1
75+
fi
76+
fi
77+
6778
OAG_REPO_DIR="$SCRIPT_ROOT/.oag_repo"
6879
OPENATTRIBUTEGRAPH_ROOT="$OAG_REPO_DIR"
6980
AG_REPO_DIR="$SCRIPT_ROOT/.ag_repo"
7081

82+
# Check if we're already on the target branch
83+
cd "$SCRIPT_ROOT"
84+
CURRENT_BRANCH="$(git branch --show-current)"
85+
USE_WORKTREE=true
86+
if [[ "$CURRENT_BRANCH" == "$TARGET_BRANCH" ]]; then
87+
USE_WORKTREE=false
88+
OPENATTRIBUTEGRAPH_ROOT="$SCRIPT_ROOT"
89+
fi
90+
7191
echo "Starting DarwinPrivateFrameworks bump PR workflow..."
7292
echo "Target branch: $TARGET_BRANCH"
7393
if [[ -n "$FORCE_PUSH" ]]; then
@@ -80,7 +100,7 @@ cleanup() {
80100
echo "Cleaning up temporary repository..."
81101
rm -rf "$AG_REPO_DIR"
82102
fi
83-
if [[ -d "$OAG_REPO_DIR" ]]; then
103+
if [[ "$USE_WORKTREE" == true ]] && [[ -d "$OAG_REPO_DIR" ]]; then
84104
echo "Cleaning up git worktree..."
85105
cd "$SCRIPT_ROOT"
86106
git worktree remove --force "$OAG_REPO_DIR" 2>/dev/null || true
@@ -92,13 +112,17 @@ trap cleanup EXIT
92112

93113
cd "$SCRIPT_ROOT"
94114

95-
# Step 1: Setup git worktree for target branch
96-
echo "Setting up git worktree for branch: $TARGET_BRANCH"
97-
if [[ -d "$OAG_REPO_DIR" ]]; then
98-
git worktree remove --force "$OAG_REPO_DIR" 2>/dev/null || true
99-
fi
115+
# Step 1: Setup git worktree for target branch (if needed)
116+
if [[ "$USE_WORKTREE" == true ]]; then
117+
echo "Setting up git worktree for branch: $TARGET_BRANCH"
118+
if [[ -d "$OAG_REPO_DIR" ]]; then
119+
git worktree remove --force "$OAG_REPO_DIR" 2>/dev/null || true
120+
fi
100121

101-
git worktree add "$OAG_REPO_DIR" "$TARGET_BRANCH"
122+
git worktree add "$OAG_REPO_DIR" "$TARGET_BRANCH"
123+
else
124+
echo "Using current directory (already on target branch)"
125+
fi
102126

103127
# Step 2: Clone DarwinPrivateFrameworks repository
104128
echo "Cloning DarwinPrivateFrameworks repository..."

0 commit comments

Comments
 (0)