]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'jk/send-email-sender-prompt'
authorJunio C Hamano <gitster@pobox.com>
Thu, 29 Nov 2012 20:52:45 +0000 (12:52 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 29 Nov 2012 20:52:45 +0000 (12:52 -0800)
General clean-ups in various areas, originally written to support a
patch that later turned out to be unneeded.

* jk/send-email-sender-prompt:
  t9001: check send-email behavior with implicit sender
  t: add tests for "git var"
  ident: keep separate "explicit" flags for author and committer
  ident: make user_ident_explicitly_given static
  t7502: factor out autoident prerequisite
  test-lib: allow negation of prerequisites

builtin/commit.c
cache.h
ident.c
t/t0000-basic.sh
t/t0007-git-var.sh [new file with mode: 0755]
t/t7502-commit.sh
t/t9001-send-email.sh
t/test-lib-functions.sh
t/test-lib.sh

index 1dd2ec5e6f878c02e2858d72f08d8b88d67bcd85..d6dd3df8b1e1f449e7781bdb033f5cfa11753436 100644 (file)
@@ -755,7 +755,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
                                ident_shown++ ? "" : "\n",
                                author_ident->buf);
 
-               if (!user_ident_sufficiently_given())
+               if (!committer_ident_sufficiently_given())
                        status_printf_ln(s, GIT_COLOR_NORMAL,
                                _("%s"
                                "Committer: %s"),
@@ -1265,7 +1265,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1,
                strbuf_addstr(&format, "\n Author: ");
                strbuf_addbuf_percentquote(&format, &author_ident);
        }
-       if (!user_ident_sufficiently_given()) {
+       if (!committer_ident_sufficiently_given()) {
                strbuf_addstr(&format, "\n Committer: ");
                strbuf_addbuf_percentquote(&format, &committer_ident);
                if (advice_implicit_identity) {
diff --git a/cache.h b/cache.h
index dbd8018b5827ce40fd72ac0ba84934551a11f225..18fdd18f3674b1d7c62de65509bdb7bc57743395 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -1149,11 +1149,8 @@ struct config_include_data {
 #define CONFIG_INCLUDE_INIT { 0 }
 extern int git_config_include(const char *name, const char *value, void *data);
 
-#define IDENT_NAME_GIVEN 01
-#define IDENT_MAIL_GIVEN 02
-#define IDENT_ALL_GIVEN (IDENT_NAME_GIVEN|IDENT_MAIL_GIVEN)
-extern int user_ident_explicitly_given;
-extern int user_ident_sufficiently_given(void);
+extern int committer_ident_sufficiently_given(void);
+extern int author_ident_sufficiently_given(void);
 
 extern const char *git_commit_encoding;
 extern const char *git_log_output_encoding;
diff --git a/ident.c b/ident.c
index a4bf206e2f88da3a7ee31a04c5c0dda2b1547baa..ac9672f607909111167559e3aa58e1585f05d0d8 100644 (file)
--- a/ident.c
+++ b/ident.c
 static struct strbuf git_default_name = STRBUF_INIT;
 static struct strbuf git_default_email = STRBUF_INIT;
 static char git_default_date[50];
-int user_ident_explicitly_given;
+
+#define IDENT_NAME_GIVEN 01
+#define IDENT_MAIL_GIVEN 02
+#define IDENT_ALL_GIVEN (IDENT_NAME_GIVEN|IDENT_MAIL_GIVEN)
+static int committer_ident_explicitly_given;
+static int author_ident_explicitly_given;
 
 #ifdef NO_GECOS_IN_PWENT
 #define get_gecos(ignored) "&"
@@ -109,7 +114,8 @@ const char *ident_default_email(void)
 
                if (email && email[0]) {
                        strbuf_addstr(&git_default_email, email);
-                       user_ident_explicitly_given |= IDENT_MAIL_GIVEN;
+                       committer_ident_explicitly_given |= IDENT_MAIL_GIVEN;
+                       author_ident_explicitly_given |= IDENT_MAIL_GIVEN;
                } else
                        copy_email(xgetpwuid_self(), &git_default_email);
                strbuf_trim(&git_default_email);
@@ -327,6 +333,10 @@ const char *fmt_name(const char *name, const char *email)
 
 const char *git_author_info(int flag)
 {
+       if (getenv("GIT_AUTHOR_NAME"))
+               author_ident_explicitly_given |= IDENT_NAME_GIVEN;
+       if (getenv("GIT_AUTHOR_EMAIL"))
+               author_ident_explicitly_given |= IDENT_MAIL_GIVEN;
        return fmt_ident(getenv("GIT_AUTHOR_NAME"),
                         getenv("GIT_AUTHOR_EMAIL"),
                         getenv("GIT_AUTHOR_DATE"),
@@ -336,16 +346,16 @@ const char *git_author_info(int flag)
 const char *git_committer_info(int flag)
 {
        if (getenv("GIT_COMMITTER_NAME"))
-               user_ident_explicitly_given |= IDENT_NAME_GIVEN;
+               committer_ident_explicitly_given |= IDENT_NAME_GIVEN;
        if (getenv("GIT_COMMITTER_EMAIL"))
-               user_ident_explicitly_given |= IDENT_MAIL_GIVEN;
+               committer_ident_explicitly_given |= IDENT_MAIL_GIVEN;
        return fmt_ident(getenv("GIT_COMMITTER_NAME"),
                         getenv("GIT_COMMITTER_EMAIL"),
                         getenv("GIT_COMMITTER_DATE"),
                         flag);
 }
 
-int user_ident_sufficiently_given(void)
+static int ident_is_sufficient(int user_ident_explicitly_given)
 {
 #ifndef WINDOWS
        return (user_ident_explicitly_given & IDENT_MAIL_GIVEN);
@@ -354,6 +364,16 @@ int user_ident_sufficiently_given(void)
 #endif
 }
 
+int committer_ident_sufficiently_given(void)
+{
+       return ident_is_sufficient(committer_ident_explicitly_given);
+}
+
+int author_ident_sufficiently_given(void)
+{
+       return ident_is_sufficient(author_ident_explicitly_given);
+}
+
 int git_ident_config(const char *var, const char *value, void *data)
 {
        if (!strcmp(var, "user.name")) {
@@ -361,7 +381,8 @@ int git_ident_config(const char *var, const char *value, void *data)
                        return config_error_nonbool(var);
                strbuf_reset(&git_default_name);
                strbuf_addstr(&git_default_name, value);
-               user_ident_explicitly_given |= IDENT_NAME_GIVEN;
+               committer_ident_explicitly_given |= IDENT_NAME_GIVEN;
+               author_ident_explicitly_given |= IDENT_NAME_GIVEN;
                return 0;
        }
 
@@ -370,7 +391,8 @@ int git_ident_config(const char *var, const char *value, void *data)
                        return config_error_nonbool(var);
                strbuf_reset(&git_default_email);
                strbuf_addstr(&git_default_email, value);
-               user_ident_explicitly_given |= IDENT_MAIL_GIVEN;
+               committer_ident_explicitly_given |= IDENT_MAIL_GIVEN;
+               author_ident_explicitly_given |= IDENT_MAIL_GIVEN;
                return 0;
        }
 
index 08677df10e9d2a4c87fbe1e5d24eb836b1117e64..562cf41cad7b0532ab4a15625950720c71549742 100755 (executable)
@@ -115,6 +115,38 @@ then
        exit 1
 fi
 
+test_lazy_prereq LAZY_TRUE true
+havetrue=no
+test_expect_success LAZY_TRUE 'test runs if lazy prereq is satisfied' '
+       havetrue=yes
+'
+donthavetrue=yes
+test_expect_success !LAZY_TRUE 'missing lazy prereqs skip tests' '
+       donthavetrue=no
+'
+
+if test "$havetrue$donthavetrue" != yesyes
+then
+       say 'bug in test framework: lazy prerequisites do not work'
+       exit 1
+fi
+
+test_lazy_prereq LAZY_FALSE false
+nothavefalse=no
+test_expect_success !LAZY_FALSE 'negative lazy prereqs checked' '
+       nothavefalse=yes
+'
+havefalse=yes
+test_expect_success LAZY_FALSE 'missing negative lazy prereqs will skip' '
+       havefalse=no
+'
+
+if test "$nothavefalse$havefalse" != yesyes
+then
+       say 'bug in test framework: negative lazy prerequisites do not work'
+       exit 1
+fi
+
 clean=no
 test_expect_success 'tests clean up after themselves' '
        test_when_finished clean=yes
diff --git a/t/t0007-git-var.sh b/t/t0007-git-var.sh
new file mode 100755 (executable)
index 0000000..5868a87
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+test_description='basic sanity checks for git var'
+. ./test-lib.sh
+
+test_expect_success 'get GIT_AUTHOR_IDENT' '
+       test_tick &&
+       echo "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
+       git var GIT_AUTHOR_IDENT >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'get GIT_COMMITTER_IDENT' '
+       test_tick &&
+       echo "$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE" >expect &&
+       git var GIT_COMMITTER_IDENT >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success !AUTOIDENT 'requested identites are strict' '
+       (
+               sane_unset GIT_COMMITTER_NAME &&
+               sane_unset GIT_COMMITTER_EMAIL &&
+               test_must_fail git var GIT_COMMITTER_IDENT
+       )
+'
+
+# For git var -l, we check only a representative variable;
+# testing the whole output would make our test too brittle with
+# respect to unrelated changes in the test suite's environment.
+test_expect_success 'git var -l lists variables' '
+       git var -l >actual &&
+       echo "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
+       sed -n s/GIT_AUTHOR_IDENT=//p <actual >actual.author &&
+       test_cmp expect actual.author
+'
+
+test_expect_success 'git var -l lists config' '
+       git var -l >actual &&
+       echo false >expect &&
+       sed -n s/core\\.bare=//p <actual >actual.bare &&
+       test_cmp expect actual.bare
+'
+
+test_expect_success 'listing and asking for variables are exclusive' '
+       test_must_fail git var -l GIT_COMMITTER_IDENT
+'
+
+test_done
index deb187eb7b4277a43f46e73c1d85012b728ce14a..1a5cb6983c527b6d3e1ad6fad427d3513e8704b1 100755 (executable)
@@ -243,16 +243,6 @@ test_expect_success 'message shows author when it is not equal to committer' '
          .git/COMMIT_EDITMSG
 '
 
-test_expect_success 'setup auto-ident prerequisite' '
-       if (sane_unset GIT_COMMITTER_EMAIL &&
-           sane_unset GIT_COMMITTER_NAME &&
-           git var GIT_COMMITTER_IDENT); then
-               test_set_prereq AUTOIDENT
-       else
-               test_set_prereq NOAUTOIDENT
-       fi
-'
-
 test_expect_success AUTOIDENT 'message shows committer when it is automatic' '
 
        echo >>negative &&
@@ -271,7 +261,7 @@ echo editor started > "$(pwd)/.git/result"
 exit 0
 EOF
 
-test_expect_success NOAUTOIDENT 'do not fire editor when committer is bogus' '
+test_expect_success !AUTOIDENT 'do not fire editor when committer is bogus' '
        >.git/result
        >expect &&
 
index c5d66cf3869384a60db876caab3ba1b06ee32ce2..97d6f4c7de57c54adfd5fed6401dbd168b5f3064 100755 (executable)
@@ -201,6 +201,34 @@ test_expect_success $PREREQ 'Prompting works' '
                grep "^To: to@example.com\$" msgtxt1
 '
 
+test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' '
+       clean_fake_sendmail &&
+       (sane_unset GIT_AUTHOR_NAME &&
+       sane_unset GIT_AUTHOR_EMAIL &&
+       sane_unset GIT_COMMITTER_NAME &&
+       sane_unset GIT_COMMITTER_EMAIL &&
+       GIT_SEND_EMAIL_NOTTY=1 git send-email \
+               --smtp-server="$(pwd)/fake.sendmail" \
+               --to=to@example.com \
+               $patches </dev/null 2>errors
+       )
+'
+
+test_expect_success $PREREQ,!AUTOIDENT 'broken implicit ident aborts send-email' '
+       clean_fake_sendmail &&
+       (sane_unset GIT_AUTHOR_NAME &&
+       sane_unset GIT_AUTHOR_EMAIL &&
+       sane_unset GIT_COMMITTER_NAME &&
+       sane_unset GIT_COMMITTER_EMAIL &&
+       GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
+       test_must_fail git send-email \
+               --smtp-server="$(pwd)/fake.sendmail" \
+               --to=to@example.com \
+               $patches </dev/null 2>errors &&
+       test_i18ngrep "tell me who you are" errors
+       )
+'
+
 test_expect_success $PREREQ 'tocmd works' '
        clean_fake_sendmail &&
        cp $patches tocmd.patch &&
index 8889ba5104cd3f7c783a179d45816d3a82685ef0..22a4f8fb64a4e8084139fc148e8e7dd4aa73d684 100644 (file)
@@ -275,6 +275,15 @@ test_have_prereq () {
 
        for prerequisite
        do
+               case "$prerequisite" in
+               !*)
+                       negative_prereq=t
+                       prerequisite=${prerequisite#!}
+                       ;;
+               *)
+                       negative_prereq=
+               esac
+
                case " $lazily_tested_prereq " in
                *" $prerequisite "*)
                        ;;
@@ -294,10 +303,20 @@ test_have_prereq () {
                total_prereq=$(($total_prereq + 1))
                case "$satisfied_prereq" in
                *" $prerequisite "*)
+                       satisfied_this_prereq=t
+                       ;;
+               *)
+                       satisfied_this_prereq=
+               esac
+
+               case "$satisfied_this_prereq,$negative_prereq" in
+               t,|,t)
                        ok_prereq=$(($ok_prereq + 1))
                        ;;
                *)
-                       # Keep a list of missing prerequisites
+                       # Keep a list of missing prerequisites; restore
+                       # the negative marker if necessary.
+                       prerequisite=${negative_prereq:+!}$prerequisite
                        if test -z "$missing_prereq"
                        then
                                missing_prereq=$prerequisite
index 489bc80fc1b1ba4066a1fd5ad6d2024d67160ba7..0334a9e8fd761b8415f7beb5d70794bc5be33dfd 100644 (file)
@@ -738,6 +738,12 @@ test_lazy_prereq UTF8_NFD_TO_NFC '
        esac
 '
 
+test_lazy_prereq AUTOIDENT '
+       sane_unset GIT_AUTHOR_NAME &&
+       sane_unset GIT_AUTHOR_EMAIL &&
+       git var GIT_AUTHOR_IDENT
+'
+
 # When the tests are run as root, permission tests will report that
 # things are writable when they shouldn't be.
 test -w / || test_set_prereq SANITY