index cc97f9f5c1b8ebfb21a4487d4c5b0ee972797779..dda67d268dcacce2293d245395a38106860fb881 100644 (file)
--- a/setup.c
+++ b/setup.c
const char *name;
struct stat st;
const char *name;
struct stat st;
+ if (is_inside_git_dir())
+ return;
if (*arg == '-')
return; /* flag */
name = prefix ? prefix_filename(prefix, strlen(prefix), arg) : arg;
if (*arg == '-')
return; /* flag */
name = prefix ? prefix_filename(prefix, strlen(prefix), arg) : arg;
return 1;
}
return 1;
}
+static int inside_git_dir = -1;
+
+int is_inside_git_dir(void)
+{
+ if (inside_git_dir < 0) {
+ char buffer[1024];
+
+ if (is_bare_repository())
+ return (inside_git_dir = 1);
+ if (getcwd(buffer, sizeof(buffer))) {
+ const char *git_dir = get_git_dir(), *cwd = buffer;
+ while (*git_dir && *git_dir == *cwd) {
+ git_dir++;
+ cwd++;
+ }
+ inside_git_dir = !*git_dir;
+ } else
+ inside_git_dir = 0;
+ }
+ return inside_git_dir;
+}
+
const char *setup_git_directory_gently(int *nongit_ok)
{
static char cwd[PATH_MAX+1];
const char *setup_git_directory_gently(int *nongit_ok)
{
static char cwd[PATH_MAX+1];
if (chdir(cwd))
die("Cannot come back to cwd");
setenv(GIT_DIR_ENVIRONMENT, cwd, 1);
if (chdir(cwd))
die("Cannot come back to cwd");
setenv(GIT_DIR_ENVIRONMENT, cwd, 1);
+ inside_git_dir = 1;
return NULL;
}
if (nongit_ok) {
return NULL;
}
if (nongit_ok) {
offset++;
cwd[len++] = '/';
cwd[len] = 0;
offset++;
cwd[len++] = '/';
cwd[len] = 0;
+ inside_git_dir = !prefixcmp(cwd + offset, ".git/");
return cwd + offset;
}
return cwd + offset;
}