Git@OSC 安卓手机客户端测试版发布,尝鲜请 点击查看详情

Ignore executable bit when adding files if filemode=0.

If the user has configured core.filemode=0 then we shouldn't set
the execute bit in the index when adding a new file as the user
has indicated that the local filesystem can't be trusted.

This means that when adding files that should be marked executable
in a repository with core.filemode=0 the user must perform a
'git update-index --chmod=+x' on the file before committing the
addition.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Shawn Pearce 提交于
Junio C Hamano 提交于
master v1.8.3-rc2 ... v1.4.3
commit fd28b34afd9bbd58297a25edced3f504c9a5487a
1 parent 4dafd7d244

影响行数: 28 + 2 -

3 个文件发生了变化

builtin-update-index.c 查看文件 @ fd28b34
... ... @@ -112,11 +112,13 @@
112 112 ce->ce_mode = create_ce_mode(st.st_mode);
113 113 if (!trust_executable_bit) {
114 114 /* If there is an existing entry, pick the mode bits
115   - * from it.
  115 + * from it, otherwise force to 644.
116 116 */
117 117 int pos = cache_name_pos(path, namelen);
118 118 if (0 <= pos)
119 119 ce->ce_mode = active_cache[pos]->ce_mode;
  120 + else
  121 + ce->ce_mode = create_ce_mode(S_IFREG | 0644);
120 122 }
121 123  
122 124 if (index_path(ce->sha1, path, &st, !info_only))
... ... @@ -347,11 +347,13 @@
347 347 ce->ce_mode = create_ce_mode(st.st_mode);
348 348 if (!trust_executable_bit) {
349 349 /* If there is an existing entry, pick the mode bits
350   - * from it.
  350 + * from it, otherwise force to 644.
351 351 */
352 352 int pos = cache_name_pos(path, namelen);
353 353 if (pos >= 0)
354 354 ce->ce_mode = active_cache[pos]->ce_mode;
  355 + else
  356 + ce->ce_mode = create_ce_mode(S_IFREG | 0644);
355 357 }
356 358  
357 359 if (index_path(ce->sha1, path, &st, 1))
t/t3700-add.sh 查看文件 @ fd28b34
... ... @@ -19,5 +19,27 @@
19 19 'Test that "git-add -- -q" works' \
20 20 'touch -- -q && git-add -- -q'
21 21  
  22 +test_expect_success \
  23 + 'git-add: Test that executable bit is not used if core.filemode=0' \
  24 + 'git repo-config core.filemode 0 &&
  25 + echo foo >xfoo1 &&
  26 + chmod 755 xfoo1 &&
  27 + git-add xfoo1 &&
  28 + case "`git-ls-files --stage xfoo1`" in
  29 + 100644" "*xfoo1) echo ok;;
  30 + *) echo fail; git-ls-files --stage xfoo1; exit 1;;
  31 + esac'
  32 +
  33 +test_expect_success \
  34 + 'git-update-index --add: Test that executable bit is not used...' \
  35 + 'git repo-config core.filemode 0 &&
  36 + echo foo >xfoo2 &&
  37 + chmod 755 xfoo2 &&
  38 + git-add xfoo2 &&
  39 + case "`git-ls-files --stage xfoo2`" in
  40 + 100644" "*xfoo2) echo ok;;
  41 + *) echo fail; git-ls-files --stage xfoo2; exit 1;;
  42 + esac'
  43 +
22 44 test_done
注册 登录 后才可以发表评论。