One can exclude the ".git" from the URL of a package dependency in a Package.swift
file, but I almost always see the ".git" included in example code. I tend to not include it as it seems to me to be mostly noise. Is there is a good reason to declare my dependencies like this:
.package(
url: "https://github.com/apple/swift-syntax.git",
from: "509.0.0"
),
instead of like this:
.package(
url: "https://github.com/apple/swift-syntax",
from: "509.0.0"
),
?
SwiftPM normalizes these URLs under the hood, as we have to account for http://
and https://
used inconsistently, presence and absence of .git
, capitalization, and even www.github.com
used instead of github.com
. There are also HTTP redirects caused by transferred and renamed repositories. You shouldn't need to spend too much time on this, unless you want to make sure it's consistent across packages that you control.
Older versions of SwiftPM had issues with normalization of URLs of dependencies. If some of your dependencies had a transitive dependency with a URL slightly different from the top-level one you specified, you could stumble upon bugs where such packages would be considered as different. If you still see such bugs in the latest version, please let us know.
2 Likes
I tend to include the ".git" extension, because a quick glance at the code immediately distinguishes the URLs to be git repositories, which otherwise look like web page URLs.
1 Like