Commit Diff


commit - 01a217a7bc691f0ebc7c9f5cc36059b5a9077ee2
commit + e012cf94a2ba4c30e3b5842aacd715b5f5e420f9
blob - 2dcb63267e36d94e9cdff8cf736147e2ded5f199
blob + 518e73d32dd54163f0c184e0373f963ae473079b
--- got/got.1
+++ got/got.1
@@ -117,6 +117,9 @@ The
 .Ar pattern
 follows the globbing rules documented in
 .Xr glob 7 .
+Ignore patterns which end with a slash,
+.Dq / ,
+will only match directories.
 .It Fl m Ar message
 Use the specified log message when creating the new commit.
 Without the
blob - a45339114895d53cb16168cd6dc55379e43f94d7
blob + 223a1aad55da449f067a61b7dd4dd3d7be9017c2
--- lib/repository.c
+++ lib/repository.c
@@ -2148,9 +2148,27 @@ write_tree(struct got_object_id **new_tree_id, const c
 		if (strcmp(de->d_name, ".") == 0 ||
 		    strcmp(de->d_name, "..") == 0)
 			continue;
+
+		err = got_path_dirent_type(&type, path_dir, de);
+		if (err)
+			goto done;
 
 		TAILQ_FOREACH(pe, ignores, entry) {
-			if (fnmatch(pe->path, de->d_name, 0) == 0) {
+			if (type == DT_DIR && pe->path_len > 0 &&
+			    pe->path[pe->path_len - 1] == '/') {
+				char stripped[PATH_MAX];
+
+				if (strlcpy(stripped, pe->path,
+				    sizeof(stripped)) >= sizeof(stripped)) {
+					err = got_error(GOT_ERR_NO_SPACE);
+					goto done;
+				}
+				got_path_strip_trailing_slashes(stripped);
+				if (fnmatch(stripped, de->d_name, 0) == 0) {
+					ignore = 1;
+					break;
+				}
+			} else if (fnmatch(pe->path, de->d_name, 0) == 0) {
 				ignore = 1;
 				break;
 			}
@@ -2158,10 +2176,6 @@ write_tree(struct got_object_id **new_tree_id, const c
 		if (ignore)
 			continue;
 
-		err = got_path_dirent_type(&type, path_dir, de);
-		if (err)
-			goto done;
-
 		if (type == DT_DIR) {
 			err = import_subdir(&new_te, de, path_dir,
 			    ignores, repo, progress_cb, progress_arg);
blob - 9ce21cacfc1fea14fa9289ed4180e0640cfdffdf
blob + 28fd8607f9a6b87c382e3669204da90a4ec3c6ac
--- regress/cmdline/import.sh
+++ regress/cmdline/import.sh
@@ -374,7 +374,7 @@ test_import_ignores() {
 	mkdir $testroot/tree
 	make_test_tree $testroot/tree
 
-	got import -I alpha -I '*lta*' -I '*silon' \
+	got import -I alpha -I 'beta/' -I '*lta*' -I '*silon/' \
 		-m 'init' -r $testroot/repo $testroot/tree > $testroot/stdout
 	ret=$?
 	if [ $ret -ne 0 ]; then