From 7eff28a9b42cb0d3aad932338b2e645fc6ed8fa9 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sat, 30 Dec 2006 23:32:38 -0500 Subject: [PATCH] Disallow working directory commands in a bare repository. If the user tries to run a porcelainish command which requires a working directory in a bare repository they may get unexpected results which are difficult to predict and may differ from command to command. Instead we should detect that the current repository is a bare repository and refuse to run the command there, as there is no working directory associated with it. [jc: updated Shawn's original somewhat -- bugs are mine.] Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- git-am.sh | 1 + git-checkout.sh | 1 + git-clean.sh | 1 + git-commit.sh | 1 + git-merge.sh | 1 + git-pull.sh | 1 + git-rebase.sh | 1 + git-reset.sh | 1 + git-revert.sh | 1 + git-sh-setup.sh | 5 +++++ git.c | 15 +++++++++++---- 11 files changed, 25 insertions(+), 4 deletions(-) diff --git a/git-am.sh b/git-am.sh index 7c0bb6084..f50de6104 100755 --- a/git-am.sh +++ b/git-am.sh @@ -7,6 +7,7 @@ USAGE='[--signoff] [--dotest=] [--utf8] [--binary] [--3way] or, when resuming [--skip | --resolved]' . git-sh-setup set_reflog_action am +require_work_tree git var GIT_COMMITTER_IDENT >/dev/null || exit diff --git a/git-checkout.sh b/git-checkout.sh index 92ec069a3..a5649a050 100755 --- a/git-checkout.sh +++ b/git-checkout.sh @@ -3,6 +3,7 @@ USAGE='[-f] [-b ] [-m] [] [...]' SUBDIRECTORY_OK=Sometimes . git-sh-setup +require_work_tree old_name=HEAD old=$(git-rev-parse --verify $old_name 2>/dev/null) diff --git a/git-clean.sh b/git-clean.sh index 071b974f4..db177a788 100755 --- a/git-clean.sh +++ b/git-clean.sh @@ -14,6 +14,7 @@ When optional ... arguments are given, the paths affected are further limited to those that match them.' SUBDIRECTORY_OK=Yes . git-sh-setup +require_work_tree ignored= ignoredonly= diff --git a/git-commit.sh b/git-commit.sh index 04aad5e5d..557b90355 100755 --- a/git-commit.sh +++ b/git-commit.sh @@ -6,6 +6,7 @@ USAGE='[-a] [-s] [-v] [--no-verify] [-m | -F | (-C|-c) ] [-u] [--amend] [-e] [--author ] [[-i | -o] ...]' SUBDIRECTORY_OK=Yes . git-sh-setup +require_work_tree git-rev-parse --verify HEAD >/dev/null 2>&1 || initial_commit=t diff --git a/git-merge.sh b/git-merge.sh index 477002910..3eef048ef 100755 --- a/git-merge.sh +++ b/git-merge.sh @@ -7,6 +7,7 @@ USAGE='[-n] [--no-commit] [--squash] [-s ] [-m=] option & USE_PAGER) setup_pager(); + if ((p->option & NOT_BARE) && is_bare_repository()) + die("%s cannot be used in a bare git directory", cmd); trace_argv_printf(argv, argc, "trace: built-in: git"); exit(p->fn(argc, argv, prefix)); -- 2.30.2