git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 9/9] checkout: add new options to support narrow checkout

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Aug 15, 2008, 14:27 UTC
Message-ID
<20080815142730.GA10781@laptop>
In-Reply-To
<cover.1218807249.git.pclouds@gmail.com>
These options include:
 --full: return to full checkout (default)
 --path: narrow checkout to some areas according to given spec
 --add-path/--remove-path: adjust current narrow checkout
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin-checkout.c |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)
diff --git a/builtin-checkout.c b/builtin-checkout.c
index e95eab9..f2254c6 100644
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
@@ -160,6 +160,11 @@ struct checkout_opts {
 	char *new_branch;
 	int new_branch_log;
 	enum branch_track track;
+
+	char *new_path;
+	char *add_path;
+	char *remove_path;
+	int no_narrow_checkout;
 };
 
 static int reset_tree(struct tree *tree, struct checkout_opts *o, int worktree)
@@ -255,6 +260,23 @@ static int merge_working_tree(struct checkout_opts *opts,
 		tree = parse_tree_indirect(new->commit->object.sha1);
 		init_tree_desc(&trees[1], tree->buffer, tree->size);
 
+		if (opts->no_narrow_checkout) {
+			/* leave narrow_spec NULL */
+			topts.new_narrow_path = 1;
+		}
+		else if (opts->new_path) {
+			topts.narrow_spec = opts->new_path;
+			topts.new_narrow_path = 1;
+		}
+		else if (opts->add_path) {
+			topts.narrow_spec = opts->add_path;
+			topts.add_narrow_path = 1;
+		}
+		else if (opts->remove_path) {
+			topts.narrow_spec = opts->remove_path;
+			topts.remove_narrow_path = 1;
+		}
+
 		ret = unpack_trees(2, trees, &topts);
 		if (ret == -1) {
 			/*
@@ -428,6 +450,10 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
 			BRANCH_TRACK_EXPLICIT),
 		OPT_BOOLEAN('f', NULL, &opts.force, "force"),
 		OPT_BOOLEAN('m', NULL, &opts.merge, "merge"),
+		OPT_BOOLEAN(0, "full", &opts.no_narrow_checkout, "quit sparse checkout"),
+		OPT_STRING(0, "path", &opts.new_path, "prefixes", "apply new narrow checkout path"),
+		OPT_STRING(0, "add-path", &opts.add_path, "prefixes", "add more checkout area"),
+		OPT_STRING(0, "remove-path", &opts.remove_path, "prefixes", "narrow checkout area"),
 		OPT_END(),
 	};
 	int has_dash_dash;
@@ -460,6 +486,18 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
 	if (opts.track == -1)
 		opts.track = git_branch_track;
 
+	if (((opts.no_narrow_checkout ? 1 : 0) +
+	     (opts.new_path ? 1 : 0) +
+	     (opts.add_path ? 1 : 0) +
+	     (opts.remove_path ? 1 : 0)) > 1)
+		die("git checkout: --path, --full, --add-path and --remove-path are incompatible");
+
+	if (opts.new_branch && (opts.add_path || opts.remove_path))
+		die("git checkout: --add-path and --remove-path should only be used on current branch");
+
+	if (opts.new_branch && opts.no_narrow_checkout)
+		die("git checkout: switching branch with --full does not make sense");
+
 	if (opts.force && opts.merge)
 		die("git checkout: -f and -m are incompatible");
 
@@ -550,6 +588,9 @@ no_reference:
 			}
 		}
 
+		if (opts.no_narrow_checkout || opts.new_path || opts.add_path || opts.remove_path)
+			die("git checkout: updating paths is incompatible with setting sparse checkout");
+
 		return checkout_paths(source_tree, pathspec);
 	}
 
-- 
1.6.0.rc3.250.g8dd0
Previous: Nguyễn Thái Ngọc Duy
Message 9 of 9 in “Introduce CE_NO_CHECKOUT bit”
  1. 1/9 Introduce CE_NO_CHECKOUT bitNguyễn Thái Ngọc Duy, Aug 15, 2008
  2. 2/9 update-index: add --checkout/--no-checkout options to update CE_NO_CHECKOUT bitNguyễn Thái Ngọc Duy, Aug 15, 2008
  3. 3/9 ls-files: add --checkout option to show checked out filesNguyễn Thái Ngọc Duy, Aug 15, 2008
  4. 4/9 Prevent diff machinery from examining worktree outside narrow checkoutNguyễn Thái Ngọc Duy, Aug 15, 2008
  5. 5/9 Clear CE_NO_CHECKOUT on checked out entries.Nguyễn Thái Ngọc Duy, Aug 15, 2008
  6. 6/9 Add support for narrow checkout in unpack_trees()Nguyễn Thái Ngọc Duy, Aug 15, 2008
  7. 7/9 ls-files: add --narrow-match=spec option to test narrow matchingNguyễn Thái Ngọc Duy, Aug 15, 2008
  8. 8/9 clone: support narrow checkout with --path optionNguyễn Thái Ngọc Duy, Aug 15, 2008
  9. 9/9 checkout: add new options to support narrow checkoutNguyễn Thái Ngọc Duy, Aug 15, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.