Skip to content
This repository was archived by the owner on Jun 26, 2024. It is now read-only.

Conversation

pmacik
Copy link
Contributor

@pmacik pmacik commented Mar 24, 2021

Motivation

Currently it is possible to accidently commit conflict notes (such as <<<<<<< HEAD) in source files without actually noticing it.

Changes

This PR:

  • Adds a new linter for detecting git conflict notes in tracked and staged files.

Testing

make lint-conflicts

@codecov
Copy link

codecov bot commented Mar 24, 2021

Codecov Report

Merging #912 (5a7a037) into master (81b6624) will decrease coverage by 1.34%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #912      +/-   ##
==========================================
- Coverage   63.84%   62.50%   -1.35%     
==========================================
  Files          25       20       -5     
  Lines        1751     1040     -711     
==========================================
- Hits         1118      650     -468     
+ Misses        461      300     -161     
+ Partials      172       90      -82     
Impacted Files Coverage Δ
pkg/binding/definition.go 47.00% <0.00%> (-0.50%) ⬇️
controllers/secret/secret.go
controllers/mapper.go
controllers/sbrcontroller.go
controllers/common.go
pkg/envvars/envvars.go
controllers/binder.go
controllers/reconciler.go
controllers/retriever.go
controllers/flag.go
... and 18 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 81b6624...5a7a037. Read the comment docs.

@pmacik pmacik force-pushed the lint-conflict-notes branch from bb5d0b3 to 87885f1 Compare March 26, 2021 15:34

echo -ne "\n\tChecking staged files... "
if [ $(git diff --cached --name-only | wc -l) != "0" ]; then
results=$(git diff --cached --name-only | grep -v "vendor/" | xargs grep -PiIrnH '<<<<''<<<|>>>''>>>>|===''====' || true)
Copy link
Contributor

Choose a reason for hiding this comment

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

we can move even check logic into check_result (or whatever we call it later on) function. Something along these lines:

check_merge_conflicts() {
  for f in "$@"; do 
    grep -PiIrnH '<<<<''<<<|>>>''>>>>|===''====' "$f" && echo "$f" && break
  done || found=1
if [ -z "$found" ]; then
  echo PASS
else
  echo FAIL
  exit 1
fi
}

check_merge_conflicts $(git diff --cached --name-only | grep -v "vendor/")
check_merge_conflicts $(git ls-tree --full-tree -r HEAD --name-only | grep -v "vendor/")

@pmacik pmacik force-pushed the lint-conflict-notes branch from 87885f1 to 5a7a037 Compare April 12, 2021 11:54
@pedjak
Copy link
Contributor

pedjak commented Apr 12, 2021

/lgtm
/approve

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: pedjak

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit 5417a97 into redhat-developer:master Apr 12, 2021
@pmacik pmacik deleted the lint-conflict-notes branch May 24, 2021 16:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants