Skip to content

--new-from-rev gets confused by merge commits #4097

Closed
@mering

Description

@mering

Welcome

Description of the problem

Adding a reproduction example to demonstrate breakage of #4047.

Version of golangci-lint

$ ./golangci-lint --version
# 1.54.2

Configuration

No configuration file

--new-from-rev <sha of 1 commit before HEAD>

Go environment

Using binary

Verbose output of running

Running with --new-from-rev HEAD~1 doesn't show anything even though an unused variable was introduced in the last commit when an error already existed before a merge commit. When adding changes in unrelated files it shows all problems even though some of them have been introduced before.

A minimal reproducible example or link to a public repository

#!/bin/sh
set -x

REPO="rev-binary"
git init "$REPO" && pushd $_
echo golangci-lint > .gitignore
GOLANGCI_LINT_VERSION="1.54.2"
curl -Lf https://github.com/golangci/golangci-lint/releases/download/v${GOLANGCI_LINT_VERSION}/golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64.tar.gz | tar xz -C . --strip-components=1 && chmod +x ./golangci-lint
git add .
git commit -m "chore: initial empty commit."

go mod init github.com/gcl/example 
git add .
git commit -m "chore: setup project"

cat <<EOF > foo.go
package pkg

func foo() {
    unusedVariableInFoo := 0
}
EOF
git add .
git commit -m "introduced unused var"

git diff HEAD~1
./golangci-lint run
./golangci-lint run --new-from-rev HEAD~1

git checkout -b b1
git commit -m "empty b1" --allow-empty
git switch -
git merge b1 --no-ff --no-edit

cat <<EOF >> foo.go

func foo2() {
    unusedVariableInFoo2 := 0
}
EOF
git add .
git commit -m "another prob"

git diff HEAD~1
./golangci-lint run
# NOTE the following command doesn't print anything although it should print the problem within bar()
./golangci-lint run --new-from-rev HEAD~1

cat <<EOF > bar.go
package pkg

func bar() {
    unusedVariableInBar := 0
}
EOF
git add .
git commit -m "another prob"

git diff HEAD~1
./golangci-lint run
# NOTE the following command also prints the problems in foo.go although this file didn't change in the last commit
./golangci-lint run --new-from-rev HEAD~1

echo "Cleanup"
popd
rm -rf "$REPO"

Validation

  • Yes, I've included all information above (version, config, etc.).

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions