-
Notifications
You must be signed in to change notification settings - Fork 2.6k
provide simple option to set unix style on windows platform(Git Bash) #1959
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
Comments
Could you elaborate?
What pre-commit hook? It would be good to come up with a Minimal, Complete & Verifiable Example to drive this ticket forward. |
rewrite the description, please comment if anything is still not clear. Thanks. |
Without seeing that hook, there is little anybody else can do (except for conjecturing wild guesses). In any case, it might be as benign as a lack of the appropriate And for the record, your edits did not provide any example, let alone a minimal, complete & verifiable one. So the ball is squarely in your court, still. |
Thanks dscho very much. I think “* text=auto” is the solution that what we are looking for. I will try to suggest our administrator to set this in the repository. But personally, I still suggest GIT-bash can provide unix-style option for local git configuration on windows system. Since autocrlf is not suggested for cross-platform team work. For this issue reproduction, we can follow below steps: |
In these steps, I do not see any Could you please turn this MCVE into a real script? |
Hi dscho, Please following below steps and try to reproduce it on Windows platform: 1, change .git\hooks\pre-commit.sample to pre-commit Here will no warning in Step 7, and will success on step 9. Thanks, |
@xheke so when I try this, I see what you are seeing. But on Windows, the committed file is not CR/LF. It is in the worktree, but not in the Git index (verify for yourself, using To get the same behavior on Windows as on Linux, you simply have to set You can even do that by choosing the option "Checkout as-is, commit as-is" in Git for Windows' installer. Does that clarify why you see what you see? |
Hi dscho, That why we need one option to set UNIX-style or Windows-style for git base environment, we hope when we set UNIX-style option for git bash, the pre-commit hook (or something else, perhaps is diff) can auto detect the DOS format files and prevent commit as on UNIX platform behavior. Thanks for your help. |
Yes, and we do have that. I even pointed it out to you:
This is the option that you asked for. Having said that, I think you'd be a lot better served by following the excellent advice in https://www.edwardthomson.com/blog/git_for_windows_line_endings.html. Since you want Unix line endings (LF-only, to be precise) in all your files, just add a file In short: there are ways in Git to get what you want. |
”You can even do that by choosing the option "Checkout as-is, commit as-is" in Git for Windows' installer.” -- this option only work for existed files but no impact for new files. “Having said that, I think you'd be a lot better served by following the excellent advice in https://www.edwardthomson.com/blog/git_for_windows_line_endings.html. Since you want Unix line endings (LF-only, to be precise) in all your files, just add a file .gitattributes (unless it exists already) and declare * eol=lf. In short: there are ways in Git to get what you want.” -- agree,it is right way. But I am not the GIT administrators in our product/project. I already ask them to change the setting. but there are long process in our company,till to now,no response from them. so, if we can do something from local, that may helpful. |
@xheke you do not change In any case, it has become clear that this is not a bug in Git for Windows, so I'll close this ticket. |
Yes, it is not bug, but one suggestion. thanks. |
Are we not accidentally talking across each other here. Hooks are not stored in the repo object store, so (IUC) are not subject to the various attribute settings. The various bits of advice about setting attributes, while useful, are closing the stable door after the horse has bolted (aren't users annoying;-). The hook is meant to be a poka yoke test, and it's failing... As @xheke says, "the pre-commit hook doesn’t work fine", and it is the (reading of) pre-commit hook that in some way needs fixing, so that if it has CRLF endings (on Windows), then it should work the same as if it had only LF endings on Linux. Now I see that this problem could be:
For point 2, I'd still see that as needing a contributor (@xheke and colleagues) provided PR. However it is more important to agree what the problem actually is, and avoid the XY-Problem aspect. |
@PhilipOakley the And from there, the discussion evolved to cover the aspect of having a different So I still think that we resolved this conundrum to @xheke's satisfaction. |
Thanks @PhilipOakley, I think you got my points exactly. @dscho, I have no right to change .gitattributes since it is controlled by the administrators. For point 2 listed by @PhilipOakley, whatever core.autocrlf set to true or false, include "Checkout as-is, commit as-is" option, we still have no way to avoid colleagues continue to commit more and more format errors to DB during this period. That real let me very upset ... ... |
@dscho , please consider below scenarios: scenario 1: scenario 2: For these two scenarios, the errors will be increased day after day. if we have unix-style options, for these two scenarios, the commit will failed, that will force or remind colleagues to check file's format. In this way, we can avoid to increase errors and decrease already existed errors in DB day after day. BTW, the administrators may not change .gitattributes for some other reasons from their view, I guess in some complex conditions. |
Well, you asked how to fix it, you got the proper solution, and now you tell us that you need another fix because somebody refuses to apply the necessary changes. I have no idea how I can help, then! |
@dscho, this is just suggestion, that may help others with some conditions like me in the future.
I don't know why our administrators still not change this attributes, it is just my guess, i don't know the real reason. but it is another problem not related to this suggestion. |
On 02/03/2019 01:59, xheke wrote:
Thanks @PhilipOakley <https://github.com/PhilipOakley>, I think you
got my points exactly.
@dscho <https://github.com/dscho>, I have no right to change
.gitattributes since it is controlled by the administrators.
@xhehe, could you describe how your local repository is setup and why
the administrators have so much control?
I am guessing that the local repository is on a drive letter that is
actually a network share allocated to you, but hosted on a central
server (rather than your hard/SSD drive).
And that the .gitattributesfile has been locked as a read only,
administrator access file.
Are you able to share the content of that file (with sensitive aspects
removed/redacted).
Also, what method is used for re-integrating individual changes into the
upstream master? Which workflow is used - see
https://git-scm.com/book/en/v2/Distributed-Git-Distributed-Workflows -
are you (a) Centralized Workflow (b) Integration-Manager Workflow (c)
Dictator and Lieutenants Workflow, or (d) special local variants?
Within the flows (especially b&c) there are two types of upward flow:
(1) patches, (2) Pull Requests (split `git` and GitHub styles)
For point 2 listed by @PhilipOakley <https://github.com/PhilipOakley>,
whatever core.autocrlf set to true or false, we have no way to avoid
colleagues continue to commit more and more format errors to DB during
this period.
Are you able to personally visit the colleagues who have the 'problem'
to help and advise them? If you are able to set your _personal_
core.autocrlf [1], then visiting colleagues and getting them to change
their _personal_ setting may be the best way to at least remove the most
significant problems.
That real let me very upset ... ...
I would agree that if the administrators have a poor default setup (and
not user training) then it can be an issue. Choosing the right defaults
can be hard. However Git is a _distributed_ system so everyone gets to
have their own control, which is confusing for managers in a command and
control style system.
Philip
[1] if you can change your local core.autocrlf then you do have hope...
|
I still don't get why setting |
I expect that the confusion is because it is not @xheke that needs to make the change. It is the 'colleagues' (wherever they may be) that need to be made to change their settings. And that would need some bigger management action that isn't in @xheke's gift, leaving @xheke frustrated that there is almost nothing 'they' can do beyond whinging to indifferent management/administrators. Plus, reading between the lines, @xheke then has to fix the issue created by those 'bad' commits. To summarise, it is a right answer, but does not distribute well (or at all) in @xheke's environment, hence the XY-problem aspects! I think they may need an Automated Integration Manager Workflow, where instead of a race to commit first (Centralised flow), they send a PR, which is then auto checked, and if passing, can be committed to the golden repo, but again, it needs management to do something (and when does that happen ;-) It's a people / social problem, not a Git [technology] problem! |
No, the right answer is changing |
@PhilipOakley, thanks for your help. I can not get the whole picture for our git flow. But let me try to describe our work flow: Our team work on the branch for the feature of the product, at the same time, other teams may work on the other branch together. Feature Teams, include administrators team, may come from the whole world, we don't know each other but communicate by email or issue track system. that is the brief background information. In general, we follow below steps to work: From page provided by @dscho, I saw .gitattributes should be configured in the repository but not in the local Git configuration.
I send mail to our administrators team and provide three suggestions:
Seems the suggestions are still under discussion in administrator team during this time. I agree with you, It's a people / social problem, not a Git [technology] problem! I have no idea how to handle this problem, what I can do is ensure my work is good. I talked to my colleagues, most of them may have confusion how to set core.autocrlf , from my view, it should be set to "input", is that right? Anyway, I am so upset for current environment :( Hope pre-commit hook is work both for UNIX platform and Windows platform in the future ... .. Hope our administrators take action ASAP :) |
Hi @xheke I think the discussion should be taken to the Git-users group list (https://groups.google.com/forum/#!forum/git-users), to avoid cluttering the bug tracker.
That will depend....
The pre-commit hook is a red herring as it is also a local (personal) setting, with the same roll out issues. It is only the upstream server that could do checking before accepting a push from someone (who may have made the mistake). That would be a pre-receive hook (and needs to be done by the admin of that server) |
Many thanks @PhilipOakley for your very kindly help ! |
The comment from management team:
My answer:
I think there are two levels to manage this problem( diff errors check): Anyway, it is suggestion. Best Wish, |
an aside: could you (@xheke ) clarify/annotate who the various "we/you/your/they" statements refer to. This is so that there is no confusion between different groups (both within the corporate structure and the open source git teams) as to where fingers are being 'pointed' or 'suggestions' being made, as to who should (or should not) do which bit of work. At the moment it looks like you are "between a rock and a hard place" (where ownership and authority have been separated). Also consider (via https://githooks.com/), e.g. * pre-receive: Enforce project coding standards. ... If I read correctly, it would be the support group that would install such a hook (on the teams project server), but you would code it and test it first, by locally push/pulling to a second repo acting as a server via the file:// transport such that the hooks get triggered on your local machine. If you can demonstrate the hook, then you can take them (support group) up on their promised offer of support... |
@PhilipOakley, thanks for you kindly help first :) I’m not quite understand you first question, seems there are two groups, the corporate structure and the open source git teams. Yes, in our company, the ownership and authority have been separated. We have coding standards or coding rules, but unfortunately, for this problem, seems the administrator or management team think it should be solved by develop team, however, the develop team think it should be solved by management team. In personally, from my view, it should be handled by management team, that because they are last goalkeeper. The management team suggest us (develop team) to modify the standard hook locally, it is not the good idea, at least it is not the general solution. Absolutely, they observed there are around 1625 files in the repository not correctly saved in the past months or years. And I guess they also are aware the hook can not work on the window platform, so they suggest us to modify the hook to check EOL by ourselves. But it is not good idea from my thought, the hook should not be changed by them or us. It should be kept original and simple. That is why I said, provide UNIX style option in “git bash”, to take the same behavior of the hook is the suggestion. It is not my responsibility to avoid this problem between people and people, team and team, but I hope if we have some way to solve it in the future. |
hi @xheke
Just to clarify, and answer your question, I had the divisions more finely divided:
Back in #1959 (comment) you (3) quoted a response from your (1) support group which had a "you" in it - "you should be able to implement yourself", it was there that the potential 'who is you?' starts. I think they(1) are pointing at you(3), but really need to point at you(2), etc. etc. From the distance of being No 7 in the list it is easy to misunderstand, while for you at No3 there does not appear to be any ambiguity - which was why I asked initially (that's just to clarify, it's not an issue).
Which type of hook is this hook?
Do you mean that the type of hook above does not execute at all on Windows?
As noted in (5), the 'differences in OS abstractions and Windows user expectations' means that dscho's much earlier comment is still generally true. I doubt that there is an easy solution.
You (your(2) project) will need a 'flag day' where all the line ending errors are corrected, and a server side(1) script for your project that simply refuses to accept new commits that users attempt to push to the 'blessed' repository that contain such errors. You(3) can write such a script. My apologies if I(7) have gone on too much. |
That statement is incorrect, as I pointed out a couple times already. The hook does work correctly. It just does not detect any problem because |
It is still unclear what you mean, but I get more and more the impression that you want me to change the default from |
@xheke Are you able to post your current and project .gitattributes, git config and that standard hook, or at least the relevant parts? As has been noted a few times, this (at project scale) is a social / management issue. Identify the starting point, and a desired end point , and plan a route... |
@dscho, I got your message this time. I redo the test with core.autocrlf = false again, this time, I got I want, you are right, if core.autocrlf = false, the hook can work fine just as in UNIX platform. Perhaps, from my view, core.autocrlf = false is almost like unix-style(in our cases), but something look like a little strange. autocrlf like behavior/action, unix/windows style is like a mode.
No, it is not my want. I just want to find out the solution, you give me two useful suggestions. One for remote, one for local, it is really help me, and it is enough. there are some misunderstanding for the local solution, it is my fault. Sorry for that. For this issue, my suggestion is, can we consider use: unix-style replace: core.autocrlf true |
@PhilipOakley, thank you so much! Without your help, I can not go there. I can not find any .gitattributes file in local directory, I also afraid if I change .gitattributes and push it, that may impact something else. :( With you and decho's help, now, I know, we can take below actions in our team: 1, set core.autocrlf = false that may avoid import more and more errors. |
@dscho , I recall what I saw at that time, the difference behavior between Linux and window: ( On Linux side: On Window side: |
@xheke are you asking me something? If so, I don't understand the question... |
Yes, is this possible provide "error message" on windows side just as on Linux side? Thanks dscho. |
If you set |
Setup
git version 2.19.2.windows.1
cpu: x86_64
built from commit: 26dcaa1
sizeof-long: 4
sizeof-size_t: 8
Microsoft Windows [Version 10.0.16299.726]
defaults?
$ cat /etc/install-options.txt
Editor Option: VIM
Custom Editor Path:
Path Option: Cmd
SSH Option: OpenSSH
CURL Option: OpenSSL
CRLF Option: LFOnly
Bash Terminal Option: MinTTY
Performance Tweaks FSCache: Enabled
Use Credential Manager: Enabled
Enable Symlinks: Disabled
to the issue you're seeing?
** insert your response here **
Details
** insert your response here **
GIT bash
Minimal, Complete, and Verifiable example
this will help us understand the issue.
git apply ../diff/abc.diff
** insert here **
We want prevent commit code files with DOS format to repository.
Therefore, we enable client standard/default pre-commit hook on both Linux side and Windows side.
The hook works fine on Linux side as expected, but not works on Windows side.
We also observed that when we try to import diff with new DOS format files on the Linux side, GIT will report some whitespace warnings and this may lead commit failure with pre-commit hook impact. However, nothing happened on windows side if we do the same commands, and the commit will success even we enable the same pre-commit hook on Windows side.
We hope team can work with same style, no matter he/she work on Linux side or Windows side.
The behavior is different between Windows side and Linux side currently. In addition, we try to set core.autocrlf and core.safecrlf on Windows side, anyway, it does not prevent commit. Therefore, we hope if there have simple option to set like Linux-style on GIT bash (Windows Side) to simulate Linux environment (perhaps just for file format checking is enough) on Windows side.
** insert here **
no whitespace warnings report
URL to that repository to help us with testing?
** insert URL here **
The text was updated successfully, but these errors were encountered: