Skip to content

Commit bc63d05

Browse files
🩹 [Patch]: Update fetch-depth to 0 in Update-FontsData workflow and enhance git operations in script
1 parent d07e880 commit bc63d05

2 files changed

Lines changed: 46 additions & 12 deletions

File tree

‎.github/workflows/Update-FontsData.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Checkout repository
1818
uses: actions/checkout@v4
1919
with:
20-
fetch-depth: 1
20+
fetch-depth: 0
2121
persist-credentials: false
2222

2323
- name: Update-FontsData

‎scripts/Update-FontsData.ps1‎

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,36 @@
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
6186
if (-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

Comments
 (0)