@@ -18,22 +18,22 @@ Usage: $SCRIPT_NAME [branch] [--force] [--help]
1818Automated script to update DarwinPrivateFrameworks with AttributeGraph changes.
1919
2020Arguments:
21- branch Target branch to generate from (default: main )
21+ branch Target branch to generate from (default: current branch )
2222
2323Options:
2424 --force Force push the branch when creating PR
2525 --help Show this help message
2626
2727Examples:
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
3333Description:
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
4242}
4343
4444# Parse command line arguments
45- TARGET_BRANCH=" main "
45+ TARGET_BRANCH=" "
4646FORCE_PUSH=" "
4747
4848# Parse arguments
@@ -64,10 +64,30 @@ while [[ $# -gt 0 ]]; do
6464done
6565
6666SCRIPT_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+
6778OAG_REPO_DIR=" $SCRIPT_ROOT /.oag_repo"
6879OPENATTRIBUTEGRAPH_ROOT=" $OAG_REPO_DIR "
6980AG_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+
7191echo " Starting DarwinPrivateFrameworks bump PR workflow..."
7292echo " Target branch: $TARGET_BRANCH "
7393if [[ -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
93113cd " $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
104128echo " Cloning DarwinPrivateFrameworks repository..."
0 commit comments