From 7eff28a9b42cb0d3aad932338b2e645fc6ed8fa9 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sat, 30 Dec 2006 23:32:38 -0500 Subject: 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.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'git.c') diff --git a/git.c b/git.c index bf55499dc3..692773b9ae 100644 --- a/git.c +++ b/git.c @@ -199,6 +199,11 @@ const char git_version_string[] = GIT_VERSION; #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) { @@ -208,7 +213,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 }, + { "add", cmd_add, RUN_SETUP | NOT_BARE }, { "annotate", cmd_annotate, }, { "apply", cmd_apply }, { "archive", cmd_archive }, @@ -239,7 +244,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp) { "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 }, @@ -252,8 +257,8 @@ 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 }, - { "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 }, @@ -290,6 +295,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()) + 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)); -- cgit v1.2.3