MinGW tests: override 'pwd', too
[git/mingw/4msysgit/wingit-dll.git] / var.c
blob33457dc6ab1e9fcbcc311a0264793479619b5200
1 /*
2 * GIT - The information manager from hell
4 * Copyright (C) Eric Biederman, 2005
5 */
6 #include "cache.h"
7 #include "exec_cmd.h"
9 static const char var_usage[] = "git var [-l | <variable>]";
11 struct git_var {
12 const char *name;
13 const char *(*read)(int);
15 static struct git_var git_vars[] = {
16 { "GIT_COMMITTER_IDENT", git_committer_info },
17 { "GIT_AUTHOR_IDENT", git_author_info },
18 { "", NULL },
21 static void list_vars(void)
23 struct git_var *ptr;
24 for(ptr = git_vars; ptr->read; ptr++) {
25 printf("%s=%s\n", ptr->name, ptr->read(IDENT_WARN_ON_NO_NAME));
29 static const char *read_var(const char *var)
31 struct git_var *ptr;
32 const char *val;
33 val = NULL;
34 for(ptr = git_vars; ptr->read; ptr++) {
35 if (strcmp(var, ptr->name) == 0) {
36 val = ptr->read(IDENT_ERROR_ON_NO_NAME);
37 break;
40 return val;
43 static int show_config(const char *var, const char *value, void *cb)
45 if (value)
46 printf("%s=%s\n", var, value);
47 else
48 printf("%s\n", var);
49 return git_default_config(var, value, cb);
52 int main(int argc, char **argv)
54 const char *val;
55 int nongit;
56 if (argc != 2) {
57 usage(var_usage);
60 if (argv[0] && *argv[0])
61 git_extract_argv0_path(argv[0]);
63 setup_git_directory_gently(&nongit);
64 val = NULL;
66 if (strcmp(argv[1], "-l") == 0) {
67 git_config(show_config, NULL);
68 list_vars();
69 return 0;
71 git_config(git_default_config, NULL);
72 val = read_var(argv[1]);
73 if (!val)
74 usage(var_usage);
76 printf("%s\n", val);
78 return 0;