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

Git cola not saving configuration on Windows #927

Closed
mmoderau opened this issue Feb 7, 2019 · 19 comments
Closed

Git cola not saving configuration on Windows #927

mmoderau opened this issue Feb 7, 2019 · 19 comments

Comments

@mmoderau
Copy link

mmoderau commented Feb 7, 2019

Whenever I edit Settings in preferences window ("Insert spaces instead of tabs", "Editor" etc.) the values are not saved. Closing the Preferences dialog and re-opening it shows the old (default) values.

My system is Windows 10. I installed git-cola using the provided installer.

Home directory settings (enforced by company IT):

HOMEDRIVE=U:
HOMEPATH=\

Git cola version is 3.3.

@mmoderau
Copy link
Author

mmoderau commented Feb 7, 2019

To further clarify: I mean git-cola settings, not git settings.

@jm4R
Copy link
Contributor

jm4R commented Feb 7, 2019

This sometimes also happens to me in "All repositories" tab. Works good in "This Repository" tab. Can you check this is your case too?

@davvid
Copy link
Member

davvid commented Feb 9, 2019

I suspect it's the part where we figure out where your ~/.gitconfig lives. On Unix this is all super simple and easy, it's in /home/$USER/.gitconfig and we can just ask python to do os.path.expanduser('~/.gitconfig') and get the correct answer.

Someone with a Windows machine can do a little poking around and see what's changed in Git for Windows, or possibly your specific configuration, that is breaking these assumptions.

The file of interest is cola/gitcfg.py. It's possible you'll have to add some platform-specific behavior to check for the environment variables you mentioned when calculating the home directory.

In general, supporting windows is a royal pain in the aardvark, and I sometimes wonder whether it's even worth it. I don't run Windows so any help from Windows users is appreciated.

The other possibility is that git config --global foo bar isn't working as expected. That's basically what we're doing to store values in the git config.

@mmoderau
Copy link
Author

This sometimes also happens to me in "All repositories" tab. Works good in "This Repository" tab. Can you check this is your case too?

Yes, this exactly. Changes to "This repository" are preserved, while changes to "All repositories" reset as soon as I move to a different tab in "Preferences" window.

@davvid , I will try to check what you describe.

@mmoderau
Copy link
Author

For what is worth: os.path.expanduser(os.path.join('~', '.gitconfig')) (as used, more or less, in gitcfg.py) returns u'C:\\Users\\moderaum\\.gitconfig'

My actual .gitconfig file, as used by git bash, is located in U:\.gitconfig

XDG_CONFIG_HOME variable, that is used to set the path for git-cola settings is not set.

@mmoderau
Copy link
Author

On the other hand... saving some preferences work. Just not those in the "preferences" dialog.

For example, saving recent repositories works. Adding custom toolbars too.

@davvid
Copy link
Member

davvid commented Feb 12, 2019

Very interesting. As a test in your configuration where you have HOMEDRIVE and HOMEPATH set in your environment, what does this print?:

git config --global test.value 42
git config --global test.value

I suspect that will do the right thing and print 42. If that's the case, it does seem like a solution will be to adjust the gitcfg code to check for 1. utils.is_win32() is true, 2. core.getenv('HOMEDRIVE') and core.getenv('HOMEPATH') are defined, and if they are, 3. use the concatenation of those two paths as the home directory instead of using the expansion of ~.

From reading the logic, that should make it behave correctly. Let me know if you're able to run cola from its source tree. If so I can push up a test branch to try out (unless someone with a win32 environment beats me to it first).

Thanks for your help narrowing this down everyone -- that's super helpful.

@jm4R
Copy link
Contributor

jm4R commented Feb 12, 2019

That's weird because I can not reproduce it anymore - even on the same environment that bug happened before.

@mmoderau
Copy link
Author

@davvid , this prints correctly 42.

Additional informations:
After running:

"c:\Program Files\Git\bin\git.exe" config --global -l --show-origin

I got this output (email hidden for privacy reasons):

file:U://.gitconfig     user.email=M.Moderau@[...]
file:U://.gitconfig     push.default=upstream
file:U://.gitconfig     cola.fontdiff=DejaVu Sans Mono,8.25,-1,5,50,0,0,0,0,0
file:U://.gitconfig     cola.spellcheck=false
file:U://.gitconfig     cola.expandtab=true
file:U://.gitconfig     cola.blameviewer=git gui blame
file:U://.gitconfig     cola.tabwidth=4
file:U://.gitconfig     diff.tool="C:\Program Files\TortoiseGit\bin\TortoiseGitIDiff.exe"
file:U://.gitconfig     diff.algorithm=patience
file:U://.gitconfig     gui.editor=C:\dev\emacs-26.1-x86_64\bin\emacsclientw
file:U://.gitconfig     gui.historybrowser="C:/Program Files (x86)/git-cola/Python/pythonw.exe" "C:/Program Files (x86)/git-cola/git-cola.launch.pyw" dag --repo C:/dev/git/eds
file:U://.gitconfig     color.ui=true
file:U://.gitconfig     core.autocrlf=true
file:U://.gitconfig     core.preloadindex=true
file:U://.gitconfig     core.fscache=true
file:U://.gitconfig     test.value=42

@mmoderau
Copy link
Author

For what it's worth, I previously had a much older version of git-cola installed, so these settings in .gitconfig could be leftovers from that.

@mmoderau
Copy link
Author

@davvid, , please note, that some settings are successfully saved to:
c:/Users/moderaum/.config/git-cola/settings

guistate.mainview.toolbars, guistate.recent, guistate.mainview.lock_layout - basically anything that is not set through preferences dialog.

@mmoderau
Copy link
Author

For what it's worth, the old git cola successfully stored the config in u:/.config/git-cola/settings, but that might be because I almost always ran it through git bash (as git cola), which uses u:/ as ~/. I haven't found a way to do this with the new version, so I run it from Windows start menu instead.

@mmoderau
Copy link
Author

mmoderau commented Feb 15, 2019

Also, I just noticed that the windows start menu shortcut by default runs git-cola using %HOMEDRIVE%\%HOMEPATH% as current directory.

davvid added a commit to davvid/git-cola that referenced this issue Feb 16, 2019
Teach cola to find gitconfig on Windows when HOMEDRIVE and HOMEPATH are
set in the environment.

Add a new core.git_expanduser() that special-cases "~" expansion and use
it when constructing the paths to ~/.gitconfig.

Closes git-cola#927
Reported-by: Miron Moderau <em3@minions.org.pl>
Signed-off-by: David Aguilar <davvid@gmail.com>
@davvid
Copy link
Member

davvid commented Feb 16, 2019

I may have fixed this in the windows-gitconfig branch in my davvid/git-cola fork based on the details you provided. Thanks for your help.

That code is untested since I won't hit that code path in my environment. Please try it out and let me know if it's better behaved. If so I'll merge the fix in promptly.

davvid added a commit to davvid/git-cola that referenced this issue Feb 16, 2019
Teach cola to find gitconfig on Windows when HOMEDRIVE and HOMEPATH are
set in the environment.

Add a new core.git_expanduser() that special-cases "~" expansion and use
it when constructing the paths to ~/.gitconfig.

Closes git-cola#927
Reported-by: Miron Moderau <em3@minions.org.pl>
Signed-off-by: David Aguilar <davvid@gmail.com>
@shrutivarsha
Copy link

@davvid Hi! I wanted to contribute to this code, and when I came upon this issue. I checked the preferences and it seems to be solved. The changes made are saved. But I am unable to check if a change like "Insert spaces instead of tabs" is actually reflecting in the editor as I am unable to configure it properly. Could you guide me on how I can? I tried configuring in the preferences but it did not work.

@davvid
Copy link
Member

davvid commented Aug 31, 2021

Sure thing. That setting is related the commit message editor. Go into a test repo and create a commit and try inserting "tab" in the commit message editor. When you later inspect the commit message with git log you should see spaces instead of tabs.

It's a pretty subtle thing to notice. If you git commit --amend on the command-line, or use the ctrl-m to enable amend mode after creating a test commit, you should see any tabs that were originally there get replaced with spaces.

Let me know if that setting is working for you. I don't use windows so I very much appreciate help from windows users who can help clarify the instructions or improve the windows edge cases. git grep is_win32 to see some of the trickier parts where we have to deal with windows.

@davvid
Copy link
Member

davvid commented Aug 31, 2021

the per-repo git config user.email and global git config --global user.email settings are easy to test. Those all go through the git config configuration mechanism. We basically have two ways cola is configured.

Through git config stuff, via the global /etc/gitconfig, the per-user ~/.gitconfig and the per-repo .git/config. Cola reads/writes settings to these locations.

The other configuration mechanism is the settings json file that it writes for all of its internal non-git-config settings. This is typically written in ~/.config/git-cola/settings. Since the windows/toolbar settings were working, the only issue could possibly be the git config settings.

If you see issues, please try testing the windows-gitconfig branch in my https://github.com/davvid/git-cola fork. I believe we've already addressed this, but I haven't tested it, so if you could test it it would be helpful.

One note is that perhaps the edge case is when HOMEPATH or HOMEDRIVE are defined. If you don't have those set in your environment then you may not be able to reproduce the issue. Just a guess, though.

Let me know if you have any questions. I kinda forgot about this issue, but the branch is still there. I'm super curious to know whether the changes in that branch are related.

davvid added a commit to davvid/git-cola that referenced this issue Sep 29, 2022
Teach cola to find gitconfig on Windows when HOMEDRIVE and HOMEPATH are
set in the environment.

Add a new core.git_expanduser() that special-cases "~" expansion and use
it when constructing the paths to ~/.gitconfig.

Closes git-cola#927
Reported-by: Miron Moderau <em3@minions.org.pl>
Signed-off-by: David Aguilar <davvid@gmail.com>
@davvid
Copy link
Member

davvid commented Sep 29, 2022

In case anyone wants to test the latest version of the proposed patch, I've updated it and have repushed the windows-gitconfig branch to my davvid fork.

git remote add davvid https://github.com/davvid/git-cola.git
git fetch davvid
git checkout -b windows-gitconfig davvid/windows-gitconfig

If a Windows user is still having issues and can test this branch and verify that it fixes their issues then I'll merge it.

https://github.com/davvid/git-cola/tree/windows-gitconfig

davvid@2e7a8db

@davvid
Copy link
Member

davvid commented Oct 11, 2022

I just rewrote the config reader to be path-agnostic. The new implementation ensures that cola can always read gitconfig-provided configuration values. Please see the 2c77ba5 for more details.

The next release (v4.0.3 or newer) will contain the fix. Please test the latest from git.

bmwiedemann pushed a commit to bmwiedemann/openSUSE that referenced this issue Nov 12, 2022
https://build.opensuse.org/request/show/1035308
by user marcinbajor + dimstar_suse
- Update to 4.0.3
- Usability, bells and whistles
* The branches widget no longer loses its selection state in response to
  notifications and UI actions.
  git-cola/git-cola#1221
* The use of ``gravatar.com`` to fetch icons associated with author emails
  can now be disabled by setting `git config --global cola.gravatar false`.
  git-cola/git-cola#933
- Fixes
* The config reader has been revamped to better read settings when git config
  files are located in unexpected locations.
  git-cola/git-cola#927
  git-cola/git-cola#1264
* The preferences dialog no longer throws an error when the editor has not
  been configured.
  git-cola/git-cola#1263
* Context menu ac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants