git-config: handle --file option with relative pathname properly
When calling git-config not from the top level directory of a repository, it changes directory before trying to open the config file specified through the --file option, which then fails if the config file was specified by a relative pathname. This patch adjusts the pathname to the config file if applicable. The problem was noticed by Joey Hess, reported through http://bugs.debian.org/445208 Signed-off-by: Gerrit Pape <pape@smarden.org> Signed-off-by: Lars Hjemli <hjemli@gmail.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Gerrit Pape committed
Oct 12, 2007 at 11:32 UTC
1ae14a6b52f8f0506780cd361933f717163ae19b
1 file changed
+7
-2
builtin-config.c
+7
-2
@@ -165,7 +165,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
165
{
166
int nongit = 0;
167
char* value;
168
- setup_git_directory_gently(&nongit);
168
+ const char *file = setup_git_directory_gently(&nongit);
169
170
while (1 < argc) {
171
if (!strcmp(argv[1], "--int"))
@@ -192,7 +192,12 @@ int cmd_config(int argc, const char **argv, const char *prefix)
192
else if (!strcmp(argv[1], "--file") || !strcmp(argv[1], "-f")) {
193
if (argc < 3)
194
usage(git_config_set_usage);
195
- setenv(CONFIG_ENVIRONMENT, argv[2], 1);
195
+ if (!is_absolute_path(argv[2]) && file)
196
+ file = prefix_filename(file, strlen(file),
197
+ argv[2]);
198
+ else
199
+ file = argv[2];
200
+ setenv(CONFIG_ENVIRONMENT, file, 1);
201
argc--;
202
argv++;
203
}