Skip to content

Commit 752f88e

Browse files
authored
publish: Ensure pulls happen to the correct branch (#920)
If a user has set the default branch to anything other than "master", 'nimble publish' fails. This commit fixes that by ensuring that the git pull followed by git init happens to the default branch used by upstream https://github.com/nim-lang/packages.
1 parent 6d74bde commit 752f88e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/nimblepkg/publish.nim

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const
2020
ApiKeyFile = "github_api_token"
2121
ApiTokenEnvironmentVariable = "NIMBLE_GITHUB_API_TOKEN"
2222
ReposUrl = "https://api.github.com/repos/"
23+
defaultBranch = "master" # Default branch on https://github.com/nim-lang/packages
2324

2425
proc userAborted() =
2526
raise newException(NimbleError, "User aborted the process.")
@@ -101,7 +102,7 @@ proc createPullRequest(a: Auth, packageName, branch: string): string =
101102
display("Info", "Creating PR", priority = HighPriority)
102103
var body = a.http.postContent(ReposUrl & "nim-lang/packages/pulls",
103104
body="""{"title": "Add package $1", "head": "$2:$3",
104-
"base": "master"}""" % [packageName, a.user, branch])
105+
"base": "$4"}""" % [packageName, a.user, branch, defaultBranch])
105106
var pr = parseJson(body)
106107
return pr{"html_url"}.getStr()
107108

@@ -176,11 +177,14 @@ proc publish*(p: PackageInfo, o: Options) =
176177
# https://github.com/blog/1270-easier-builds-and-deployments-using-git-over-https-and-oauth
177178
display("Copying", "packages fork into: " & pkgsDir, priority = HighPriority)
178179
doCmd("git init")
180+
# The repo will have 0 branches created at this point. So the
181+
# below command will always work.
182+
doCmd("git checkout -b " & defaultBranch)
179183
doCmd("git pull https://github.com/" & auth.user & "/packages")
180184
# Make sure to update the fork
181185
display("Updating", "the fork", priority = HighPriority)
182-
doCmd("git pull https://github.com/nim-lang/packages.git master")
183-
doCmd("git push https://" & auth.token & "@github.com/" & auth.user & "/packages master")
186+
doCmd("git pull https://github.com/nim-lang/packages.git " & defaultBranch)
187+
doCmd("git push https://" & auth.token & "@github.com/" & auth.user & "/packages " & defaultBranch)
184188

185189
if not dirExists(pkgsDir):
186190
raise newException(NimbleError,

0 commit comments

Comments
 (0)