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

Re: [RFC] GIT_WORK_TREE

From
MLMatthias Lederhofer <matled@gmx.net>
Date
Jun 3, 2007, 14:48 UTC
Message-ID
<20070603144816.GE20061@moooo.ath.cx>
In-Reply-To
<20070603144401.GA9518@moooo.ath.cx>
Up to now to check for a working tree this was used:
	!is_bare && !inside_git_dir
(the check for bare is redundant because is_inside_git_dir
returned already 1 for bare repositories).
Now the check is:
	inside_work_tree && !inside_git_dir
Signed-off-by: Matthias Lederhofer <matled@gmx.net>
---
 builtin-ls-files.c |    2 +-
 git-sh-setup.sh    |    2 +-
 git-svn.perl       |    2 +-
 git.c              |   20 ++++++++++----------
 setup.c            |    2 +-
 5 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/builtin-ls-files.c b/builtin-ls-files.c
index f7c066b..48a3135 100644
--- a/builtin-ls-files.c
+++ b/builtin-ls-files.c
@@ -470,7 +470,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
 	}
 
 	if (require_work_tree &&
-			(is_bare_repository() || is_inside_git_dir()))
+			(!is_inside_work_tree() || is_inside_git_dir()))
 		die("This operation must be run in a work tree");
 
 	pathspec = get_pathspec(prefix, argv + i);
diff --git a/git-sh-setup.sh b/git-sh-setup.sh
index 9ac657a..0de49e8 100755
--- a/git-sh-setup.sh
+++ b/git-sh-setup.sh
@@ -44,7 +44,7 @@ cd_to_toplevel () {
 }
 
 require_work_tree () {
-	test $(is_bare_repository) = false &&
+	test $(git-rev-parse --is-inside-work-tree) = true &&
 	test $(git-rev-parse --is-inside-git-dir) = false ||
 	die "fatal: $0 cannot be used without a working tree."
 }
diff --git a/git-svn.perl b/git-svn.perl
index e3a5cbb..886b898 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -594,7 +594,7 @@ sub post_fetch_checkout {
 	my $index = $ENV{GIT_INDEX_FILE} || "$ENV{GIT_DIR}/index";
 	return if -f $index;
 
-	return if command_oneline(qw/rev-parse --is-bare-repository/) eq 'true';
+	return if command_oneline(qw/rev-parse --is-inside-work-tree/) eq 'false';
 	return if command_oneline(qw/rev-parse --is-inside-git-dir/) eq 'true';
 	command_noisy(qw/read-tree -m -u -v HEAD HEAD/);
 	print STDERR "Checked out HEAD:\n  ",
diff --git a/git.c b/git.c
index 05a391b..cd3910a 100644
--- a/git.c
+++ b/git.c
@@ -224,7 +224,7 @@ const char git_version_string[] = GIT_VERSION;
  * require working tree to be present -- anything uses this needs
  * RUN_SETUP for reading from the configuration file.
  */
-#define NOT_BARE 	(1<<2)
+#define NEED_WORK_TREE	(1<<2)
 
 static void handle_internal_command(int argc, const char **argv, char **envp)
 {
@@ -234,7 +234,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
 		int (*fn)(int, const char **, const char *);
 		int option;
 	} commands[] = {
-		{ "add", cmd_add, RUN_SETUP | NOT_BARE },
+		{ "add", cmd_add, RUN_SETUP | NEED_WORK_TREE },
 		{ "annotate", cmd_annotate, RUN_SETUP | USE_PAGER },
 		{ "apply", cmd_apply },
 		{ "archive", cmd_archive },
@@ -244,9 +244,9 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
 		{ "cat-file", cmd_cat_file, RUN_SETUP },
 		{ "checkout-index", cmd_checkout_index, RUN_SETUP },
 		{ "check-ref-format", cmd_check_ref_format },
-		{ "check-attr", cmd_check_attr, RUN_SETUP | NOT_BARE },
+		{ "check-attr", cmd_check_attr, RUN_SETUP | NEED_WORK_TREE },
 		{ "cherry", cmd_cherry, RUN_SETUP },
-		{ "cherry-pick", cmd_cherry_pick, RUN_SETUP | NOT_BARE },
+		{ "cherry-pick", cmd_cherry_pick, RUN_SETUP | NEED_WORK_TREE },
 		{ "commit-tree", cmd_commit_tree, RUN_SETUP },
 		{ "config", cmd_config },
 		{ "count-objects", cmd_count_objects, RUN_SETUP },
@@ -274,7 +274,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
 		{ "mailsplit", cmd_mailsplit },
 		{ "merge-base", cmd_merge_base, RUN_SETUP },
 		{ "merge-file", cmd_merge_file },
-		{ "mv", cmd_mv, RUN_SETUP | NOT_BARE },
+		{ "mv", cmd_mv, RUN_SETUP | NEED_WORK_TREE },
 		{ "name-rev", cmd_name_rev, RUN_SETUP },
 		{ "pack-objects", cmd_pack_objects, RUN_SETUP },
 		{ "pickaxe", cmd_blame, RUN_SETUP | USE_PAGER },
@@ -287,9 +287,9 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
 		{ "rerere", cmd_rerere, RUN_SETUP },
 		{ "rev-list", cmd_rev_list, RUN_SETUP },
 		{ "rev-parse", cmd_rev_parse, RUN_SETUP },
-		{ "revert", cmd_revert, RUN_SETUP | NOT_BARE },
-		{ "rm", cmd_rm, RUN_SETUP | NOT_BARE },
-		{ "runstatus", cmd_runstatus, RUN_SETUP | NOT_BARE },
+		{ "revert", cmd_revert, RUN_SETUP | NEED_WORK_TREE },
+		{ "rm", cmd_rm, RUN_SETUP | NEED_WORK_TREE },
+		{ "runstatus", cmd_runstatus, RUN_SETUP | NEED_WORK_TREE },
 		{ "shortlog", cmd_shortlog, RUN_SETUP | USE_PAGER },
 		{ "show-branch", cmd_show_branch, RUN_SETUP },
 		{ "show", cmd_show, RUN_SETUP | USE_PAGER },
@@ -326,8 +326,8 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
 			prefix = setup_git_directory();
 		if (p->option & USE_PAGER)
 			setup_pager();
-		if ((p->option & NOT_BARE) &&
-				(is_bare_repository() || is_inside_git_dir()))
+		if ((p->option & NEED_WORK_TREE) &&
+				(!is_inside_work_tree() || is_inside_git_dir()))
 			die("%s must be run in a work tree", cmd);
 		trace_argv_printf(argv, argc, "trace: built-in: git");
 
diff --git a/setup.c b/setup.c
index 4856232..ddf4013 100644
--- a/setup.c
+++ b/setup.c
@@ -95,7 +95,7 @@ void verify_non_filename(const char *prefix, const char *arg)
 	const char *name;
 	struct stat st;
 
-	if (is_inside_git_dir())
+	if (!is_inside_work_tree() || is_inside_git_dir())
 		return;
 	if (*arg == '-')
 		return; /* flag */
-- 
1.5.0.3
Previous: Matthias LederhoferNext: Matthias Lederhofer
Message 13 of 22 in “[RFC] GIT_WORK_TREE”
  1. Matthias LederhoferJun 3, 2007
  2. 1/7 rev-parse: document --is-inside-git-dirMatthias Lederhofer, Jun 3, 2007
  3. 2/7 rev-parse: introduce --is-bare-repositoryMatthias Lederhofer, Jun 3, 2007
  4. 3/7 test git rev-parseMatthias Lederhofer, Jun 3, 2007
  5. 3/7 test git rev-parseMatthias Lederhofer, Jun 6, 2007
  6. 4/7 introduce GIT_WORK_TREE to specify the work treeMatthias Lederhofer, Jun 3, 2007
  7. Junio C HamanoJun 5, 2007
  8. filter-branch: always export GIT_DIR if it is setMatthias Lederhofer, Jun 5, 2007
  9. Johannes SchindelinJun 5, 2007
  10. Junio C HamanoJun 5, 2007
  11. filter-branch: always export GIT_DIR if it is setMatthias Lederhofer, Jun 6, 2007
  12. 4/7 introduce GIT_WORK_TREE to specify the work treeMatthias Lederhofer, Jun 6, 2007
  13. Matthias LederhoferJun 3, 2007
  14. Matthias LederhoferJun 3, 2007
  15. 6/7 extend rev-parse test for --is-inside-work-treeMatthias Lederhofer, Jun 3, 2007
  16. 6/7 extend rev-parse test for --is-inside-work-treeMatthias Lederhofer, Jun 6, 2007
  17. 7/7 test GIT_WORK_TREEMatthias Lederhofer, Jun 3, 2007
  18. 7/7 test GIT_WORK_TREEMatthias Lederhofer, Jun 6, 2007
  19. SergioJun 3, 2007
  20. Matthias LederhoferJun 3, 2007
  21. SergioJun 3, 2007
  22. setup_git_directory: fix segfault if repository is found in cwdMatthias Lederhofer, Jun 6, 2007

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.