t / t0100-environment-names.shon commit Merge with gitk. (2b64f88)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Junio C Hamano
   4#
   5
   6test_description='general environment name warning test.
   7
   8This test makes sure that use of deprecated environment variables
   9trigger the warnings from gitenv().'
  10
  11env_vars='GIT_AUTHOR_DATE:AUTHOR_DATE
  12GIT_AUTHOR_EMAIL:AUTHOR_EMAIL
  13GIT_AUTHOR_NAME:AUTHOR_NAME
  14GIT_COMMITTER_EMAIL:COMMIT_AUTHOR_EMAIL
  15GIT_COMMITTER_NAME:COMMIT_AUTHOR_NAME
  16GIT_ALTERNATE_OBJECT_DIRECTORIES:SHA1_FILE_DIRECTORIES
  17GIT_OBJECT_DIRECTORY:SHA1_FILE_DIRECTORY
  18'
  19
  20. ./test-lib.sh
  21
  22export_them () {
  23        for ev in $env_vars
  24        do
  25                new=$(expr "$ev" : '\(.*\):')
  26                old=$(expr "$ev" : '.*:\(.*\)')
  27                # Build and eval the following:
  28                # case "${VAR+set}" in set) export VAR;; esac
  29                evstr='case "${'$new'+set}" in set) export '$new';; esac'
  30                eval "$evstr"
  31                evstr='case "${'$old'+set}" in set) export '$old';; esac'
  32                eval "$evstr"
  33        done
  34}
  35
  36date >path0
  37git-update-cache --add path0
  38tree=$(git-write-tree)
  39
  40AUTHOR_DATE='Wed May 11 23:55:18 2005'
  41AUTHOR_EMAIL='author@example.xz'
  42AUTHOR_NAME='A U Thor'
  43COMMIT_AUTHOR_EMAIL='author@example.xz'
  44COMMIT_AUTHOR_NAME='A U Thor'
  45SHA1_FILE_DIRECTORY=.git/objects
  46
  47export_them
  48
  49echo 'foo' | git-commit-tree $tree >/dev/null 2>errmsg
  50cat >expected-err <<\EOF
  51warning: Attempting to use SHA1_FILE_DIRECTORY
  52warning: GIT environment variables have been renamed.
  53warning: Please adjust your scripts and environment.
  54warning: old AUTHOR_DATE => new GIT_AUTHOR_DATE
  55warning: old AUTHOR_EMAIL => new GIT_AUTHOR_EMAIL
  56warning: old AUTHOR_NAME => new GIT_AUTHOR_NAME
  57warning: old COMMIT_AUTHOR_EMAIL => new GIT_COMMITTER_EMAIL
  58warning: old COMMIT_AUTHOR_NAME => new GIT_COMMITTER_NAME
  59warning: old SHA1_FILE_DIRECTORY => new GIT_OBJECT_DIRECTORY
  60EOF
  61sed -ne '/^warning: /p' <errmsg >generated-err
  62
  63test_expect_success \
  64    'using old names should issue warnings.' \
  65    'cmp generated-err expected-err'
  66
  67for ev in $env_vars
  68do
  69        new=$(expr "$ev" : '\(.*\):')
  70        old=$(expr "$ev" : '.*:\(.*\)')
  71        # Build and eval the following:
  72        # NEWENV=$OLDENV
  73        evstr="$new=\$$old"
  74        eval "$evstr"
  75done
  76export_them
  77echo 'foo' | git-commit-tree $tree >/dev/null 2>errmsg
  78sed -ne '/^warning: /p' <errmsg >generated-err
  79
  80test_expect_success \
  81    'using old names but having new names should not issue warnings.' \
  82    'cmp generated-err /dev/null'
  83
  84test_done