Commits

Anonymous committed 2bbaaed

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>

Comments (0)

Files changed (3)

builtin-update-index.c

 	ce->ce_mode = create_ce_mode(st.st_mode);
 	if (!trust_executable_bit) {
 		/* If there is an existing entry, pick the mode bits
-		 * from it, otherwise force to 644.
+		 * from it, otherwise assume unexecutable.
 		 */
 		int pos = cache_name_pos(path, namelen);
 		if (0 <= pos)
 			ce->ce_mode = active_cache[pos]->ce_mode;
-		else
-			ce->ce_mode = create_ce_mode(S_IFREG | 0644);
+		else if (S_ISREG(st.st_mode))
+			ce->ce_mode = create_ce_mode(S_IFREG | 0666);
 	}
 
 	if (index_path(ce->sha1, path, &st, !info_only))
 	ce->ce_mode = create_ce_mode(st.st_mode);
 	if (!trust_executable_bit) {
 		/* If there is an existing entry, pick the mode bits
-		 * from it, otherwise force to 644.
+		 * from it, otherwise assume unexecutable.
 		 */
 		int pos = cache_name_pos(path, namelen);
 		if (pos >= 0)
 			ce->ce_mode = active_cache[pos]->ce_mode;
-		else
-			ce->ce_mode = create_ce_mode(S_IFREG | 0644);
+		else if (S_ISREG(st.st_mode))
+			ce->ce_mode = create_ce_mode(S_IFREG | 0666);
 	}
 
 	if (index_path(ce->sha1, path, &st, 1))
 	 git-add xfoo1 &&
 	 case "`git-ls-files --stage xfoo1`" in
 	 100644" "*xfoo1) echo ok;;
-	 *) echo fail; git-ls-files --stage xfoo1; exit 1;;
+	 *) echo fail; git-ls-files --stage xfoo1; (exit 1);;
 	 esac'
 
 test_expect_success \
 	 git-update-index --add xfoo2 &&
 	 case "`git-ls-files --stage xfoo2`" in
 	 100644" "*xfoo2) echo ok;;
-	 *) echo fail; git-ls-files --stage xfoo2; exit 1;;
+	 *) echo fail; git-ls-files --stage xfoo2; (exit 1);;
+	 esac'
+
+test_expect_success \
+	'git-update-index --add: Test that executable bit is not used...' \
+	'git repo-config core.filemode 0 &&
+	 ln -s xfoo2 xfoo3 &&
+	 git-update-index --add xfoo3 &&
+	 case "`git-ls-files --stage xfoo3`" in
+	 120000" "*xfoo3) echo ok;;
+	 *) echo fail; git-ls-files --stage xfoo3; (exit 1);;
 	 esac'
 
 test_done
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.