Fixed branch checkout and handling of branch names with dashes. (#379)
* Fixed branch checkout and handling of branch names with dashes. * Added assert
This commit is contained in:
parent
10a38a3c90
commit
e756a14c15
3 changed files with 16 additions and 9 deletions
|
|
@ -178,7 +178,9 @@ proc doDownload*(url: string, downloadDir: string, verRange: VersionRange,
|
|||
# Grab the full repo.
|
||||
doClone(downMethod, url, downloadDir, tip = false)
|
||||
# Then perform a checkout operation to get the specified branch/commit.
|
||||
doCheckout(downMethod, downloadDir, $verRange.spe)
|
||||
# `spe` starts with '#', trim it.
|
||||
doAssert(($verRange.spe)[0] == '#')
|
||||
doCheckout(downMethod, downloadDir, substr($verRange.spe, 1))
|
||||
result = verRange.spe
|
||||
else:
|
||||
case downMethod
|
||||
|
|
|
|||
|
|
@ -72,15 +72,18 @@ proc getNameVersion*(pkgpath: string): tuple[name, version: string] =
|
|||
result.name = ""
|
||||
result.version = ""
|
||||
let tail = pkgpath.splitPath.tail
|
||||
if '-' notin tail:
|
||||
|
||||
const specialSeparator = "-#"
|
||||
var sepIdx = tail.find(specialSeparator)
|
||||
if sepIdx == -1:
|
||||
sepIdx = tail.rfind('-')
|
||||
|
||||
if sepIdx == -1:
|
||||
result.name = tail
|
||||
return
|
||||
|
||||
for i in countdown(tail.len-1, 0):
|
||||
if tail[i] == '-':
|
||||
result.name = tail[0 .. i-1]
|
||||
result.version = tail[i+1 .. tail.len-1]
|
||||
break
|
||||
result.name = tail[0 .. sepIdx - 1]
|
||||
result.version = tail.substr(sepIdx + 1)
|
||||
|
||||
proc optionalField(obj: JsonNode, name: string, default = ""): string =
|
||||
## Queries ``obj`` for the optional ``name`` string.
|
||||
|
|
@ -501,6 +504,8 @@ when isMainModule:
|
|||
("package-a", "0.1")
|
||||
doAssert getNameVersion("/home/user/.nimble/libs/package-#head") ==
|
||||
("package", "#head")
|
||||
doAssert getNameVersion("/home/user/.nimble/libs/package-#branch-with-dashes") ==
|
||||
("package", "#branch-with-dashes")
|
||||
|
||||
doAssert toValidPackageName("foo__bar") == "foo_bar"
|
||||
doAssert toValidPackageName("jhbasdh!£$@%#^_&*_()qwe") == "jhbasdh_qwe"
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ type
|
|||
hint*: string
|
||||
|
||||
proc newVersion*(ver: string): Version =
|
||||
doAssert(ver[0] in {'#', '\0'} + Digits)
|
||||
doAssert(ver[0] in {'#', '\0'} + Digits, "Wrong version: " & ver)
|
||||
return Version(ver)
|
||||
|
||||
proc `$`*(ver: Version): string {.borrow.}
|
||||
|
|
@ -196,7 +196,7 @@ proc parseVersionRange*(s: string): VersionRange =
|
|||
|
||||
else:
|
||||
raise newException(ParseVersionError,
|
||||
"Unexpected char in version range: " & s[i])
|
||||
"Unexpected char in version range '" & s & "': " & s[i])
|
||||
inc(i)
|
||||
|
||||
proc toVersionRange*(ver: Version): VersionRange =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue