From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
sbeller@google.com, asottile@umich.edu,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v2 0/3] nd/clear-gitenv-upon-use-of-alias
Date: Sun, 20 Dec 2015 14:50:16 +0700 [thread overview]
Message-ID: <1450597819-26278-1-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1449166676-30845-1-git-send-email-pclouds@gmail.com>
Changes since v1:
- make sure we save/restore env for external commands in 2/3
- fix t0001 test in 3/3
Interdiff:
diff --git b/git.c a/git.c
index 83b6c56..da278c3 100644
--- b/git.c
+++ a/git.c
@@ -229,7 +229,6 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
static int handle_alias(int *argcp, const char ***argv)
{
int envchanged = 0, ret = 0, saved_errno = errno;
- const char *subdir;
int count, option_count;
const char **new_argv;
const char *alias_command;
@@ -237,7 +236,7 @@ static int handle_alias(int *argcp, const char ***argv)
int unused_nongit;
save_env_before_alias();
- subdir = setup_git_directory_gently(&unused_nongit);
+ setup_git_directory_gently(&unused_nongit);
alias_command = (*argv)[0];
alias_string = alias_lookup(alias_command);
@@ -296,8 +295,7 @@ static int handle_alias(int *argcp, const char ***argv)
ret = 1;
}
- if (subdir && chdir(subdir))
- die_errno("Cannot change to '%s'", subdir);
+ restore_env(0);
errno = saved_errno;
@@ -534,9 +532,13 @@ static void handle_builtin(int argc, const char **argv)
builtin = get_builtin(cmd);
if (builtin) {
- if (saved_env_before_alias)
- restore_env(0);
- else
+ /*
+ * XXX: if we can figure out cases where it is _safe_
+ * to do, we can avoid spawning a new process when
+ * saved_env_before_alias is true
+ * (i.e. setup_git_dir* has been run once)
+ */
+ if (!saved_env_before_alias)
exit(run_builtin(builtin, argc, argv));
}
}
diff --git b/t/t0001-init.sh a/t/t0001-init.sh
index 19539fc..295aa59 100755
--- b/t/t0001-init.sh
+++ a/t/t0001-init.sh
@@ -88,24 +88,14 @@ test_expect_success 'plain nested in bare through aliased command' '
'
test_expect_success 'No extra GIT_* on alias scripts' '
- cat <<-\EOF >expected &&
- GIT_ATTR_NOSYSTEM
- GIT_AUTHOR_EMAIL
- GIT_AUTHOR_NAME
- GIT_COMMITTER_EMAIL
- GIT_COMMITTER_NAME
- GIT_CONFIG_NOSYSTEM
- GIT_EXEC_PATH
- GIT_MERGE_AUTOEDIT
- GIT_MERGE_VERBOSITY
- GIT_PREFIX
- GIT_TEMPLATE_DIR
- GIT_TEXTDOMAINDIR
- GIT_TRACE_BARE
- EOF
+ (
+ env | sed -ne "/^GIT_/s/=.*//p" &&
+ echo GIT_PREFIX && # setup.c
+ echo GIT_TEXTDOMAINDIR # wrapper-for-bin.sh
+ ) | sort | uniq >expected &&
cat <<-\EOF >script &&
#!/bin/sh
- env | grep GIT_ | sed "s/=.*//" | sort >actual
+ env | sed -ne "/^GIT_/s/=.*//p" | sort >actual
exit 0
EOF
chmod 755 script &&
Nguyễn Thái Ngọc Duy (3):
git.c: make it clear save_env() is for alias handling only
setup.c: re-fix d95138e (setup: set env $GIT_WORK_TREE when ..
git.c: make sure we do not leak GIT_* to alias scripts
environment.c | 2 --
git.c | 41 +++++++++++++++++++++++------------------
t/t0001-init.sh | 17 +++++++++++++++++
t/t5601-clone.sh | 23 +++++++++++++++++++++++
4 files changed, 63 insertions(+), 20 deletions(-)
--
2.3.0.rc1.137.g477eb31
next prev parent reply other threads:[~2015-12-20 7:50 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CA+dzEB=2LJXiLSTqyLw8AeHNwdQicwvEiMg=hVEX0-_s1bySpA@mail.gmail.com>
2015-11-24 2:22 ` Fwd: Git clone fails during pre-commit hook due to GIT_WORK_TREE=. (regression 2.5 -> 2.6) Anthony Sottile
2015-11-24 17:57 ` Stefan Beller
2015-11-25 20:13 ` Duy Nguyen
2015-11-30 19:01 ` Duy Nguyen
2015-11-30 20:16 ` Junio C Hamano
2015-12-01 17:59 ` Duy Nguyen
2015-12-02 17:09 ` Junio C Hamano
2015-12-03 18:17 ` [PATCH 1/2] git.c: make it clear save_env() is for alias handling only Nguyễn Thái Ngọc Duy
2015-12-03 18:17 ` [PATCH 2/2] setup.c: re-fix d95138e (setup: set env $GIT_WORK_TREE when Nguyễn Thái Ngọc Duy
2015-12-04 20:35 ` Junio C Hamano
2015-12-05 5:48 ` Duy Nguyen
2015-12-05 15:32 ` [PATCH 3/2] git.c: make sure we do not leak GIT_* to alias scripts Nguyễn Thái Ngọc Duy
2015-12-07 18:54 ` Junio C Hamano
2015-12-08 16:55 ` Duy Nguyen
2015-12-08 17:20 ` Jeff King
2015-12-08 23:55 ` Junio C Hamano
2015-12-05 19:12 ` [PATCH 2/2] setup.c: re-fix d95138e (setup: set env $GIT_WORK_TREE when Duy Nguyen
2015-12-07 18:33 ` Junio C Hamano
2015-12-20 7:50 ` Nguyễn Thái Ngọc Duy [this message]
2015-12-20 7:50 ` [PATCH v2 1/3] git.c: make it clear save_env() is for alias handling only Nguyễn Thái Ngọc Duy
2015-12-20 7:50 ` [PATCH v2 2/3] setup.c: re-fix d95138e (setup: set env $GIT_WORK_TREE when Nguyễn Thái Ngọc Duy
2015-12-20 7:50 ` [PATCH v2 3/3] git.c: make sure we do not leak GIT_* to alias scripts Nguyễn Thái Ngọc Duy
2015-12-21 21:18 ` [PATCH v2 0/3] nd/clear-gitenv-upon-use-of-alias Junio C Hamano
2015-12-22 10:57 ` Duy Nguyen
2015-12-22 11:53 ` Duy Nguyen
2015-12-22 18:13 ` Junio C Hamano
2015-12-23 9:37 ` Jeff King
2015-12-23 10:20 ` Duy Nguyen
2015-12-23 16:17 ` Eric Sunshine
2015-12-23 20:37 ` Johannes Sixt
2015-12-23 21:31 ` Jeff King
2015-12-24 9:35 ` Duy Nguyen
2015-12-29 8:12 ` Jeff King
2015-12-29 21:34 ` Junio C Hamano
2015-12-21 10:22 ` [PATCH] Revert "setup: set env $GIT_WORK_TREE when work tree is set, like $GIT_DIR" Nguyễn Thái Ngọc Duy
2015-12-21 17:28 ` Junio C Hamano
2015-12-21 18:31 ` Junio C Hamano
2015-12-22 1:06 ` Duy Nguyen
2015-12-22 21:50 ` Junio C Hamano
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=1450597819-26278-1-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=asottile@umich.edu \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=sbeller@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.