swiftlang / swift-package-manager

The Package Manager for the Swift Programming Language
Apache License 2.0
9.71k stars 1.33k forks source link

`git config --global column.ui {auto,always}` breaks version resolution #7343

Open iainsmith opened 7 months ago

iainsmith commented 7 months ago

Description

SPM, has a few places where it assumes git tags (& possibly other output) are split by newline. From a user's perspective you get a misleading error message:

Dependencies could not be resolved because no versions of '....' match the requirement ... and root depends on '.....'.

Here's an example of the spm code that I think is causing the issue. This could be avoided with either: git -c column.ui=never tag or git tag --no-column.

    /// Returns the tags present in repository.
    public func getTags() throws -> [String] {
        // Get the contents using `ls-tree`.
        try self.cachedTags.memoize {
            try self.lock.withLock {
                let tagList = try callGit(
                    "tag",
                    "-l",
                    failureMessage: "Couldn’t get the list of tags"
                )
                return tagList.split(whereSeparator: { $0.isNewline }).map(String.init)
            }
        }
    }

Expected behavior

global git ui configuration shouldn't break SPM

Actual behavior

Obscure error message, that left me slightly perplexed.

Steps to reproduce

  1. Run git config --global column.ui always
  2. Create a minimal Package.swift with any remote dependency (with multiple versions)

Swift Package Manager version/commit hash

main

Swift & OS version (output of swift --version ; uname -a)

swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5) Target: arm64-apple-macosx14.0

Darwin JM9JHGY76P 23.3.0 Darwin Kernel Version 23.3.0: Wed Dec 20 21:30:44 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T6000 arm64

benjiwolff commented 6 months ago

I am so glad you posted this issue here. I would have never been able to figure out why this bug is happening for me... 😅

OttoFI commented 4 months ago

I have been trying to figure out this error for the past week.

Setting git config --global column.ui {auto,always} seemed to fix it. Thanks!

Update: My column.ui was set to row dense, which resulted in SPM always failing to resolve dependencies. But after changing it to {auto,always} and successfully resolving package versions, I was able to change it back to row dense (or what ever I wanted) and it worked fine, even after removing caches.