"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Tracey Emery <tracey@traceyemery.net>
Subject:
Re: got add recursion ignore ignores
To:
gameoftrees@openbsd.org
Date:
Thu, 5 Dec 2019 10:44:18 -0700

Download raw body.

Thread
Now with a conditional test for -R option and correcting usage_add.

-- 

Tracey Emery

diff 22694bb8ff1cf412bbdfc251e2dce27baca160b6 /home/basepr1me/Documents/got/got
blob - 044aadf30b3ae798d851660a58e8dddd57a6b746
file + TODO
--- TODO
+++ TODO
@@ -11,7 +11,6 @@ lib:
 
 got:
 - 'histedit -c' prompts for log message even if there are no changes to commit
-- recursive addition: got add -R
 - recursive removal: got rm -R
 
 tog:
blob - 57af02b4edfdbb7d0e6764d05c516a435f823c56
file + got/got.1
--- got/got.1
+++ got/got.1
@@ -625,7 +625,7 @@ If a tag must be deleted, the
 command may be used to delete a tag's reference.
 This should only be done if the tag has not already been copied to
 another repository.
-.It Cm add Oo Fl R Oc Ar path ...
+.It Cm add Oo Fl R Oc Oo Fl I Oc Ar path ...
 Schedule unversioned files in a work tree for addition to the
 repository in the next commit.
 .Pp
@@ -640,6 +640,10 @@ If this option is not specified,
 will refuse to run if a specified
 .Ar path
 is a directory.
+.It Fl I
+With -R, add files even if they match a
+.Cm got status
+ignore pattern.
 .El
 .It Cm remove Ar file-path ...
 Remove versioned files from a work tree and schedule them for deletion
blob - 756eaa2ea3216dabe5aaf7080a2c652fdbfd0f74
file + got/got.c
--- got/got.c
+++ got/got.c
@@ -4146,7 +4146,8 @@ done:
 __dead static void
 usage_add(void)
 {
-	fprintf(stderr, "usage: %s add file-path ...\n", getprogname());
+	fprintf(stderr, "usage: %s add [-R] [-I] file-path ...\n",
+	    getprogname());
 	exit(1);
 }
 
@@ -4168,12 +4169,15 @@ cmd_add(int argc, char *argv[])
 	char *cwd = NULL;
 	struct got_pathlist_head paths;
 	struct got_pathlist_entry *pe;
-	int ch, can_recurse = 0;
+	int ch, can_recurse = 0, no_ignores = 0;
 
 	TAILQ_INIT(&paths);
 
-	while ((ch = getopt(argc, argv, "R")) != -1) {
+	while ((ch = getopt(argc, argv, "IR")) != -1) {
 		switch (ch) {
+		case 'I':
+			no_ignores = 1;
+			break;
 		case 'R':
 			can_recurse = 1;
 			break;
@@ -4218,6 +4222,13 @@ cmd_add(int argc, char *argv[])
 	if (error)
 		goto done;
 
+	if (!can_recurse && no_ignores) {
+		error = got_error_msg(GOT_ERR_BAD_PATH,
+		    "disregarding ignores requires -R option");
+			goto done;
+
+	}
+
 	if (!can_recurse) {
 		char *ondisk_path;
 		struct stat sb;
@@ -4246,8 +4257,9 @@ cmd_add(int argc, char *argv[])
 			}
 		}
 	}
+
 	error = got_worktree_schedule_add(worktree, &paths, add_progress,
-	    NULL, repo);
+	    NULL, repo, no_ignores);
 done:
 	if (repo)
 		got_repo_close(repo);
blob - a18fc5a59d6c2c165d6f449c5accb262eb450485
file + include/got_worktree.h
--- include/got_worktree.h
+++ include/got_worktree.h
@@ -159,7 +159,7 @@ const struct got_error *got_worktree_resolve_path(char
 /* Schedule files at on-disk paths for addition in the next commit. */
 const struct got_error *got_worktree_schedule_add(struct got_worktree *,
     struct got_pathlist_head *, got_worktree_checkout_cb, void *,
-    struct got_repository *);
+    struct got_repository *, int);
 
 /*
  * Remove files from disk and schedule them to be deleted in the next commit.
blob - c45a95888b5015de44ca323f6dd4759e19eb36f4
file + lib/got_lib_worktree.h
--- lib/got_lib_worktree.h
+++ lib/got_lib_worktree.h
@@ -33,6 +33,8 @@ struct got_worktree {
 	 * shared lock must be upgraded to an exclusive lock.
 	 */
 	int lockfd;
+	int flags;
+#define GOT_WORKTREE_NO_IGNORES 0x01
 };
 
 struct got_commitable {
blob - c56c307e7fad0d579e6eb3fa799150a8b8d31558
file + lib/worktree.c
--- lib/worktree.c
+++ lib/worktree.c
@@ -2670,11 +2670,13 @@ worktree_status(struct got_worktree *worktree, const c
 		arg.cancel_cb = cancel_cb;
 		arg.cancel_arg = cancel_arg;
 		TAILQ_INIT(&arg.ignores);
-		err = add_ignores(&arg.ignores, worktree->root_path, path,
-		    ".cvsignore");
-		if (err == NULL)
+		if (!(worktree->flags & GOT_WORKTREE_NO_IGNORES)) {
 			err = add_ignores(&arg.ignores, worktree->root_path,
-			    path, ".gitignore");
+			    path, ".cvsignore");
+			if (err == NULL)
+				err = add_ignores(&arg.ignores,
+				    worktree->root_path, path, ".gitignore");
+		}
 		if (err == NULL)
 			err = got_fileindex_diff_dir(fileindex, workdir,
 			    worktree->root_path, path, repo, &fdiff_cb, &arg);
@@ -2840,7 +2842,7 @@ const struct got_error *
 got_worktree_schedule_add(struct got_worktree *worktree,
     struct got_pathlist_head *paths,
     got_worktree_checkout_cb progress_cb, void *progress_arg,
-    struct got_repository *repo)
+    struct got_repository *repo, int no_ignores)
 {
 	struct got_fileindex *fileindex = NULL;
 	char *fileindex_path = NULL;
@@ -2861,6 +2863,9 @@ got_worktree_schedule_add(struct got_worktree *worktre
 	saa.progress_cb = progress_cb;
 	saa.progress_arg = progress_arg;
 	saa.repo = repo;
+
+	if (no_ignores)
+		worktree->flags |= GOT_WORKTREE_NO_IGNORES;
 
 	TAILQ_FOREACH(pe, paths, entry) {
 		char *ondisk_path;
blob - 9260016060fa594ef14a31a90e815737bb487ca1
file + regress/cmdline/add.sh
--- regress/cmdline/add.sh
+++ regress/cmdline/add.sh
@@ -163,12 +163,19 @@ function test_add_directory {
 
 	(cd $testroot/wt && got add . > $testroot/stdout 2> $testroot/stderr)
 	ret="$?"
-	if [ "$ret" == "0" ]; then
-		echo "got add command succeeded unexpectedly" >&2
-		test_done "$testroot" "1"
+	echo "got: adding directories requires -R option" \
+		> $testroot/stderr.expected
+	cmp -s $testroot/stderr.expected $testroot/stderr
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/stderr.expected $testroot/stderr
+		test_done "$testroot" "$ret"
 		return 1
 	fi
-	echo "got: adding directories requires -R option" \
+
+	(cd $testroot/wt && got add -I . > $testroot/stdout 2> $testroot/stderr)
+	ret="$?"
+	echo "got: disregarding ignores requires -R option" \
 		> $testroot/stderr.expected
 	cmp -s $testroot/stderr.expected $testroot/stderr
 	ret="$?"
@@ -187,11 +194,19 @@ function test_add_directory {
 		return 1
 	fi
 
-	(touch $testroot/wt/epsilon/zeta1 && touch $testroot/wt/epsilon/zeta2)
+	mkdir -p $testroot/wt/tree1
+	mkdir -p $testroot/wt/tree2
+	echo "tree1/**" > $testroot/wt/.gitignore
+	echo "tree2/**" >> $testroot/wt/.gitignore
+	echo -n > $testroot/wt/tree1/foo
+	echo -n > $testroot/wt/tree2/foo
+	echo -n > $testroot/wt/epsilon/zeta1
+	echo -n > $testroot/wt/epsilon/zeta2
 
 	(cd $testroot/wt && got add -R . > $testroot/stdout)
 
-	echo 'A  epsilon/zeta1' > $testroot/stdout.expected
+	echo 'A  .gitignore' > $testroot/stdout.expected
+	echo 'A  epsilon/zeta1' >> $testroot/stdout.expected
 	echo 'A  epsilon/zeta2' >> $testroot/stdout.expected
 
 	cmp -s $testroot/stdout.expected $testroot/stdout
@@ -202,13 +217,28 @@ function test_add_directory {
 		return 1
 	fi
 
-	echo "zeta" > $testroot/content.expected
-	cat $testroot/wt/epsilon/zeta > $testroot/content
+	(cd $testroot/wt && got add -RI tree1 > $testroot/stdout)
 
-	cmp -s $testroot/content.expected $testroot/content
+	echo 'A  tree1/foo' > $testroot/stdout.expected
+
+	cmp -s $testroot/stdout.expected $testroot/stdout
 	ret="$?"
 	if [ "$ret" != "0" ]; then
-		diff -u $testroot/content.expected $testroot/content
+		diff -u $testroot/stdout.expected $testroot/stdout
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	(cd $testroot/wt && got add tree2/foo > $testroot/stdout)
+
+	echo 'A  tree2/foo' > $testroot/stdout.expected
+
+	cmp -s $testroot/stdout.expected $testroot/stdout
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
+		test_done "$testroot" "$ret"
+		return 1
 	fi
 	test_done "$testroot" "$ret"
 }