JohnSundell / JohnSundell/ShellOut

ShellOut "swift package update" not working in some scenarios

Open
#36 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
888
Forks
87
PR merge metrics
No merged PRs in 30d

Description

I'm working on using Swift in some pre-commit scripts. For some reason when I attempted to run various versions of "swift package update" as a script for git pre-commit I would get a failure.

```swift
// swift script in ./.git/hooks/pre-commit
shellOut(to: "swift package update")
```

produces the following error:

```sh
xcrun --sdk macosx --show-sdk-path
xcrun --sdk macosx --show-sdk-platform-path
xcrun --find clang
sandbox-exec -p '(version 1)
(deny default)
(import "system.sb")
(allow file-read*)
(allow process*)
(allow sysctl*)
(allow file-write*
(regex #"^/private/var/tmp/org\.llvm\.clang.*")
(regex #"^/var/folders/h8/2l1nf2ss5qqfblyby0tnl7sm0000gn/T/org\.llvm\.clang.*")
(regex #"^/private/var/folders/h8/2l1nf2ss5qqfblyby0tnl7sm0000gn/T/org\.llvm\.clang.*")
(regex #"^/private/var/folders/h8/2l1nf2ss5qqfblyby0tnl7sm0000gn/C/org\.llvm\.clang.*")
)
' /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc --driver-mode=swift -L /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/4 -lPackageDescription -suppress-warnings -swift-version 4 -I /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/4 -target x86_64-apple-macosx10.10 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk ~redacted~/b4/cache/SwiftPreCommitHooks/Package.swift -fileno 5
sandbox-exec -p '(version 1)
(deny default)
(import "system.sb")
(allow file-read*)
(allow process*)
(allow sysctl*)
(allow file-write*
(regex #"^/private/var/tmp/org\.llvm\.clang.*")
(regex #"^/var/folders/h8/2l1nf2ss5qqfblyby0tnl7sm0000gn/T/org\.llvm\.clang.*")
(regex #"^/private/var/folders/h8/2l1nf2ss5qqfblyby0tnl7sm0000gn/T/org\.llvm\.clang.*")
(regex #"^/private/var/folders/h8/2l1nf2ss5qqfblyby0tnl7sm0000gn/C/org\.llvm\.clang.*")
)
' /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc --driver-mode=swift -L /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/4 -lPackageDescription -suppress-warnings -swift-version 4 -I /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/4 -target x86_64-apple-macosx10.10 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk /var/folders/h8/2l1nf2ss5qqfblyby0tnl7sm0000gn/T/TemporaryFile.TJUETQ.swift -fileno 6
git -C /Users/cavellebenjamin/Development/b4/cache/SwiftPreCommitHooks/.build/repositories/PathKit.git--1865447967743163058 rev-parse --is-bare-repositorygit -C ~redacted~/b4/cache/SwiftPreCommitHooks/.build/repositories/SwiftCLI.git-1996021284977509885 rev-parse --is-bare-repositorygit -C ~redacted~/b4/cache/SwiftPreCommitHooks/.build/repositories/ShellOut.git--4208804319273938067 rev-parse --is-bare-repository

git -C /Users/cavellebenjamin/Development/b4/cache/SwiftPreCommitHooks/.build/repositories/ShellOut.git--4208804319273938067 remote update -p
git -C /Users/cavellebenjamin/Development/b4/cache/SwiftPreCommitHooks/.build/repositories/SwiftCLI.git-1996021284977509885 remote update -p
Updating https://github.com/JohnSundell/ShellOut.git
Updating https://github.com/jakeheis/SwiftCLI.git
Updating https://github.com/kylef/PathKit.git
git -C ~redacted~/b4/cache/SwiftPreCommitHooks/.build/repositories/PathKit.git--1865447967743163058 remote update -p
error: terminated(128): git -C ~redacted~/b4/cache/SwiftPreCommitHooks/.build/repositories/PathKit.git--1865447967743163058 remote update -p output:
```

Appears to correct itself if I add Environment variables to the script that changes the PATH variable.

```swift
let updated = try bash(
command: .swiftPackageUpdate(),
at: "\(FileManager.default.homeDirectoryForCurrentUser.path)/Development/b4/cache/SwiftPreCommitHooks",
env: ["PATH":"/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"]
"PATH":"/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"]
)
```

thoughts on a pull request? or am I overthinking the situation and should use shellOut as is with additional arguments?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.