-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
--new-from-rev gets confused by merge commits #4097
Comments
Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors. |
Hello,
Have you tried with previous versions? is there a difference? |
Which version do you want me to try? I am not aware of any previous working version. I tried 1.50.0 for example with the same result. |
Hi @ldez, friendly reminder. Can you help us with this please? |
This is how git works, so I have no magic solution. |
Can you elaborate on which part of Git workings you are referring to? To me the git diff looks as expected but |
This comment was marked as off-topic.
This comment was marked as off-topic.
I think I'm currently running in the same problem when using golangci-lint in Gitlab merge result pipielines. This is my CI stage: lint:
image: golangci/golangci-lint:latest-alpine
script:
- git fetch origin $CI_MERGE_REQUEST_TARGET_BRANCH_NAME && git branch $CI_MERGE_REQUEST_TARGET_BRANCH_NAME -f remotes/origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME
- git diff HEAD $CI_MERGE_REQUEST_TARGET_BRANCH_NAME # Works, and gives back files and lines that do contain linting errors.
- golangci-lint run --new-from-rev $CI_MERGE_REQUEST_TARGET_BRANCH_NAME # No result, this same command works locally. Locally it works fine, but within merge result pipelines it does not work :( |
@janwytze we discovered this in the GitHub CI which by default also creates a merge commit against the base branch. So golangci-lint is pretty much unusable for GitHub CI at the moment as well. |
@mering Hmm, but
I've also added these commands:
golangci-lint internally uses revgrep. This works well, also in the Gitlab CI merge result pipeline. So both git diff and revgrep do detect the correct diff, also in the merge result pipeline. I just don't understand how |
@janwytze I mean golangci-lint without this fixed is unusable. I updated my previous comment to clarify this. |
@mering Sorry I was also talking about The hardest part about it, is that I am not able to reproduce this locally in any way. When I have some spare time I will try to find a way to reproduce it, and hopefully fix it. Do you maybe have a way to reproduce it locally? I've tried creating a new branch of the target branch, merging it source branch in it and then running it with the origin target branch as rev. This works perfectly... This is the same as what a result pipeline does right? |
@janwytze yes I included a minimal reproduction example in the issue description. Just unfold the "Details". |
What makes this issue more confusing is that there is a difference between how git installed via homebrew on MacOS behaves (it gets the diff mostly correctly) and how git from macos dev toosl behaves (this bug reproduces there for me). |
@PiotrZakrzewski-instruqt I noticed a lot in differences with my local I really wanted to get it working, so I created a CI stage which would soft reset all changes between the target branch and source branch, and make them unstaged. The Then I tried to replicate it with a clean repo, but then everything seems to work just fine. But most of our Gitlab repo's seem to break So shortly, there are differences between my local installation and the docker image (maybe git version). And fresh repo's seem to work fine, but the Gitlab repo's we want to apply the linting to don't seem to cooperate. |
@janwytze did you try the minimal reproduction example from the issue description? |
@mering Yes I did, your example gives the same results on my local installation and in Docker. I've also debugged through the source code with your example, but making a fix is not that easy :( I don't know if my issue where unstaged changes with the |
The example (from the description) is not really a good example because the reports are only related to If you look closely at the output:
You can see that the report is on As the error is a compilation error, it's not possible to skip it. The 2nd case (after the merge with the comment If someone can create a reproducible example with a real linter, it can help. |
I modified the script to be based on a real linter: modified script#!/bin/sh
set -x
REPO="rev-binary"
rm -rf $REPO
git init "$REPO" && pushd $_
echo golangci-lint > .gitignore
GOLANGCI_LINT_VERSION="1.57.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 commit."
go mod init github.com/gcl/example
git add .
git commit -m "chore: setup project"
cat <<EOF > foo.go
package example
import "errors"
func foo(a string) error {
if a == "a" {
return nil
}
return errors.New("OOPS")
}
func Bar1() {
foo("b")
}
EOF
git add .
git commit -m "introduced problem"
git diff HEAD~1
# 1 issue expected.
./golangci-lint run
# 1 issue expected.
./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 Bar2() {
foo("b")
}
EOF
git add .
git commit -m "another prob"
git diff HEAD~1
# 2 issue expected.
./golangci-lint run
# 1 issue expected.
./golangci-lint run --new-from-rev HEAD~1
cat <<EOF > bar.go
package example
func BarBar() {
foo("b")
}
EOF
git add .
git commit -m "another prob"
git diff HEAD~1
# 3 issue expected.
./golangci-lint run
# 1 issue expected.
./golangci-lint run --new-from-rev HEAD~1
echo "Cleanup"
popd
rm -rf "$REPO"
Everything works as expected. I think the root of the confusion was only because the text of the The other behavior is related to the fact that the diff processor, in some unexpected cases, ignored/skipped |
Welcome
Description of the problem
Adding a reproduction example to demonstrate breakage of #4047.
Version of golangci-lint
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
Validation
The text was updated successfully, but these errors were encountered: