Commit Diff


commit - b0ac38bb75347d8463628704f64f5ff0349272a6
commit + 49351f3bf4ab5a99f1b0653e176e01ab5988acde
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 - 9b6bfeb03479b844dcb5ea253742cfce88a0b45f
blob + 5d8a9b15a65274f5aca4f4b684451904e68f0615
--- lib/repository.c
+++ lib/repository.c
@@ -2152,9 +2152,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;
 			}
@@ -2162,10 +2180,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