go-git icon indicating copy to clipboard operation
go-git copied to clipboard

Support ignoring chmod changes on filesystems that do not support chmod (e.g. FAT)

Open osklyar opened this issue 7 years ago • 7 comments

There is a common Windows issue with Unix executables in it: cloning those in Windows leads to differences between the filesystem and the git index because Windows reports 10644 for Unix 10755 files. The standard git client permits ignoring such differences transparently via the following config option: git config core.fileMode false. A similar option is required for go-git otherwise it is very difficult to work with repositories containing Unix executables.

More info on the behaviour of the standard git client can be found here: http://stackoverflow.com/questions/1580596

A particular example of what happens on the go-git client is then found in the following earlier issue (which I will close in favour of this one for clarity): #373

Up to now I failed to find where the index tree is read from the cloned file. If you give me a couple of hints where to search I would be happy to work on a patch.

osklyar avatar May 05 '17 12:05 osklyar

The configuration option would need to be added to the config parsing: https://github.com/src-d/go-git/blob/7cd021554eb318165dd28988fe1675a5e5c32601/config/config.go#L35

Index is read in plumbing/format/index/decoder.go, but I don't think we should change the way index is decoded for this.

Maybe we could fix this by modifying Worktree.Add here, so that based on Config we can add some conditional behavior to ignore executable bit on file mode: https://github.com/src-d/go-git/blob/ced875aec7bef9113e1c37b1b811a59e17dbd138/worktree_status.go#L268

smola avatar May 08 '17 10:05 smola

Sorry if this is not right place to report this. But maybe this problem is related to this issue. so I want this feature very much!

Problem

I just want to do git pull. but after I manually run git reset --hard HEAD~ in command-line, Worktree.Pull() returns "worktree contains unstagged changes" error.

My environment is Windows Subsystem Linux (WSL). But this is maybe common problem on Windows.

Here is steps to reproduce:

  1. cd {repo}
    • {repo} is under /mnt/c/...
    • In WSL, /mnt/c is C drive
    • If I run git diff HEAD in that repository, I get the following result:
$ git diff HEAD
diff --git a/README.md b/README.md
old mode 100644
new mode 100755

2. git reset --hard HEAD~ 3. Compile this code and run ./git-pull {repo} (git-pull is compiled command of that code)

tyru avatar Nov 11 '17 17:11 tyru

Hey, I was trying to work on this and managed to get it work for as far as staged files are concerned. However, when it comes to unstaged files, the Merkletrie package directly gets the file mode and compares it with the one in the index (this is not a problem with a staged file because we can change its git mode when it is added to the index).

I'm not super-knowledgeable on the codebase, so I would like to ask how do you think it's best to approach this? Passing down the config file to merkletrie doesn't sound like a good idea.

EDIT: I can also submit a WIP PR if you want.

thehowl avatar Sep 20 '18 13:09 thehowl

+1 on this, @thehowl please share your changes, it might work for me in the mean time...

rojer avatar Sep 26 '18 21:09 rojer

i should also add that despite what the title says, it doesn't just apply to FAT volumes, it doesn't work on NTFS either, which means pretty much everywhere. fwiw, windows Git clones repos with filemode = false by default. go-git should do the same (once it's implemented, of course).

rojer avatar Sep 26 '18 21:09 rojer

@rojer see #970

thehowl avatar Sep 27 '18 08:09 thehowl

Any update on this? really need this for windows.

hulucc avatar Jan 04 '20 10:01 hulucc