Merge branch 'jk/maint-add-ignored-dir' into maint
* jk/maint-add-ignored-dir: tests for "git add ignored-dir/file" without -f dir: fix COLLECT_IGNORED on excluded prefixes t0050: mark non-working test as suchmaint
						commit
						bcbbe4f9d9
					
				
							
								
								
									
										20
									
								
								dir.c
								
								
								
								
							
							
						
						
									
										20
									
								
								dir.c
								
								
								
								
							|  | @ -594,13 +594,29 @@ static int simplify_away(const char *path, int pathlen, const struct path_simpli | |||
| 	return 0; | ||||
| } | ||||
|  | ||||
| static int in_pathspec(const char *path, int len, const struct path_simplify *simplify) | ||||
| /* | ||||
|  * This function tells us whether an excluded path matches a | ||||
|  * list of "interesting" pathspecs. That is, whether a path matched | ||||
|  * by any of the pathspecs could possibly be ignored by excluding | ||||
|  * the specified path. This can happen if: | ||||
|  * | ||||
|  *   1. the path is mentioned explicitly in the pathspec | ||||
|  * | ||||
|  *   2. the path is a directory prefix of some element in the | ||||
|  *      pathspec | ||||
|  */ | ||||
| static int exclude_matches_pathspec(const char *path, int len, | ||||
| 		const struct path_simplify *simplify) | ||||
| { | ||||
| 	if (simplify) { | ||||
| 		for (; simplify->path; simplify++) { | ||||
| 			if (len == simplify->len | ||||
| 			    && !memcmp(path, simplify->path, len)) | ||||
| 				return 1; | ||||
| 			if (len < simplify->len | ||||
| 			    && simplify->path[len] == '/' | ||||
| 			    && !memcmp(path, simplify->path, len)) | ||||
| 				return 1; | ||||
| 		} | ||||
| 	} | ||||
| 	return 0; | ||||
|  | @ -678,7 +694,7 @@ static enum path_treatment treat_one_path(struct dir_struct *dir, | |||
| { | ||||
| 	int exclude = excluded(dir, path, &dtype); | ||||
| 	if (exclude && (dir->flags & DIR_COLLECT_IGNORED) | ||||
| 	    && in_pathspec(path, *len, simplify)) | ||||
| 	    && exclude_matches_pathspec(path, *len, simplify)) | ||||
| 		dir_add_ignored(dir, path, *len); | ||||
|  | ||||
| 	/* | ||||
|  |  | |||
|  | @ -108,13 +108,17 @@ $test_case 'merge (case change)' ' | |||
|  | ||||
| ' | ||||
|  | ||||
| $test_case 'add (with different case)' ' | ||||
|  | ||||
|  | ||||
| test_expect_failure 'add (with different case)' ' | ||||
|  | ||||
| 	git reset --hard initial && | ||||
| 	rm camelcase && | ||||
| 	echo 1 >CamelCase && | ||||
| 	git add CamelCase && | ||||
| 	test $(git ls-files | grep -i camelcase | wc -l) = 1 | ||||
| 	camel=$(git ls-files | grep -i camelcase) && | ||||
| 	test $(echo "$camel" | wc -l) = 1 && | ||||
| 	test "z$(git cat-file blob :$camel)" = z1 | ||||
|  | ||||
| ' | ||||
|  | ||||
|  |  | |||
|  | @ -0,0 +1,79 @@ | |||
| #!/bin/sh | ||||
|  | ||||
| test_description='giving ignored paths to git add' | ||||
|  | ||||
| . ./test-lib.sh | ||||
|  | ||||
| test_expect_success setup ' | ||||
| 	mkdir sub dir dir/sub && | ||||
| 	echo sub >.gitignore && | ||||
| 	echo ign >>.gitignore && | ||||
| 	for p in . sub dir dir/sub | ||||
| 	do | ||||
| 		>"$p/ign" && | ||||
| 		>"$p/file" || exit 1 | ||||
| 	done | ||||
| ' | ||||
|  | ||||
| for i in file dir/file dir 'd*' | ||||
| do | ||||
| 	test_expect_success "no complaints for unignored $i" ' | ||||
| 		rm -f .git/index && | ||||
| 		git add "$i" && | ||||
| 		git ls-files "$i" >out && | ||||
| 		test -s out | ||||
| 	' | ||||
| done | ||||
|  | ||||
| for i in ign dir/ign dir/sub dir/sub/*ign sub/file sub sub/* | ||||
| do | ||||
| 	test_expect_success "complaints for ignored $i" ' | ||||
| 		rm -f .git/index && | ||||
| 		test_must_fail git add "$i" 2>err && | ||||
| 		git ls-files "$i" >out && | ||||
| 		! test -s out && | ||||
| 		grep -e "Use -f if" err && | ||||
| 		cat err | ||||
| 	' | ||||
|  | ||||
| 	test_expect_success "complaints for ignored $i with unignored file" ' | ||||
| 		rm -f .git/index && | ||||
| 		test_must_fail git add "$i" file 2>err && | ||||
| 		git ls-files "$i" >out && | ||||
| 		! test -s out && | ||||
| 		grep -e "Use -f if" err && | ||||
| 		cat err | ||||
| 	' | ||||
| done | ||||
|  | ||||
| for i in sub sub/* | ||||
| do | ||||
| 	test_expect_success "complaints for ignored $i in dir" ' | ||||
| 		rm -f .git/index && | ||||
| 		( | ||||
| 			cd dir && | ||||
| 			test_must_fail git add "$i" 2>err && | ||||
| 			git ls-files "$i" >out && | ||||
| 			! test -s out && | ||||
| 			grep -e "Use -f if" err && | ||||
| 			cat err | ||||
| 		) | ||||
| 	' | ||||
| done | ||||
|  | ||||
| for i in ign file | ||||
| do | ||||
| 	test_expect_success "complaints for ignored $i in sub" ' | ||||
| 		rm -f .git/index && | ||||
| 		( | ||||
| 			cd sub && | ||||
| 			test_must_fail git add "$i" 2>err && | ||||
| 			git ls-files "$i" >out && | ||||
| 			! test -s out && | ||||
| 			grep -e "Use -f if" err && | ||||
| 			cat err | ||||
| 		) | ||||
| 	' | ||||
| done | ||||
|  | ||||
| test_done | ||||
		Loading…
	
		Reference in New Issue
	
	 Junio C Hamano
						Junio C Hamano