Skip to content

throw error if git version is less than 2 #201

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
merged 6 commits into from
Mar 22, 2016

Conversation

kostiakoval
Copy link
Contributor

Fix https://bugs.swift.org/browse/SR-966.
Require git with version >= 2

@@ -38,6 +39,8 @@ extension Error: CustomStringConvertible {
return "No version tag found in (\(package)) package. Add a version tag with \"git tag\" command. Example: \"git tag 0.1.0\""
case NoManifest(let clonePath, let version):
return "The package at `\(clonePath)' has no Package.swift for the specific version: \(version)"
case ObsoleteGitVersion:
return "Git 2.0 or higer is required. Please update git and retry."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling mistake: higer -> higher

var version = self.version
if version.hasPrefix(prefix) {
let prefixRange = version.startIndex...version.startIndex.advanced(by: prefix.characters.count)
version.removeSubrange(prefixRange)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can just do version = version[version.startIndex.advance(by: prefix.characters.count)..<version.endIndex]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String is not a sequence, so I can't :(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do this, but in that case there are to many expressions in 1 line, I think

version = String(version.characters[version.characters.startIndex.advanced(by: prefix.characters.count)..<version.characters.endIndex])

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that'll be worse 😅

@mxcl
Copy link
Contributor

mxcl commented Mar 18, 2016

Specifically what I wanted here was only to check the git version in the event of another git error being thrown, checking every time is wasteful.

@kostiakoval
Copy link
Contributor Author

Got it 👍. Is there a convenient way to downgrade git?

@mxcl
Copy link
Contributor

mxcl commented Mar 18, 2016

Homebrew can be coaxed into installing old versions.

@kostiakoval
Copy link
Contributor Author

All calls to git system(Git.tool, ...) and popen([Git.tool, ...) could fail. Functions that uses them should be marked with throws.

When the Git error occurs and we catch it. We can:

  • Handle it in place and terminate program, exit(1)
  • Propagate error up, so that Multitool would handle it. handleError(msg: Any, ...) method
    With this solution methods that invokes Git should be marked as throws and that would require refactoring quite a lot of code.

I think I prefer solution nr.1 We should handle error in place and take necessary actions. System can't work without git, so we should terminate it.

Do you agree or have any other solutions proposal ?

@mxcl
Copy link
Contributor

mxcl commented Mar 22, 2016

Yes, seems like the right choice. Unless properties become capable of throwing at some point.

@mxcl
Copy link
Contributor

mxcl commented Mar 22, 2016

@swift-ci Please test

@kostiakoval
Copy link
Contributor Author

Tests are passing. Any more feedback on this one. If no, then I'm going to merge it

kostiakoval added a commit that referenced this pull request Mar 22, 2016
throw error if git version is less than 2
@kostiakoval kostiakoval merged commit 37d4315 into swiftlang:master Mar 22, 2016
@kostiakoval kostiakoval deleted the git-v2-error branch March 22, 2016 16:39
@mxcl
Copy link
Contributor

mxcl commented Mar 22, 2016

Next time please squash commits like "revert necessary changes" away first.

@kostiakoval
Copy link
Contributor Author

I'm sorry. I will do that next time

@mxcl
Copy link
Contributor

mxcl commented Mar 22, 2016

np, every project has its unwritten rules.

aciidgh pushed a commit to aciidgh/swift-package-manager that referenced this pull request Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants