Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support GitHub dependencies with spaces #2127

Merged
merged 6 commits into from
Jan 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions src/Paket.Core/LockFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,16 @@ module LockFileSerializer =
yield sprintf " remote: " + url

for file in files |> Seq.sortBy (fun f -> f.Owner.ToLower(),f.Project.ToLower(),f.Name.ToLower()) do

let path = file.Name.TrimStart '/'
match String.IsNullOrEmpty(file.Commit) with
| false ->

let path =
file.Name.TrimStart '/'
|> fun s ->
if System.Text.RegularExpressions.Regex.IsMatch (s, "\s") then
String.Concat ("\"", s, "\"")
else
s
match String.IsNullOrEmpty(file.Commit) with
| false ->
match file.AuthKey with
| Some authKey ->
yield sprintf " %s (%s) %s" path file.Commit authKey
Expand Down Expand Up @@ -415,8 +421,22 @@ module LockFileParser =
| GitHubLink | GistLink ->
match currentGroup.RemoteUrl |> Option.map(fun s -> s.Split '/') with
| Some [| owner; project |] ->
let pieces =
if details.Contains "\"" then
let pathInfo =
match details.IndexOf ('"', 1) with
| idx when idx >= 0 -> Some (details.Substring (1, idx - 1), idx)
| _ -> None
match pathInfo with
| Some (path, pathEndIdx) ->
let commitAndAuthKey = details.Substring(pathEndIdx + 2).Split(' ')
Array.append [| path |] commitAndAuthKey
| None -> Array.empty
else
details.Split ' '

let path, commit, authKey =
match details.Split ' ' with
match pieces with
| [| filePath; commit; authKey |] -> filePath, commit |> removeBrackets, (Some authKey)
| [| filePath; commit |] -> filePath, commit |> removeBrackets, None
| _ -> failwith "invalid file source details."
Expand Down
2 changes: 2 additions & 0 deletions tests/Paket.Tests/Lockfile/GeneratorSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ let ``should generate lock file with disabled content for packages``() =

let expectedWithGitHub = """GITHUB
remote: owner/project1
"folder/file 2.fs" (commit1)
folder/file.fs (master)
folder/file1.fs (commit1)
remote: owner/project2
Expand All @@ -165,6 +166,7 @@ let expectedWithGitHub = """GITHUB
let ``should generate lock file for source files``() =
let config = """github "owner:project1:master" "folder/file.fs"
github "owner/project1:commit1" "folder/file1.fs"
github "owner/project1:commit1" "folder/file 2.fs"
github "owner:project2:commit2" "folder/file.fs"
github "owner:project2:commit3" "folder/file3.fs" githubAuth """

Expand Down
33 changes: 33 additions & 0 deletions tests/Paket.Tests/Lockfile/ParserSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -880,3 +880,36 @@ let ``should parse local git lock file with build and no specs``() =
lockFile.Head.SourceFiles.Head.Commit |> shouldEqual "2942d23fcb13a2574b635194203aed7610b21903"
lockFile.Head.SourceFiles.Head.Project |> shouldEqual "nupkgtest"
lockFile.Head.SourceFiles.Head.Command |> shouldEqual (Some "build.cmd Test")

let lockFileWithFilesContainingSpaces = """
GITHUB
remote: owner/repo
specs:
"file 1.fs" (7623fc13439f0e60bd05c1ed3b5f6dcb937fe468)
"file 2.fs" (7623fc13439f0e60bd05c1ed3b5f6dcb937fe468) secret"""

[<Test>]
let ``should parse lock file with spaces in file names``() =
let lockFile = LockFileParser.Parse (toLines lockFileWithFilesContainingSpaces)
let sourceFiles = List.rev lockFile.Head.SourceFiles
sourceFiles|> shouldEqual
[ { Owner = "owner"
Project = "repo"
Name = "file 1.fs"
Origin = ModuleResolver.Origin.GitHubLink
Dependencies = Set.empty
Commit = "7623fc13439f0e60bd05c1ed3b5f6dcb937fe468"
Command = None
OperatingSystemRestriction = None
PackagePath = None
AuthKey = None }
{ Owner = "owner"
Project = "repo"
Name = "file 2.fs"
Origin = ModuleResolver.Origin.GitHubLink
Dependencies = Set.empty
Commit = "7623fc13439f0e60bd05c1ed3b5f6dcb937fe468"
Command = None
OperatingSystemRestriction = None
PackagePath = None
AuthKey = Some "secret" } ]