From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
Jonathan Nieder <jrnieder@gmail.com>
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH] builtins: reset startup_info->have_run_setup_gitdir when unsetting up repository
Date: Sat, 27 Mar 2010 16:13:04 +0700 [thread overview]
Message-ID: <1269681184-1992-2-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1269681184-1992-1-git-send-email-pclouds@gmail.com>
startup_info->have_run_setup_gitdir is used to guard unallowed access
to repository. When a repository has been set up and the real command
does not expect any setup, we should revert to the original "fresh"
state, including startup_info->have_run_setup_gitdir. Otherwise, the
next attempt to set up repository will fail.
While at it, also reset repository_format_version to zero. When
omitted, the format should be understood as the last supported
version, i.e. zero. This is probably only used by "git init" or "git
clone".
Fault caught by Jonathan Nieder (and demonstrated with a beautiful test case)
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
Junio, I can split this up and put it to the original patches where the faults
are introduced if you want.
git.c | 13 ++++++++-----
setup.c | 2 +-
t/t0001-init.sh | 14 ++++++++++++++
3 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/git.c b/git.c
index 7ebfea5..5c249fd 100644
--- a/git.c
+++ b/git.c
@@ -242,11 +242,14 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
int nongit_ok;
setup_git_directory_gently(&nongit_ok);
}
- else if (startup_info->have_repository) {
- if (p->option & (RUN_SETUP_GENTLY | RUN_SETUP))
- ; /* done already */
- else
- unset_git_directory(startup_info->prefix);
+ else if (startup_info->have_run_setup_gitdir) {
+ if (startup_info->have_repository) {
+ if (p->option & (RUN_SETUP_GENTLY | RUN_SETUP))
+ ; /* done already */
+ else
+ unset_git_directory(startup_info->prefix);
+ }
+ startup_info->have_run_setup_gitdir = 0;
}
if (use_pager == -1 && p->option & RUN_SETUP)
diff --git a/setup.c b/setup.c
index d9bb616..43b529e 100644
--- a/setup.c
+++ b/setup.c
@@ -358,7 +358,7 @@ void unset_git_directory(const char *prefix)
inside_git_dir = -1;
/* Initialized in check_repository_format_version() */
- repository_format_version = 0xFF;
+ repository_format_version = 0;
shared_repository = PERM_UMASK;
is_bare_repository_cfg = -1;
git_work_tree_cfg = NULL;
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index 5386504..f93856b 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -33,6 +33,20 @@ test_expect_success 'plain' '
check_config plain/.git false unset
'
+test_expect_success 'plain through aliased command' '
+ (
+ unset GIT_DIR GIT_WORK_TREE GIT_CONFIG_NOGLOBAL &&
+ HOME=$(pwd)/alias-config &&
+ export HOME &&
+ mkdir alias-config &&
+ echo "[alias] aliasedinit = init" >alias-config/.gitconfig &&
+ mkdir plain-aliased &&
+ cd plain-aliased &&
+ git aliasedinit
+ ) &&
+ check_config plain-aliased/.git false unset
+'
+
test_expect_success 'plain with GIT_WORK_TREE' '
if (
unset GIT_DIR
--
1.7.0.rc1.541.g2da82.dirty
next prev parent reply other threads:[~2010-03-27 15:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-27 9:13 [PATCH] builtins: setup repository before print unknown command error Nguyễn Thái Ngọc Duy
2010-03-27 9:13 ` Nguyễn Thái Ngọc Duy [this message]
2010-03-27 22:38 ` [PATCH] builtins: reset startup_info->have_run_setup_gitdir when unsetting up repository Jonathan Nieder
2010-03-28 7:11 ` Nguyen Thai Ngoc Duy
2010-03-28 0:34 ` Jonathan Nieder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1269681184-1992-2-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).