3131 }
3232}
3333
34- Invoke-NativeCommand git checkout main
35- Invoke-NativeCommand git pull
34+ # Get the current branch and default branch information
35+ $currentBranch = (Invoke-NativeCommand git rev- parse -- abbrev- ref HEAD).Trim()
36+ $defaultBranch = (Invoke-NativeCommand git remote show origin | Select-String ' HEAD branch:' | ForEach-Object { $_.ToString ().Split(' :' )[1 ].Trim() })
37+
38+ Write-Output " Current branch: $currentBranch "
39+ Write-Output " Default branch: $defaultBranch "
40+
41+ # Fetch latest changes from remote
42+ Invoke-NativeCommand git fetch origin
43+
44+ # Get the head branch (latest default branch)
45+ Invoke-NativeCommand git checkout $defaultBranch
46+ Invoke-NativeCommand git pull origin $defaultBranch
47+
3648$timeStamp = Get-Date - Format ' yyyyMMdd-HHmmss'
37- $branchName = " auto-font-update-$timeStamp "
38- Invoke-NativeCommand git checkout - b $branchName
49+
50+ # Determine target branch based on current context
51+ if ($currentBranch -eq $defaultBranch ) {
52+ # Running on main/default branch - create new branch
53+ $targetBranch = " auto-font-update-$timeStamp "
54+ Write-Output " Running on default branch. Creating new branch: $targetBranch "
55+ Invoke-NativeCommand git checkout - b $targetBranch
56+ } else {
57+ # Running on another branch (e.g., workflow_dispatch) - use current branch
58+ $targetBranch = $currentBranch
59+ Write-Output " Running on feature branch. Using existing branch: $targetBranch "
60+ Invoke-NativeCommand git checkout $targetBranch
61+ # Merge latest changes from default branch
62+ Invoke-NativeCommand git merge origin/ $defaultBranch
63+ }
3964
4065$release = Get-GitHubRelease - Owner ryanoasis - Repository nerd- fonts
4166$fonts = @ ()
@@ -61,15 +86,24 @@ $changes = Invoke-NativeCommand git status --porcelain
6186if (-not [string ]::IsNullOrWhiteSpace($changes )) {
6287 Invoke-NativeCommand git add .
6388 Invoke-NativeCommand git commit - m " Update-FontsData via script on $timeStamp "
64- Invoke-NativeCommand git push -- set-upstream origin $branchName
6589
66- Invoke-NativeCommand gh pr create `
67- -- base main `
68- -- head $branchName `
69- -- title " Auto-Update: NerdFonts Data ($timeStamp )" `
70- -- body ' This PR updates FontsData.json with the latest NerdFonts metadata.'
90+ # Push behavior depends on branch type
91+ if ($targetBranch -eq $currentBranch -and $currentBranch -ne $defaultBranch ) {
92+ # Push to existing branch
93+ Invoke-NativeCommand git push origin $targetBranch
94+ Write-Output " Changes committed and pushed to existing branch: $targetBranch "
95+ } else {
96+ # Push new branch and create PR
97+ Invoke-NativeCommand git push -- set-upstream origin $targetBranch
7198
72- Write-Output ' Changes detected and PR opened.'
99+ Invoke-NativeCommand gh pr create `
100+ -- base $defaultBranch `
101+ -- head $targetBranch `
102+ -- title " Auto-Update: NerdFonts Data ($timeStamp )" `
103+ -- body ' This PR updates FontsData.json with the latest NerdFonts metadata.'
104+
105+ Write-Output " Changes detected and PR opened for branch: $targetBranch "
106+ }
73107} else {
74108 Write-Output ' No changes to commit.'
75109}
0 commit comments