Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: permissive git diff parameter #185

Merged
merged 9 commits into from
Sep 10, 2021

Conversation

nvuillam
Copy link
Contributor

@nvuillam nvuillam commented Aug 19, 2021

Manage a new argument --permissivediff to add the following parameters to git diff call

[
    '--ignore-all-space',
    '--ignore-blank-lines',
    '--ignore-cr-at-eol',
    '--word-diff-regex',
]

It allows to avoid detecting as a difference the indentation/spaces stuff

Fixes #184

@codecov
Copy link

codecov bot commented Aug 20, 2021

Codecov Report

Merging #185 (db0dc0c) into master (6b2adb4) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #185   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           19        19           
  Lines          459       462    +3     
=========================================
+ Hits           459       462    +3     
Impacted Files Coverage Δ
src/utils/fileGitDiff.js 100.00% <100.00%> (ø)
src/utils/gitConstants.js 100.00% <100.00%> (ø)
src/utils/repoGitDiff.js 100.00% <100.00%> (ø)

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 6b2adb4...db0dc0c. Read the comment docs.

@scolladon scolladon changed the title Allow to use permissive git diff to ignore diffs related to indentation feat: permissive git diff parameter Aug 20, 2021
@scolladon
Copy link
Owner

Hi @nvuillam !

I copy paste my comment from the related issue

I have questions:

  • Why this should not be the standard behaviour? => What will be the added value to that and why both use cases should exists?
  • why using --word-diff-regex parameter? With which value?

Suggestion: the parameter name must follow the cli parameter apache convention. I suggest the following --permissive-diff -P if we keep this wording

Please add me to your fork so I can contribute and help you solve CI/CD issues you may encounter

Manage a new argument --permissivediff to add the following parameters to git diff call

[
    '--ignore-all-space',
    '--ignore-blank-lines',
    '--ignore-cr-at-eol',
    '--word-diff-regex',
]
It allows to avoid detecting as a difference the indentation/spaces stuff
@scolladon scolladon force-pushed the feature/permissivediff branch from 520f5e7 to 7c0fa4f Compare August 30, 2021 06:51
@nvuillam
Copy link
Contributor Author

nvuillam commented Sep 2, 2021

@scolladon I see you made the code more clean, nice ! :)

When do you think this could be released ? It would greatly help sfdx-hardis ^^

@scolladon
Copy link
Owner

scolladon commented Sep 3, 2021

Hi @nvuillam !

When do you think this could be released ? It would greatly help sfdx-hardis ^^

We are going to discuss about it today with @mehdisfdc and see how we can improve (if we can) and when to ship it
We'll keep you posted!

@nvuillam
Copy link
Contributor Author

nvuillam commented Sep 3, 2021

That's great, thanks for the feedback :)

README.md Outdated
trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]

OPTIONS
-D, --ignore-destructive=ignore-destructive ignore file to use

-P, --permissive-diff ignore git diff white char (space,
Copy link
Collaborator

Choose a reason for hiding this comment

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

@scolladon As discussed together, would you prefer to name the new command -W, --ignore-whitespace instead of -P, --permissive-diff? Both are fine with me.
@nvuillam Any opinion on this alternative name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mehdisfdc --ignore-whitespace-diff maybe ? :)
Anyway, while the capability is here, I don't matter the argument name :)

Copy link
Owner

Choose a reason for hiding this comment

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

I like -W, --ignore-whitespace 👍

'--ignore-all-space',
'--ignore-blank-lines',
'--ignore-cr-at-eol',
'--word-diff-regex',
Copy link
Collaborator

Choose a reason for hiding this comment

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

@nvuillam According to the git documentation, the --word-diff-regex parameter expects a <regex> value.
Otherwise it may apply a regex that is set locally in your gitattributes or git-config (extract from doc: "The regex can also be set via a diff driver or configuration option, see gitattributes[5] or git-config[1]. Giving it explicitly overrides any diff driver or configuration setting.").

To make sure the behaviour of this command is consistent for all SGD users, what do you think about specifying explicitly the regex to use? In other words, I suggesting to modify line 10 to specify explicitly the <regex> in --word-diff-regex=<regex> (I guess you could look into you gitattributes and git-config to retrieve the value that you used during your tests).

@scolladon To go further, in addition to specifying explicitly the default regex to apply, we could even offer the ability for the users to override it with their own regex (but that would a "nice-to-have" feature, while ensure a consistent behaviour in the command in more important IMHO).

Copy link
Owner

@scolladon scolladon Sep 3, 2021

Choose a reason for hiding this comment

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

@mehdisfdc I love the idea to let the user override the default regex, I will implement it with the new parameter name (once everyone is ok) and with the default regex value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

More flexibility for the user, I fully agree, great suggestion :)

Copy link
Owner

Choose a reason for hiding this comment

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

I bounce on @mehdisfdc's message, @nvuillam could you give us the git config taken by --word-diff-regex?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm sorry, I just used the parameter and I think I viewed a difference compared to without, but i've not sent any value to this parameter

Copy link
Owner

Choose a reason for hiding this comment

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

Could you retry on your side to make sure it does something ?
And if it does something on your side, as you don't use any regex with it, could you send us your gitattributes and git config please ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't have any .gitattributes defined

About git config, except user.name & user.email, I use

  • core.longpaths=true
  • core.quotepath=false

I'll try to make new tests, but unfortunately my work week is already busy, it may wait until next week :/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But why not publishing as it is now, and send --word-diff-regex to git if --word-diff-regex is sent to sfdx-git-delta, and append --word-diff-regex value only if it is sent ? :)

Copy link
Owner

Choose a reason for hiding this comment

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

I prefer not to do that because if no parameter are given to --word-diff-regex then it uses the local configuration in .gitattributes and .git/config, which can be anything and could lead to unexpected behaviour

Copy link
Owner

@scolladon scolladon Sep 7, 2021

Choose a reason for hiding this comment

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

So, I poced around and play a little bit with it.
It is also true for me that --word-diff-regex is required to have the right behavior.
I dig a little bit more in the documentation of this parameter in git and I found that there are default regex used (which are appened to the override foundable in .gitattributes and .git/config)

I wonder if we will have issues about this and how it will be to debug 😅 but I don't think it will be used by most of the users.
With that knowledge, it looks good to me 😄 for the version without the regex passed in arguments

@codeclimate
Copy link

codeclimate bot commented Sep 7, 2021

Code Climate has analyzed commit db0dc0c and detected 0 issues on this pull request.

View more on Code Climate.

@scolladon scolladon merged commit 6d57783 into scolladon:master Sep 10, 2021
@scolladon scolladon deleted the feature/permissivediff branch September 10, 2021 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[permissivediff] Allow to use permissive git diff to ignore diffs related to indentation
4 participants