Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent git on Cygwin to set core.filemode=true

Tags:

git

cygwin

I am using git from a Cygwin installation on my Windows PC. Although cygwin supports the Unix permission bits on an NTFS file system, native Windows programs like my Eclipse don't know about them so that all files created by Windows programs have the executable bit set (755).

I only rarely ever need to check in a file with executable bit set into a Git repository. Therefore, I would like to have core.filemode=false by default. I set this value in my global configuration, but unfortunately this typically has no effect: as documented, git clone probes the file system to see if it supports permissions and sets the core.filemode accordingly per repository, and therefore I have a core.filemode=true configuration in every repository configuration, overriding my desired default.

Is there a way to prevent git clone from setting core.filemode automatically?

like image 840
oberlies Avatar asked Sep 17 '12 11:09

oberlies


2 Answers

The core.fileMode = true setting can be cleared automatically using a git hook. In this case I believe a post-checkout hook, which will run anytime a branch is checked out or a repo is cloned, is the best option. Create bash script named post-checkout (no file extension) with the following contents:

#!/usr/bin/env bash

core_file_mode=$( git config --local core.fileMode )

if [[ "${OSTYPE}" == 'cygwin' && "${core_file_mode}" == 'true' ]]; then
    git config --local --unset core.fileMode
fi

If you want the hook to be applied to an individual repo put the script in $GIT_DIR/hooks (by default $GIT_DIR is <path-to-your-repo>/.git). If want the hook to apply to all projects add the following entry to your global gitconfig file:

[core]
    hooksPath = '<path-to-folder-containing-your-hook(s)>'
like image 43
Grant Humphries Avatar answered Oct 24 '22 12:10

Grant Humphries


You can set up Bash such that each time you cd it checks if that directory is a repository and sets it up properly. In your ~/.bash_profile add

PROMPT_COMMAND=pc
pc () {
  [ -d .git -a ! -g .git/config ] || return
  git config core.filemode 0
  chmod +s .git/config
}
like image 155
Zombo Avatar answered Oct 24 '22 10:10

Zombo