Merge branch 'mt/do-not-use-scld-in-working-tree'
"git apply" adjusted the permission bits of working-tree files and directories according core.sharedRepository setting by mistake and for a long time, which has been corrected. * mt/do-not-use-scld-in-working-tree: apply: don't use core.sharedRepository to create working tree filesmaint
						commit
						9b3b4adb3f
					
				
							
								
								
									
										2
									
								
								apply.c
								
								
								
								
							
							
						
						
									
										2
									
								
								apply.c
								
								
								
								
							|  | @ -4409,7 +4409,7 @@ static int create_one_file(struct apply_state *state, | ||||||
| 		return 0; | 		return 0; | ||||||
|  |  | ||||||
| 	if (errno == ENOENT) { | 	if (errno == ENOENT) { | ||||||
| 		if (safe_create_leading_directories(path)) | 		if (safe_create_leading_directories_no_share(path)) | ||||||
| 			return 0; | 			return 0; | ||||||
| 		res = try_create_file(state, path, mode, buf, size); | 		res = try_create_file(state, path, mode, buf, size); | ||||||
| 		if (res < 0) | 		if (res < 0) | ||||||
|  |  | ||||||
							
								
								
									
										7
									
								
								cache.h
								
								
								
								
							
							
						
						
									
										7
									
								
								cache.h
								
								
								
								
							|  | @ -1255,7 +1255,11 @@ int adjust_shared_perm(const char *path); | ||||||
|  * safe_create_leading_directories() temporarily changes path while it |  * safe_create_leading_directories() temporarily changes path while it | ||||||
|  * is working but restores it before returning. |  * is working but restores it before returning. | ||||||
|  * safe_create_leading_directories_const() doesn't modify path, even |  * safe_create_leading_directories_const() doesn't modify path, even | ||||||
|  * temporarily. |  * temporarily. Both these variants adjust the permissions of the | ||||||
|  |  * created directories to honor core.sharedRepository, so they are best | ||||||
|  |  * suited for files inside the git dir. For working tree files, use | ||||||
|  |  * safe_create_leading_directories_no_share() instead, as it ignores | ||||||
|  |  * the core.sharedRepository setting. | ||||||
|  */ |  */ | ||||||
| enum scld_error { | enum scld_error { | ||||||
| 	SCLD_OK = 0, | 	SCLD_OK = 0, | ||||||
|  | @ -1266,6 +1270,7 @@ enum scld_error { | ||||||
| }; | }; | ||||||
| enum scld_error safe_create_leading_directories(char *path); | enum scld_error safe_create_leading_directories(char *path); | ||||||
| enum scld_error safe_create_leading_directories_const(const char *path); | enum scld_error safe_create_leading_directories_const(const char *path); | ||||||
|  | enum scld_error safe_create_leading_directories_no_share(char *path); | ||||||
|  |  | ||||||
| /* | /* | ||||||
|  * Callback function for raceproof_create_file(). This function is |  * Callback function for raceproof_create_file(). This function is | ||||||
|  |  | ||||||
							
								
								
									
										14
									
								
								sha1-file.c
								
								
								
								
							
							
						
						
									
										14
									
								
								sha1-file.c
								
								
								
								
							|  | @ -291,7 +291,7 @@ int mkdir_in_gitdir(const char *path) | ||||||
| 	return adjust_shared_perm(path); | 	return adjust_shared_perm(path); | ||||||
| } | } | ||||||
|  |  | ||||||
| enum scld_error safe_create_leading_directories(char *path) | static enum scld_error safe_create_leading_directories_1(char *path, int share) | ||||||
| { | { | ||||||
| 	char *next_component = path + offset_1st_component(path); | 	char *next_component = path + offset_1st_component(path); | ||||||
| 	enum scld_error ret = SCLD_OK; | 	enum scld_error ret = SCLD_OK; | ||||||
|  | @ -337,7 +337,7 @@ enum scld_error safe_create_leading_directories(char *path) | ||||||
| 				ret = SCLD_VANISHED; | 				ret = SCLD_VANISHED; | ||||||
| 			else | 			else | ||||||
| 				ret = SCLD_FAILED; | 				ret = SCLD_FAILED; | ||||||
| 		} else if (adjust_shared_perm(path)) { | 		} else if (share && adjust_shared_perm(path)) { | ||||||
| 			ret = SCLD_PERMS; | 			ret = SCLD_PERMS; | ||||||
| 		} | 		} | ||||||
| 		*slash = slash_character; | 		*slash = slash_character; | ||||||
|  | @ -345,6 +345,16 @@ enum scld_error safe_create_leading_directories(char *path) | ||||||
| 	return ret; | 	return ret; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | enum scld_error safe_create_leading_directories(char *path) | ||||||
|  | { | ||||||
|  | 	return safe_create_leading_directories_1(path, 1); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | enum scld_error safe_create_leading_directories_no_share(char *path) | ||||||
|  | { | ||||||
|  | 	return safe_create_leading_directories_1(path, 0); | ||||||
|  | } | ||||||
|  |  | ||||||
| enum scld_error safe_create_leading_directories_const(const char *path) | enum scld_error safe_create_leading_directories_const(const char *path) | ||||||
| { | { | ||||||
| 	int save_errno; | 	int save_errno; | ||||||
|  |  | ||||||
|  | @ -73,4 +73,30 @@ test_expect_success FILEMODE 'bogus mode is rejected' ' | ||||||
| 	test_i18ngrep "invalid mode" err | 	test_i18ngrep "invalid mode" err | ||||||
| ' | ' | ||||||
|  |  | ||||||
|  | test_expect_success POSIXPERM 'do not use core.sharedRepository for working tree files' ' | ||||||
|  | 	git reset --hard && | ||||||
|  | 	test_config core.sharedRepository 0666 && | ||||||
|  | 	( | ||||||
|  | 		# Remove a default ACL if possible. | ||||||
|  | 		(setfacl -k newdir 2>/dev/null || true) && | ||||||
|  | 		umask 0077 && | ||||||
|  |  | ||||||
|  | 		# Test both files (f1) and leading dirs (d) | ||||||
|  | 		mkdir d && | ||||||
|  | 		touch f1 d/f2 && | ||||||
|  | 		git add f1 d/f2 && | ||||||
|  | 		git diff --staged >patch-f1-and-f2.txt && | ||||||
|  |  | ||||||
|  | 		rm -rf d f1 && | ||||||
|  | 		git apply patch-f1-and-f2.txt && | ||||||
|  |  | ||||||
|  | 		echo "-rw-------" >f1_mode.expected && | ||||||
|  | 		echo "drwx------" >d_mode.expected && | ||||||
|  | 		test_modebits f1 >f1_mode.actual && | ||||||
|  | 		test_modebits d >d_mode.actual && | ||||||
|  | 		test_cmp f1_mode.expected f1_mode.actual && | ||||||
|  | 		test_cmp d_mode.expected d_mode.actual | ||||||
|  | 	) | ||||||
|  | ' | ||||||
|  |  | ||||||
| test_done | test_done | ||||||
|  |  | ||||||
|  | @ -367,9 +367,9 @@ test_chmod () { | ||||||
| 	git update-index --add "--chmod=$@" | 	git update-index --add "--chmod=$@" | ||||||
| } | } | ||||||
|  |  | ||||||
| # Get the modebits from a file. | # Get the modebits from a file or directory. | ||||||
| test_modebits () { | test_modebits () { | ||||||
| 	ls -l "$1" | sed -e 's|^\(..........\).*|\1|' | 	ls -ld "$1" | sed -e 's|^\(..........\).*|\1|' | ||||||
| } | } | ||||||
|  |  | ||||||
| # Unset a configuration variable, but don't fail if it doesn't exist. | # Unset a configuration variable, but don't fail if it doesn't exist. | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Junio C Hamano
						Junio C Hamano