1. 04 2月, 2012 1 次提交
    • J
      tests: add write_script helper function · 840c519d
      Junio C Hamano 提交于
      Many of the scripts in the test suite write small helper
      shell scripts to disk. It's best if these shell scripts
      start with "#!$SHELL_PATH" rather than "#!/bin/sh", because
      /bin/sh on some platforms is too buggy to be used.
      
      However, it can be cumbersome to expand $SHELL_PATH, because
      the usual recipe for writing a script is:
      
      	cat >foo.sh <<-\EOF
      	#!/bin/sh
      	echo my arguments are "$@"
      	EOF
      
      To expand $SHELL_PATH, you have to either interpolate the
      here-doc (which would require quoting "\$@"), or split the
      creation into two commands (interpolating the $SHELL_PATH
      line, but not the rest of the script). Let's provide a
      helper function that makes that less syntactically painful.
      
      While we're at it, this helper can also take care of the
      "chmod +x" that typically comes after the creation of such a
      script, saving the caller a line.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      840c519d
  2. 24 1月, 2012 1 次提交
    • J
      merge: use editor by default in interactive sessions · f8246281
      Junio C Hamano 提交于
      Traditionally, a cleanly resolved merge was committed by "git merge" using
      the auto-generated merge commit log message without invoking the editor.
      
      After 5 years of use in the field, it turns out that people perform too
      many unjustified merges of the upstream history into their topic branches.
      These merges are not just useless, but they are often not explained well,
      and making the end result unreadable when it gets time for merging their
      history back to their upstream.
      
      Earlier we added the "--edit" option to the command, so that people can
      edit the log message to explain and justify their merge commits. Let's
      take it one step further and spawn the editor by default when we are in an
      interactive session (i.e. the standard input and the standard output are
      pointing at the same tty device).
      
      There may be existing scripts that leave the standard input and the
      standard output of the "git merge" connected to whatever environment the
      scripts were started, and such invocation might trigger the above
      "interactive session" heuristics.  GIT_MERGE_AUTOEDIT environment variable
      can be set to "no" at the beginning of such scripts to use the historical
      behaviour while the script runs.
      
      Note that this backward compatibility is meant only for scripts, and we
      deliberately do *not* support "merge.edit = yes/no/auto" configuration
      option to allow people to keep the historical behaviour.
      Suggested-by: NLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f8246281
  3. 18 1月, 2012 1 次提交
    • J
      test-lib: add the test_pause convenience function · c4d2539a
      Jens Lehmann 提交于
      Since 781f76b1 (test-lib: redirect stdin of tests) you can't simply put a
      "bash &&" into a test for debugging purposes anymore. Instead you'll have
      to use "bash <&6 >&3 2>&4".
      
      As that invocation is not that easy to remember add the test_pause
      convenience function. It invokes "$SHELL_PATH" to provide a sane shell
      for the user.
      
      This function also checks if the -v flag is given and will error out if
      that is not the case instead of letting the test hang until ^D is pressed.
      Signed-off-by: NJens Lehmann <Jens.Lehmann@web.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      c4d2539a
  4. 16 12月, 2011 1 次提交
    • J
      test-lib: redirect stdin of tests · 781f76b1
      Jeff King 提交于
      We want to run tests in a predictable, sterile environment
      so we can get repeatable results.  They should take as
      little input as possible from the environment outside the
      test script. We already sanitize environment variables, but
      leave stdin untouched. This means that scripts can
      accidentally be impacted by content on stdin, or whether
      stdin isatty().
      
      Furthermore, scripts reading from stdin can be annoying to
      outer loops which care about their stdin offset, like:
      
        while read sha1; do
            make test
        done
      
      A test which accidentally reads stdin would soak up all of
      the rest of the input intended for the outer shell loop.
      
      Let's redirect stdin from /dev/null, which solves both
      of these problems. It won't detect tests accidentally
      reading from stdin, but since doing so now gives a
      deterministic result, we don't need to consider that an
      error.
      
      We'll also leave file descriptor 6 as a link to the original
      stdin. Tests shouldn't need to look at this, but it can be
      convenient for inserting interactive commands while
      debugging tests (e.g., you could insert "bash <&6 >&3 2>&4"
      to run interactive commands in the environment of the test
      script).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      781f76b1
  5. 12 12月, 2011 1 次提交
    • J
      test-lib: add test_config_global variant · a96250c6
      Jeff King 提交于
      The point of test_config is to simultaneously set a config
      variable and register its cleanup handler, like:
      
        test_config core.foo bar
      
      However, it stupidly assumes that $1 contained the name of
      the variable, which means it won't work for:
      
        test_config --global core.foo bar
      
      We could try to parse the command-line ourselves and figure
      out which parts need to be fed to test_unconfig. But since
      this is likely the most common variant, it's much simpler
      and less error-prone to simply add a new function.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      a96250c6
  6. 06 12月, 2011 1 次提交
    • Æ
      i18n: add infrastructure for translating Git with gettext · 5e9637c6
      Ævar Arnfjörð Bjarmason 提交于
      Change the skeleton implementation of i18n in Git to one that can show
      localized strings to users for our C, Shell and Perl programs using
      either GNU libintl or the Solaris gettext implementation.
      
      This new internationalization support is enabled by default. If
      gettext isn't available, or if Git is compiled with
      NO_GETTEXT=YesPlease, Git falls back on its current behavior of
      showing interface messages in English. When using the autoconf script
      we'll auto-detect if the gettext libraries are installed and act
      appropriately.
      
      This change is somewhat large because as well as adding a C, Shell and
      Perl i18n interface we're adding a lot of tests for them, and for
      those tests to work we need a skeleton PO file to actually test
      translations. A minimal Icelandic translation is included for this
      purpose. Icelandic includes multi-byte characters which makes it easy
      to test various edge cases, and it's a language I happen to
      understand.
      
      The rest of the commit message goes into detail about various
      sub-parts of this commit.
      
      = Installation
      
      Gettext .mo files will be installed and looked for in the standard
      $(prefix)/share/locale path. GIT_TEXTDOMAINDIR can also be set to
      override that, but that's only intended to be used to test Git itself.
      
      = Perl
      
      Perl code that's to be localized should use the new Git::I18n
      module. It imports a __ function into the caller's package by default.
      
      Instead of using the high level Locale::TextDomain interface I've
      opted to use the low-level (equivalent to the C interface)
      Locale::Messages module, which Locale::TextDomain itself uses.
      
      Locale::TextDomain does a lot of redundant work we don't need, and
      some of it would potentially introduce bugs. It tries to set the
      $TEXTDOMAIN based on package of the caller, and has its own
      hardcoded paths where it'll search for messages.
      
      I found it easier just to completely avoid it rather than try to
      circumvent its behavior. In any case, this is an issue wholly
      internal Git::I18N. Its guts can be changed later if that's deemed
      necessary.
      
      See <AANLkTilYD_NyIZMyj9dHtVk-ylVBfvyxpCC7982LWnVd@mail.gmail.com> for
      a further elaboration on this topic.
      
      = Shell
      
      Shell code that's to be localized should use the git-sh-i18n
      library. It's basically just a wrapper for the system's gettext.sh.
      
      If gettext.sh isn't available we'll fall back on gettext(1) if it's
      available. The latter is available without the former on Solaris,
      which has its own non-GNU gettext implementation. We also need to
      emulate eval_gettext() there.
      
      If neither are present we'll use a dumb printf(1) fall-through
      wrapper.
      
      = About libcharset.h and langinfo.h
      
      We use libcharset to query the character set of the current locale if
      it's available. I.e. we'll use it instead of nl_langinfo if
      HAVE_LIBCHARSET_H is set.
      
      The GNU gettext manual recommends using langinfo.h's
      nl_langinfo(CODESET) to acquire the current character set, but on
      systems that have libcharset.h's locale_charset() using the latter is
      either saner, or the only option on those systems.
      
      GNU and Solaris have a nl_langinfo(CODESET), FreeBSD can use either,
      but MinGW and some others need to use libcharset.h's locale_charset()
      instead.
      
      =Credits
      
      This patch is based on work by Jeff Epler <jepler@unpythonic.net> who
      did the initial Makefile / C work, and a lot of comments from the Git
      mailing list, including Jonathan Nieder, Jakub Narebski, Johannes
      Sixt, Erik Faye-Lund, Peter Krefting, Junio C Hamano, Thomas Rast and
      others.
      
      [jc: squashed a small Makefile fix from Ramsay]
      Signed-off-by: NÆvar Arnfjörð Bjarmason <avarab@gmail.com>
      Signed-off-by: NRamsay Jones <ramsay@ramsay1.demon.co.uk>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      5e9637c6
  7. 31 8月, 2011 1 次提交
  8. 19 8月, 2011 1 次提交
    • J
      test-lib: add helper functions for config · d960c47a
      Jeff King 提交于
      There are a few common tasks when working with configuration
      variables in tests; this patch aims to make them a little
      easier to write and less error-prone.
      
      When setting a variable, you should typically make sure to
      clean it up after the test is finished, so as not to pollute
      other tests. Like:
      
         test_when_finished 'git config --unset foo.bar' &&
         git config foo.bar baz
      
      This patch lets you just write:
      
        test_config foo.bar baz
      
      When clearing a variable that does not exist, git-config
      will report a specific non-zero error code. Meaning that
      tests which call "git config --unset" often either rely on
      the prior tests having actually set it, or must use
      test_might_fail. With this patch, the previous:
      
        test_might_fail git config --unset foo.bar
      
      becomes:
      
        test_unconfig foo.bar
      
      Not only is this easier to type, but it is more robust; it
      will correctly detect errors from git-config besides "key
      was not set".
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d960c47a
  9. 12 8月, 2011 1 次提交
  10. 09 8月, 2011 2 次提交
    • J
      test: cope better with use of return for errors · a7c58f28
      Jonathan Nieder 提交于
      In olden times, tests would quietly exit the script when they failed
      at an inconvenient moment, which was a little disconcerting.
      Therefore v0.99.5~24^2~4 (Trapping exit in tests, using return for
      errors, 2005-08-10) switched to an idiom of using "return" instead,
      wrapping evaluation of test code in a function to make that safe:
      
      	test_run_ () {
      		eval >&3 2>&4 "$1"
      		eval_ret="$?"
      		return 0
      	}
      
      Years later, the implementation of test_when_finished (v1.7.1.1~95,
      2010-05-02) and v1.7.2-rc2~1^2~13 (test-lib: output a newline before
      "ok" under a TAP harness, 2010-06-24) took advantage of test_run_ as a
      place to put code shared by all test assertion functions, without
      paying attention to the function's former purpose:
      
      	test_run_ () {
      		...
      		eval >&3 2>&4 "$1"
      		eval_ret=$?
      
      		if should run cleanup
      		then
      			eval >&3 2>&4 "$test_cleanup"
      		fi
      		if TAP format requires a newline here
      		then
      			echo
      		fi
      		return 0
      	}
      
      That means cleanup commands and the newline to put TAP output at
      column 0 are skipped when tests use "return" to fail early.  Fix it by
      introducing a test_eval_ function to catch the "return", with a
      comment explaining the new function's purpose for the next person who
      might touch this code.
      Signed-off-by: NJonathan Nieder <jrnieder@gmail.com>
      Acked-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      a7c58f28
    • J
      test: simplify return value of test_run_ · aa0bcf96
      Jonathan Nieder 提交于
      As v0.99.5~24^2~4 (Trapping exit in tests, using return for errors,
      2005-08-10) explains, callers to test_run_ (such as test_expect_code)
      used to check the result from eval and the return value separately so
      tests that fail early could be distinguished from tests that completed
      normally with successful (nonzero) status.  Eventually tests that
      succeed with nonzero status were phased out (see v1.7.4-rc0~65^2~19,
      2010-10-03 and especially v1.5.5-rc0~271, 2008-02-01) but the weird
      two-return-value calling convention lives on.
      
      Let's get rid of it.  The new rule: test_run_ succeeds (returns 0)
      if and only if the test succeeded.
      Signed-off-by: NJonathan Nieder <jrnieder@gmail.com>
      Acked-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      aa0bcf96
  11. 30 6月, 2011 1 次提交
    • J
      test: skip clean-up when running under --immediate mode · b586744a
      Junio C Hamano 提交于
      Some tests try to be too careful about cleaning themselves up and
      do
      
          test_expect_success description '
              set-up some test refs and/or configuration &&
              test_when_finished "revert the above changes" &&
      	the real test
          '
      
      Which is nice to make sure that a potential failure would not have
      unexpected interaction with the next test. This however interferes when
      "the real test" fails and we want to see what is going on, by running the
      test with --immediate mode and descending into its trash directory after
      the test stops. The precondition to run the real test and cause it to fail
      is all gone after the clean-up procedure defined by test_when_finished is
      done.
      
      Update test_run_ which is the workhorse of running a test script
      called from test_expect_success and test_expect_failure, so that we do not
      run clean-up script defined with test_when_finished when a test that is
      expected to succeed fails under the --immediate mode.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      Acked-by: NJeff King <peff@peff.net>
      b586744a
  12. 18 6月, 2011 1 次提交
    • J
      tests: link shell libraries into valgrind directory · 36bfb0e5
      Jeff King 提交于
      When we run tests under valgrind, we symlink anything
      executable that starts with git-* or test-* into a special
      valgrind bin directory, and then make that our
      GIT_EXEC_PATH.
      
      However, shell libraries like git-sh-setup do not have the
      executable bit marked, and did not get symlinked.  This
      means that any test looking for shell libraries in our
      exec-path would fail to find them, even though that is a
      fine thing to do when testing against a regular git build
      (or in a git install, for that matter).
      
      t2300 demonstrated this problem. The fix is to symlink these
      shell libraries directly into the valgrind directory.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      36bfb0e5
  13. 22 5月, 2011 1 次提交
    • J
      tests: make test_expect_code quieter on success · f5b7ce1b
      Jonathan Nieder 提交于
      A command exiting with the expected status is not particularly
      notable.
      
      While the indication of progress might be useful when tracking down
      where in a test a failure has happened, the same applies to most other
      test helpers, which are quiet about success, so this single helper's
      output stands out in an unpleasant way.  An alternative method for
      showing progress information might to invent a --progress option that
      runs tests with "set -x", or until that is available, to run tests
      using commands like
      
      	prove -v -j2 --shuffle --exec='sh -x' t2202-add-addremove.sh
      Signed-off-by: NJonathan Nieder <jrnieder@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f5b7ce1b
  14. 10 5月, 2011 1 次提交
  15. 29 4月, 2011 1 次提交
  16. 24 4月, 2011 1 次提交
  17. 14 4月, 2011 1 次提交
  18. 13 4月, 2011 1 次提交
    • J
      i18n: do not overuse C_LOCALE_OUTPUT · cabdee2c
      Junio C Hamano 提交于
      It is too coarse-grained way that led to artificial splitting of a
      logically single test case into "do" and "check only without poison".
      As the majority of check is done by comparing expected and actual output
      stored in a file with test_cmp anyway, just introduce test_i18ncmp that
      pretends the actual output matched the expected one when gettext-poison
      is in effect.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      cabdee2c
  19. 29 3月, 2011 2 次提交
    • A
      HOME must be set before calling git-init when creating test repositories · 90cff968
      Alex Riesen 提交于
      Otherwise the created test repositories will be affected by users ~/.gitconfig.
      For example, setting core.logAllrefupdates in users config will make all
      calls to "git config --unset core.logAllrefupdates" fail which will break
      the first test which uses the statement and expects it to succeed.
      Signed-off-by: NAlex Riesen <raa.lkml@gmail.com>
      Acked-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      90cff968
    • J
      tests: fix overeager scrubbing of environment variables · 730477f1
      Jens Lehmann 提交于
      In commit 95a1d12e ("tests: scrub environment of GIT_* variables") all
      environment variables starting with "GIT_" were unset for the tests using
      a perl script rather than unsetting them one by one. Only three exceptions
      were made to make them work as before: "GIT_TRACE*", "GIT_DEBUG*" and
      "GIT_USE_LOOKUP".
      
      Unfortunately some environment variables used by the test framework itself
      were not added to the exceptions and thus stopped working when given
      before the make command instead of after it. Those are:
      
      - GIT_NOTES_TIMING_TESTS
      - GIT_PATCHID_TIMING_TESTS
      - GIT_PROVE_OPTS
      - GIT_REMOTE_SVN_TEST_BIG_FILES
      - GIT_SKIP_TESTS
      - GIT_TEST*
      - GIT_VALGRIND_OPTIONS
      
      I noticed that when skipping a test the way I was used to suddenly failed:
      
      GIT_SKIP_TESTS='t1234' GIT_TEST_OPTS='--root=/dev/shm' make -j10 test
      
      This should work according to t/README, but didn't anymore, so let's fix
      that by adding them to the exception list. And to avoid having a long
      regexp put the exceptions in a separate variable using nicer formatting.
      Signed-off-by: NJens Lehmann <Jens.Lehmann@web.de>
      Acked-by: NJonathan Nieder <jrnieder@gmail.com>
      Thanks-to: Jeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      730477f1
  20. 16 3月, 2011 4 次提交
  21. 09 3月, 2011 2 次提交
    • J
      i18n: do not poison translations unless GIT_GETTEXT_POISON envvar is set · 30955229
      Jonathan Nieder 提交于
      Tweak the GETTEXT_POISON facility so it is activated at run time
      instead of compile time.  If the GIT_GETTEXT_POISON environment
      variable is set, _(msg) will result in gibberish as before; but if the
      GIT_GETTEXT_POISON variable is not set, it will return the message for
      human-readable output.  So the behavior of mistranslated and
      untranslated git can be compared without rebuilding git in between.
      
      For simplicity we always set the GIT_GETTEXT_POISON variable in tests.
      
      This does not affect builds without the GETTEXT_POISON compile-time
      option set, so non-i18n git will not be slowed down.
      Signed-off-by: NJonathan Nieder <jrnieder@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      30955229
    • Æ
      i18n: add GETTEXT_POISON to simulate unfriendly translator · bb946bba
      Ævar Arnfjörð Bjarmason 提交于
      Add a new GETTEXT_POISON compile-time parameter to make _(msg) always
      return gibberish. So now you can run
      
      	make GETTEXT_POISON=YesPlease
      
      to get a copy of git that functions correctly (one hopes) but produces
      output that is in nobody's native language at all.
      
      This is a debugging aid for people who are working on the i18n part of
      the system, to make sure that they are not marking plumbing messages
      that should never be translated with _().
      
      As new strings get marked for translation, naturally a number of tests
      will be broken in this mode. Tests that depend on output from
      Porcelain will need to be marked with the new C_LOCALE_OUTPUT test
      prerequisite. Newly failing tests that do not depend on output from
      Porcelain would be bugs due to messages that should not have been
      marked for translation.
      
      Note that the string we're using ("# GETTEXT POISON #") intentionally
      starts the pound sign. Some of Git's tests such as
      t3404-rebase-interactive.sh rely on interactive editing with a fake
      editor, and will needlessly break if the message doesn't start with
      something the interactive editor considers a comment.
      
      A future patch will fix fix the underlying cause of that issue by
      adding "#" characters to the commit advice automatically.
      Signed-off-by: NÆvar Arnfjörð Bjarmason <avarab@gmail.com>
      Signed-off-by: NJonathan Nieder <jrnieder@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      bb946bba
  22. 28 1月, 2011 1 次提交
  23. 09 1月, 2011 2 次提交
  24. 23 12月, 2010 1 次提交
  25. 10 11月, 2010 1 次提交
    • J
      test-lib: introduce test_line_count to measure files · fb3340a6
      Jonathan Nieder 提交于
      Some tests check their output with code like the following:
      
      	test "$(git ls-files -u B | wc -l)" -eq 3 || {
      		echo "BAD: should have left stages for B"
      		return 1
      	}
      
      The verbose failure condition is used because test, unlike
      diff, does not print any useful information about the
      nature of the failure when it fails.
      
      Introduce a test_line_count function to help. If used like
      
      	git ls-files -u B >output &&
      	test_line_count -eq 3 output
      
      it will produce output like
      
      	test_line_count: line count for output !-eq 3
      	100644 b023018cabc396e7692c70bbf5784a93d3f738ab 2	hi.c
      	100644 45b983be36b73c0788dc9cbcb76cbb80fc7bb057 3	hi.c
      
      on failure.
      Signed-off-by: NJonathan Nieder <jrnieder@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      fb3340a6
  26. 21 10月, 2010 1 次提交
  27. 19 10月, 2010 1 次提交
  28. 14 10月, 2010 1 次提交
    • J
      rev-list: handle %x00 NUL in user format · 9130ac9f
      Jeff King 提交于
      The code paths for showing commits in "git log" and "git
      rev-list --graph" correctly handle embedded NULs by looking
      only at the resulting strbuf's length, and never treating it
      as a C string. The code path for regular rev-list, however,
      used printf("%s"), which resulted in truncated output. This
      patch uses fwrite instead, like the --graph code path.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      9130ac9f
  29. 07 10月, 2010 2 次提交
  30. 02 10月, 2010 2 次提交
  31. 01 9月, 2010 1 次提交