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 committed
Sep 27, 2006 at 01:21 UTC
fd28b34afd9bbd58297a25edced3f504c9a5487a
3 files changed
+28
-2
builtin-update-index.c
+3
-1
@@ -112,11 +112,13 @@ static int add_file_to_cache(const char *path)
112
ce->ce_mode = create_ce_mode(st.st_mode);
113
if (!trust_executable_bit) {
114
/* If there is an existing entry, pick the mode bits
115
- * from it.
115
+ * from it, otherwise force to 644.
116
*/
117
int pos = cache_name_pos(path, namelen);
118
if (0 <= pos)
119
ce->ce_mode = active_cache[pos]->ce_mode;
120
+ else
121
+ ce->ce_mode = create_ce_mode(S_IFREG | 0644);
122
}
123
124
if (index_path(ce->sha1, path, &st, !info_only))
read-cache.c
+3
-1
@@ -347,11 +347,13 @@ int add_file_to_index(const char *path, int verbose)
347
ce->ce_mode = create_ce_mode(st.st_mode);
348
if (!trust_executable_bit) {
349
/* If there is an existing entry, pick the mode bits
350
- * from it.
350
+ * from it, otherwise force to 644.
351
*/
352
int pos = cache_name_pos(path, namelen);
353
if (pos >= 0)
354
ce->ce_mode = active_cache[pos]->ce_mode;
355
+ else
356
+ ce->ce_mode = create_ce_mode(S_IFREG | 0644);
357
}
358
359
if (index_path(ce->sha1, path, &st, 1))
t/t3700-add.sh
+22
@@ -19,4 +19,26 @@ test_expect_success \
19
'Test that "git-add -- -q" works' \
20
'touch -- -q && git-add -- -q'
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
+
44
test_done