Skip to content

[Commands] Don't blow away modified Packages. #373

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

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
3 changes: 3 additions & 0 deletions Sources/Commands/Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public enum Error: ErrorProtocol {
case invalidInstallation(String)
case invalidSwiftExec(String)
case buildYAMLNotFound(String)
case repositoryHasChanges(String)
}

extension Error: CustomStringConvertible {
Expand All @@ -38,6 +39,8 @@ extension Error: CustomStringConvertible {
return "invalid SWIFT_EXEC value: \(value)"
case .buildYAMLNotFound(let value):
return "no build YAML found: \(value)"
case .repositoryHasChanges(let value):
return "repository has changes: \(value)"
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions Sources/Commands/SwiftPackageTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,22 @@ public struct SwiftPackageTool {
try initPackage.writePackageStructure()

case .update:
// Attempt to ensure that none of the repositories are modified.
for item in walk(opts.path.Packages, recursively: false) {
// Only look at repositories.
guard Path.join(item, ".git").exists else { continue }

// If there is a staged or unstaged diff, don't remove the
// tree. This won't detect new untracked files, but it is
// just a safety measure for now.
let diffArgs = ["--no-ext-diff", "--quiet", "--exit-code"]
do {
_ = try Git.runPopen([Git.tool, "-C", item, "diff"] + diffArgs)
_ = try Git.runPopen([Git.tool, "-C", item, "diff", "--cached"] + diffArgs)
} catch {
throw Error.repositoryHasChanges(item)
}
}
try Utility.removeFileTree(opts.path.Packages)
fallthrough

Expand Down