Skip to content

Commit 2bbaaed

Browse files
author
Junio C Hamano
committed
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 <[email protected]>
1 parent 5d1faf8 commit 2bbaaed

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

builtin-update-index.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ static int add_file_to_cache(const char *path)
112112
ce->ce_mode = create_ce_mode(st.st_mode);
113113
if (!trust_executable_bit) {
114114
/* If there is an existing entry, pick the mode bits
115-
* from it, otherwise force to 644.
115+
* from it, otherwise assume unexecutable.
116116
*/
117117
int pos = cache_name_pos(path, namelen);
118118
if (0 <= pos)
119119
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);
122122
}
123123

124124
if (index_path(ce->sha1, path, &st, !info_only))

read-cache.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,13 +347,13 @@ int add_file_to_index(const char *path, int verbose)
347347
ce->ce_mode = create_ce_mode(st.st_mode);
348348
if (!trust_executable_bit) {
349349
/* If there is an existing entry, pick the mode bits
350-
* from it, otherwise force to 644.
350+
* from it, otherwise assume unexecutable.
351351
*/
352352
int pos = cache_name_pos(path, namelen);
353353
if (pos >= 0)
354354
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);
357357
}
358358

359359
if (index_path(ce->sha1, path, &st, 1))

t/t3700-add.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ test_expect_success \
2727
git-add xfoo1 &&
2828
case "`git-ls-files --stage xfoo1`" in
2929
100644" "*xfoo1) echo ok;;
30-
*) echo fail; git-ls-files --stage xfoo1; exit 1;;
30+
*) echo fail; git-ls-files --stage xfoo1; (exit 1);;
3131
esac'
3232

3333
test_expect_success \
@@ -38,7 +38,17 @@ test_expect_success \
3838
git-update-index --add xfoo2 &&
3939
case "`git-ls-files --stage xfoo2`" in
4040
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);;
4252
esac'
4353

4454
test_done

0 commit comments

Comments
 (0)