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