summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4b441f4)
raw | patch | inline | side by side (parent: 4b441f4)
author | Shawn O. Pearce <spearce@spearce.org> | |
Sun, 31 Dec 2006 04:32:38 +0000 (23:32 -0500) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Wed, 10 Jan 2007 23:03:09 +0000 (15:03 -0800) |
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 <spearce@spearce.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
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 <spearce@spearce.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
git-am.sh | patch | blob | history | |
git-checkout.sh | patch | blob | history | |
git-clean.sh | patch | blob | history | |
git-commit.sh | patch | blob | history | |
git-merge.sh | patch | blob | history | |
git-pull.sh | patch | blob | history | |
git-rebase.sh | patch | blob | history | |
git-reset.sh | patch | blob | history | |
git-revert.sh | patch | blob | history | |
git-sh-setup.sh | patch | blob | history | |
git.c | patch | blob | history |
diff --git a/git-am.sh b/git-am.sh
index 7c0bb6084b332db7f7b6b9058db4d92b828730f0..f50de61049d039f939956dc4a8c0b502dc1d70e5 100755 (executable)
--- a/git-am.sh
+++ b/git-am.sh
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 92ec069a3acacc2d12c2c709311969f3d0aa4153..a5649a0504f3d5b25fe800e85c0b3eb122368289 100755 (executable)
--- a/git-checkout.sh
+++ b/git-checkout.sh
USAGE='[-f] [-b <new_branch>] [-m] [<branch>] [<paths>...]'
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 071b974f496b8deff3a2d1b869c35d4f556dc17f..db177a7886b6407b4c4ad7b778a1ae99471355ac 100755 (executable)
--- a/git-clean.sh
+++ b/git-clean.sh
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 04aad5e5da6fad46bc71c859286615c2f6ce11ab..557b90355cdbaf108f0e339d61f7bf076cc7942d 100755 (executable)
--- a/git-commit.sh
+++ b/git-commit.sh
USAGE='[-a] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit>] [-u] [--amend] [-e] [--author <author>] [[-i | -o] <path>...]'
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 477002910ede7f6bc6bcb9a79f6ddebd248f6bd2..3eef048efc7a848145697e205d154c92f8c7ec0f 100755 (executable)
--- a/git-merge.sh
+++ b/git-merge.sh
. git-sh-setup
set_reflog_action "merge $*"
+require_work_tree
test -z "$(git ls-files -u)" ||
die "You are in a middle of conflicted merge."
diff --git a/git-pull.sh b/git-pull.sh
index c184fb81a4dab622d79120bcc986c3bf2b07df7f..e9826fc4cec14d82171f495af25324b24fe9f19b 100755 (executable)
--- a/git-pull.sh
+++ b/git-pull.sh
LONG_USAGE='Fetch one or more remote refs and merge it/them into the current HEAD.'
. git-sh-setup
set_reflog_action "pull $*"
+require_work_tree
test -z "$(git ls-files -u)" ||
die "You are in a middle of conflicted merge."
diff --git a/git-rebase.sh b/git-rebase.sh
index 828c59ce61a8317f23ba9113e4de6e09a58e70ce..98f9558145f269e05e121006a5853368f0572abf 100755 (executable)
--- a/git-rebase.sh
+++ b/git-rebase.sh
'
. git-sh-setup
set_reflog_action rebase
+require_work_tree
RESOLVEMSG="
When you have resolved this problem run \"git rebase --continue\".
diff --git a/git-reset.sh b/git-reset.sh
index 76c8a818d421c796141fae3835e1cb4726d23ef3..b9045bc762471b462c3c99a5357b4b30421ea49f 100755 (executable)
--- a/git-reset.sh
+++ b/git-reset.sh
SUBDIRECTORY_OK=Yes
. git-sh-setup
set_reflog_action "reset $*"
+require_work_tree
update= reset_type=--mixed
unset rev
diff --git a/git-revert.sh b/git-revert.sh
index 50cc47b0634201e7acaaa0a0642be779aaf7c2da..f9843c7c8ec4c3ae7e796fec801425e85dc1c73d 100755 (executable)
--- a/git-revert.sh
+++ b/git-revert.sh
die "What are you talking about?" ;;
esac
. git-sh-setup
+require_work_tree
no_commit=
while case "$#" in 0) break ;; esac
diff --git a/git-sh-setup.sh b/git-sh-setup.sh
index 7fdc912167ae25568ffe95132936323abbdba09e..4a02b3825ecc15cb289a1dadb328e39a1869f3f1 100755 (executable)
--- a/git-sh-setup.sh
+++ b/git-sh-setup.sh
esac
}
+require_work_tree () {
+ test $(is_bare_repository) = false ||
+ die "fatal: $0 cannot be used without a working tree."
+}
+
if [ -z "$LONG_USAGE" ]
then
LONG_USAGE="Usage: $0 $USAGE"
index bf55499dc3d555dfaa853b0c6e4aec5439c3532e..692773b9aec2c68db6ae485b60bbc74a961f2cc9 100644 (file)
--- a/git.c
+++ b/git.c
#define RUN_SETUP (1<<0)
#define USE_PAGER (1<<1)
+/*
+ * require working tree to be present -- anything uses this needs
+ * RUN_SETUP for reading from the configuration file.
+ */
+#define NOT_BARE (1<<2)
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 },
+ { "add", cmd_add, RUN_SETUP | NOT_BARE },
{ "annotate", cmd_annotate, },
{ "apply", cmd_apply },
{ "archive", cmd_archive },
{ "mailinfo", cmd_mailinfo },
{ "mailsplit", cmd_mailsplit },
{ "merge-file", cmd_merge_file },
- { "mv", cmd_mv, RUN_SETUP },
+ { "mv", cmd_mv, RUN_SETUP | NOT_BARE },
{ "name-rev", cmd_name_rev, RUN_SETUP },
{ "pack-objects", cmd_pack_objects, RUN_SETUP },
{ "pickaxe", cmd_blame, RUN_SETUP | USE_PAGER },
{ "rerere", cmd_rerere, RUN_SETUP },
{ "rev-list", cmd_rev_list, RUN_SETUP },
{ "rev-parse", cmd_rev_parse, RUN_SETUP },
- { "rm", cmd_rm, RUN_SETUP },
- { "runstatus", cmd_runstatus, RUN_SETUP },
+ { "rm", cmd_rm, RUN_SETUP | NOT_BARE },
+ { "runstatus", cmd_runstatus, RUN_SETUP | NOT_BARE },
{ "shortlog", cmd_shortlog, RUN_SETUP | USE_PAGER },
{ "show-branch", cmd_show_branch, RUN_SETUP },
{ "show", cmd_show, RUN_SETUP | USE_PAGER },
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);
trace_argv_printf(argv, argc, "trace: built-in: git");
exit(p->fn(argc, argv, prefix));