summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 98d47d4)
raw | patch | inline | side by side (parent: 98d47d4)
author | Johannes Schindelin <Johannes.Schindelin@gmx.de> | |
Tue, 23 Jan 2007 12:30:20 +0000 (13:30 +0100) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Mon, 5 Feb 2007 22:02:16 +0000 (14:02 -0800) |
This patch helps when you accidentally run something like git-clean
in the git directory instead of the work tree.
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
in the git directory instead of the work tree.
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
builtin-ls-files.c | patch | blob | history | |
builtin-rev-parse.c | patch | blob | history | |
git-sh-setup.sh | patch | blob | history | |
git.c | patch | blob | history |
diff --git a/builtin-ls-files.c b/builtin-ls-files.c
index 21c2a6e2d9b68c0c3bcfac824e85c7b392c72486..ac89eb2f770d3b8dbc35ee2c24d9d6c82b8fb6fe 100644 (file)
--- a/builtin-ls-files.c
+++ b/builtin-ls-files.c
int cmd_ls_files(int argc, const char **argv, const char *prefix)
{
int i;
- int exc_given = 0;
+ int exc_given = 0, require_work_tree = 0;
struct dir_struct dir;
memset(&dir, 0, sizeof(dir));
}
if (!strcmp(arg, "-m") || !strcmp(arg, "--modified")) {
show_modified = 1;
+ require_work_tree = 1;
continue;
}
if (!strcmp(arg, "-o") || !strcmp(arg, "--others")) {
show_others = 1;
+ require_work_tree = 1;
continue;
}
if (!strcmp(arg, "-i") || !strcmp(arg, "--ignored")) {
dir.show_ignored = 1;
+ require_work_tree = 1;
continue;
}
if (!strcmp(arg, "-s") || !strcmp(arg, "--stage")) {
}
if (!strcmp(arg, "-k") || !strcmp(arg, "--killed")) {
show_killed = 1;
+ require_work_tree = 1;
continue;
}
if (!strcmp(arg, "--directory")) {
break;
}
+ if (require_work_tree &&
+ (is_bare_repository() || is_inside_git_dir()))
+ die("This operation must be run in a work tree");
+
pathspec = get_pathspec(prefix, argv + i);
/* Verify that the pathspec matches the prefix */
diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c
index 3b716fba133ae2f0375ef73d6a50a4d93112b5e4..d53deaa3691c7b57e215f3f33c44881c4f397527 100644 (file)
--- a/builtin-rev-parse.c
+++ b/builtin-rev-parse.c
printf("%s/.git\n", cwd);
continue;
}
+ if (!strcmp(arg, "--is-inside-git-dir")) {
+ printf("%s\n", is_inside_git_dir() ? "true"
+ : "false");
+ continue;
+ }
if (!strncmp(arg, "--since=", 8)) {
show_datestring("--max-age=", arg+8);
continue;
diff --git a/git-sh-setup.sh b/git-sh-setup.sh
index b4aa4b2f4e6b53388ea9ec0ac13316ae0d0d4458..f24c7f2d23c13e9874308a019f3c0f93225de3c0 100755 (executable)
--- a/git-sh-setup.sh
+++ b/git-sh-setup.sh
}
require_work_tree () {
- test $(is_bare_repository) = false ||
+ test $(is_bare_repository) = false &&
+ test $(git-rev-parse --is-inside-git-dir) = false ||
die "fatal: $0 cannot be used without a working tree."
}
index fb03a547de16af8d9201dc41e9a6f2e37680688b..82a8357272bee1ad6d452a19bf9270f94d94a6cc 100644 (file)
--- a/git.c
+++ b/git.c
prefix = setup_git_directory();
if (p->option & USE_PAGER)
setup_pager();
- if ((p->option & NOT_BARE) && is_bare_repository())
- die("%s cannot be used in a bare git directory", cmd);
+ if ((p->option & NOT_BARE) &&
+ (is_bare_repository() || is_inside_git_dir()))
+ die("%s must be run in a work tree", cmd);
trace_argv_printf(argv, argc, "trace: built-in: git");
exit(p->fn(argc, argv, prefix));