Skip to content

Commit

Permalink
publish: Ensure pulls happen to the correct branch
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kaushalmodi committed May 23, 2021
1 parent 6d74bde commit 904f42d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/nimblepkg/publish.nim
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const
ApiKeyFile = "github_api_token"
ApiTokenEnvironmentVariable = "NIMBLE_GITHUB_API_TOKEN"
ReposUrl = "https://api.github.com/repos/"
defaultBranch = "master" # Default branch on https://github.com/nim-lang/packages

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

Expand Down Expand Up @@ -176,11 +177,12 @@ proc publish*(p: PackageInfo, o: Options) =
# https://github.com/blog/1270-easier-builds-and-deployments-using-git-over-https-and-oauth
display("Copying", "packages fork into: " & pkgsDir, priority = HighPriority)
doCmd("git init")
doCmd("git checkout -b " & defaultBranch)
doCmd("git pull https://github.com/" & auth.user & "/packages")
# Make sure to update the fork
display("Updating", "the fork", priority = HighPriority)
doCmd("git pull https://github.com/nim-lang/packages.git master")
doCmd("git push https://" & auth.token & "@github.com/" & auth.user & "/packages master")
doCmd("git pull https://github.com/nim-lang/packages.git " & defaultBranch)
doCmd("git push https://" & auth.token & "@github.com/" & auth.user & "/packages " & defaultBranch)

if not dirExists(pkgsDir):
raise newException(NimbleError,
Expand Down

0 comments on commit 904f42d

Please sign in to comment.