@matheusbsbs / matheus-bagliano / commits / 2bbaaed9ee
Fork 0

trust-executable-bit: fix breakage for symlinks

An earlier commit f28b34a broke symlinks when trust-executable-bit is not set because it incorrectly assumed that everything was a regular file. Reported by Juergen Ruehle. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Nov 22, 2006 at 16:33 UTC 2bbaaed9eefa92e8a17e74ec5f9b87ecdc7a5949
3 files changed +18 -8
builtin-update-index.c
+3 -3
@@ -112,13 +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, otherwise force to 644.
115 + * from it, otherwise assume unexecutable.
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);
120 + else if (S_ISREG(st.st_mode))
121 + ce->ce_mode = create_ce_mode(S_IFREG | 0666);
122 }
123
124 if (index_path(ce->sha1, path, &st, !info_only))
read-cache.c
+3 -3
@@ -347,13 +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, otherwise force to 644.
350 + * from it, otherwise assume unexecutable.
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);
355 + else if (S_ISREG(st.st_mode))
356 + ce->ce_mode = create_ce_mode(S_IFREG | 0666);
357 }
358
359 if (index_path(ce->sha1, path, &st, 1))
t/t3700-add.sh
+12 -2
@@ -27,7 +27,7 @@ test_expect_success \
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;;
30 + *) echo fail; git-ls-files --stage xfoo1; (exit 1);;
31 esac'
32
33 test_expect_success \
@@ -38,7 +38,17 @@ test_expect_success \
38 git-update-index --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;;
41 + *) echo fail; git-ls-files --stage xfoo2; (exit 1);;
42 + esac'
43 +
44 +test_expect_success \
45 + 'git-update-index --add: Test that executable bit is not used...' \
46 + 'git repo-config core.filemode 0 &&
47 + ln -s xfoo2 xfoo3 &&
48 + git-update-index --add xfoo3 &&
49 + case "`git-ls-files --stage xfoo3`" in
50 + 120000" "*xfoo3) echo ok;;
51 + *) echo fail; git-ls-files --stage xfoo3; (exit 1);;
52 esac'
53
54 test_done