Use core.filemode.

With "[core] filemode = false", you can tell git to ignore
differences in the working tree file only in executable bit.

 * "git-update-index --refresh" does not say "needs update" if index
   entry and working tree file differs only in executable bit.

 * "git-update-index" on an existing path takes executable bit
   from the existing index entry, if the path and index entry are
   both regular files.

 * "git-diff-files" and "git-diff-index" without --cached flag
   pretend the path on the filesystem has the same executable
   bit as the existing index entry, if the path and index entry
   are both regular files.

If you are on a filesystem with unreliable mode bits, you may need to
force the executable bit after registering the path in the index.

 * "git-update-index --chmod=+x foo" flips the executable bit of the
   index file entry for path "foo" on.  Use "--chmod=-x" to flip it
   off.

Note that --chmod only works in index file and does not look at nor
update the working tree.

So if you are on a filesystem and do not have working executable bit,
you would do:

 1. set the appropriate .git/config option;

 2. "git-update-index --add new-file.c"

 3. "git-ls-files --stage new-file.c" to see if it has the desired
   mode bits.  If not, e.g. to drop executable bit picked up from the
   filesystem, say "git-update-index --chmod=-x new-file.c".

Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Junio C Hamano
2005-10-11 18:45:33 -07:00
parent 5cbb401dba
commit 3e09cdfd11
4 changed files with 70 additions and 9 deletions

View File

@ -15,7 +15,7 @@ static void show_file(const char *prefix,
}
static int get_stat_data(struct cache_entry *ce,
unsigned char **sha1p, unsigned int *modep)
unsigned char ** sha1p, unsigned int *modep)
{
unsigned char *sha1 = ce->sha1;
unsigned int mode = ce->ce_mode;
@ -35,6 +35,10 @@ static int get_stat_data(struct cache_entry *ce,
changed = ce_match_stat(ce, &st);
if (changed) {
mode = create_ce_mode(st.st_mode);
if (!trust_executable_bit &&
S_ISREG(mode) && S_ISREG(ce->ce_mode) &&
((mode ^ ce->ce_mode) == 0111))
mode = ce->ce_mode;
sha1 = no_sha1;
}
}
@ -49,7 +53,9 @@ static void show_new_file(struct cache_entry *new)
unsigned char *sha1;
unsigned int mode;
/* New file in the index: it might actually be different in the working copy */
/* New file in the index: it might actually be different in
* the working copy.
*/
if (get_stat_data(new, &sha1, &mode) < 0)
return;
@ -174,6 +180,7 @@ int main(int argc, const char **argv)
int allow_options = 1;
int i;
git_config(git_default_config);
diff_setup(&diff_options);
for (i = 1; i < argc; i++) {
const char *arg = argv[i];