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

Added option to have paket restore fail on check failure #1963

Merged
merged 3 commits into from
Oct 22, 2016
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
2 changes: 1 addition & 1 deletion integrationtests/Paket.IntegrationTests/InstallSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ let ``#1815 duplicate fsharp core reference when using netstandard1.6``() =
let lockFilePath = Paket.DependenciesFile.FindLockfile paketDependencies.DependenciesFile

// Restore
paketDependencies.Restore(false, group, [], false, true)
paketDependencies.Restore(false, group, [], false, true, false)
|> ignore
let lockFile = paketDependencies.GetLockFile()
let lockGroup = lockFile.GetGroup groupName
Expand Down
18 changes: 9 additions & 9 deletions src/Paket.Core/PublicAPI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -241,32 +241,32 @@ type Dependencies(dependenciesFileName: string) =
NoInstall = installAfter |> not }))

/// Restores all dependencies.
member this.Restore(ignoreChecks): unit = this.Restore(false,None,[],false,ignoreChecks)
member this.Restore(ignoreChecks): unit = this.Restore(false,None,[],false,ignoreChecks,false)

/// Restores all dependencies.
member this.Restore(): unit = this.Restore(false,None,[],false,false)
member this.Restore(): unit = this.Restore(false,None,[],false,false,false)

/// Restores the given paket.references files.
member this.Restore(group: string option, files: string list, ignoreChecks): unit = this.Restore(false, group, files, false, ignoreChecks)
member this.Restore(group: string option, files: string list, ignoreChecks): unit = this.Restore(false, group, files, false, ignoreChecks,false)

/// Restores the given paket.references files.
member this.Restore(group: string option, files: string list): unit = this.Restore(false, group, files, false, false)
member this.Restore(group: string option, files: string list): unit = this.Restore(false, group, files, false, false,false)

/// Restores the given paket.references files.
member this.Restore(force: bool, group: string option, files: string list, touchAffectedRefs: bool, ignoreChecks) : unit =
member this.Restore(force: bool, group: string option, files: string list, touchAffectedRefs: bool, ignoreChecks, failOnChecks) : unit =
Utils.RunInLockedAccessMode(
this.RootPath,
fun () ->
if touchAffectedRefs then
let packagesToTouch = RestoreProcess.FindPackagesNotExtractedYet(dependenciesFileName)
this.Process (FindReferences.TouchReferencesOfPackages packagesToTouch)
RestoreProcess.Restore(dependenciesFileName,force,Option.map GroupName group,files,ignoreChecks))
RestoreProcess.Restore(dependenciesFileName,force,Option.map GroupName group,files,ignoreChecks, failOnChecks))

/// Restores packages for all available paket.references files
/// (or all packages if onlyReferenced is false)
member this.Restore(force: bool, group: string option, onlyReferenced: bool, touchAffectedRefs: bool, ignoreChecks): unit =
member this.Restore(force: bool, group: string option, onlyReferenced: bool, touchAffectedRefs: bool, ignoreChecks, failOnFailedChecks): unit =
if not onlyReferenced then
this.Restore(force,group,[],touchAffectedRefs,ignoreChecks)
this.Restore(force,group,[],touchAffectedRefs,ignoreChecks,failOnFailedChecks)
else
let referencesFiles =
this.RootPath
Expand All @@ -275,7 +275,7 @@ type Dependencies(dependenciesFileName: string) =
if Array.isEmpty referencesFiles then
traceWarnfn "No paket.references files found for which packages could be installed."
else
this.Restore(force, group, Array.toList referencesFiles, touchAffectedRefs, ignoreChecks)
this.Restore(force, group, Array.toList referencesFiles, touchAffectedRefs, ignoreChecks, failOnFailedChecks)

/// Lists outdated packages.
member this.ShowOutdated(strict: bool,includePrereleases: bool): unit =
Expand Down
15 changes: 6 additions & 9 deletions src/Paket.Core/RestoreProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,12 @@ let internal computePackageHull groupName (lockFile : LockFile) (referencesFileN
|> Seq.map (fun p -> (snd p.Key)))
|> Seq.concat

let Restore(dependenciesFileName,force,group,referencesFileNames,ignoreChecks) =
let Restore(dependenciesFileName,force,group,referencesFileNames,ignoreChecks,failOnChecks) =
let lockFileName = DependenciesFile.FindLockfile dependenciesFileName
let localFileName = DependenciesFile.FindLocalfile dependenciesFileName
let root = lockFileName.Directory.FullName

if not lockFileName.Exists then
failwithf "%s doesn't exist." lockFileName.FullName

let dependenciesFile = DependenciesFile.ReadFromFile(dependenciesFileName)
let lockFile,localFile,hasLocalFile =
let lockFile = LockFile.LoadFrom(lockFileName.FullName)
Expand All @@ -139,13 +137,12 @@ let Restore(dependenciesFileName,force,group,referencesFileNames,ignoreChecks) =
LocalFile.overrideLockFile localFile lockFile,localFile,true

if not hasLocalFile && not ignoreChecks then
try
let hasAnyChanges,_,_,_ = DependencyChangeDetection.GetChanges(dependenciesFile,lockFile,false)
let hasAnyChanges,_,_,_ = DependencyChangeDetection.GetChanges(dependenciesFile,lockFile,false)

let checkResponse = if failOnChecks then failwithf else traceWarnfn
if hasAnyChanges then
checkResponse "paket.dependencies and paket.lock are out of sync in %s.%sPlease run 'paket install' or 'paket update' to recompute the paket.lock file." lockFileName.Directory.FullName Environment.NewLine

if hasAnyChanges then
traceWarnfn "paket.dependencies and paket.lock are out of sync in %s.%sPlease run 'paket install' or 'paket update' to recompute the paket.lock file." lockFileName.Directory.FullName Environment.NewLine
with
| _ -> ()

let groups =
match group with
Expand Down
2 changes: 2 additions & 0 deletions src/Paket/Commands.fs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ type RestoreArgs =
| [<CustomCommandLine("--only-referenced")>] Install_Only_Referenced
| [<CustomCommandLine("--touch-affected-refs")>] Touch_Affected_Refs
| [<CustomCommandLine("--ignore-checks")>] Ignore_Checks
| [<CustomCommandLine("--fail-on-checks")>] Fail_On_Checks
| [<CustomCommandLine("group")>] Group of name:string
| [<Unique>] References_Files of file_name:string list
with
Expand All @@ -167,6 +168,7 @@ with
| Install_Only_Referenced -> "Allows to restore packages that are referenced in paket.references files, instead of all packages in paket.dependencies."
| Touch_Affected_Refs -> "Touches project files referencing packages which are being restored, to help incremental build tools detecting the change."
| Ignore_Checks -> "Skips the test if paket.dependencies and paket.lock are in sync."
| Fail_On_Checks -> "Causes the restore to fail if any of the checks fail."
| References_Files(_) -> "Allows to restore all packages from the given paket.references files. This implies --only-referenced."

type SimplifyArgs =
Expand Down
5 changes: 3 additions & 2 deletions src/Paket/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,9 @@ let restore (results : ParseResults<_>) =
let installOnlyReferenced = results.Contains <@ RestoreArgs.Install_Only_Referenced @>
let touchAffectedRefs = results.Contains <@ RestoreArgs.Touch_Affected_Refs @>
let ignoreChecks = results.Contains <@ RestoreArgs.Ignore_Checks @>
if List.isEmpty files then Dependencies.Locate().Restore(force, group, installOnlyReferenced, touchAffectedRefs, ignoreChecks)
else Dependencies.Locate().Restore(force, group, files, touchAffectedRefs, ignoreChecks)
let failOnChecks = results.Contains <@ RestoreArgs.Fail_On_Checks @>
if List.isEmpty files then Dependencies.Locate().Restore(force, group, installOnlyReferenced, touchAffectedRefs, ignoreChecks, failOnChecks)
else Dependencies.Locate().Restore(force, group, files, touchAffectedRefs, ignoreChecks, failOnChecks)

let simplify (results : ParseResults<_>) =
let interactive = results.Contains <@ SimplifyArgs.Interactive @>
Expand Down