summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 06f6228)
raw | patch | inline | side by side (parent: 06f6228)
author | Johannes Schindelin <Johannes.Schindelin@gmx.de> | |
Sat, 20 Jan 2007 02:09:34 +0000 (03:09 +0100) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Sun, 21 Jan 2007 03:10:26 +0000 (19:10 -0800) |
For example, it makes no sense to check the presence of a file
named "HEAD" when calling "git log HEAD" in a bare repository.
Noticed by Han-Wen Nienhuys.
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
named "HEAD" when calling "git log HEAD" in a bare repository.
Noticed by Han-Wen Nienhuys.
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
cache.h | patch | blob | history | |
setup.c | patch | blob | history | |
t/t1020-subdirectory.sh | patch | blob | history |
index a218db3b30a6b1b41b1feada2f71d71ac1623d8e..473197ded840dcd05824a54e099522f38796371b 100644 (file)
--- a/cache.h
+++ b/cache.h
extern int is_bare_repository_cfg;
extern int is_bare_repository(void);
+extern int is_inside_git_dir(void);
extern const char *get_git_dir(void);
extern char *get_object_directory(void);
extern char *get_refs_directory(void);
index cc97f9f5c1b8ebfb21a4487d4c5b0ee972797779..e9d3f5aab63225df7f1b495a19740408d23973a8 100644 (file)
--- a/setup.c
+++ b/setup.c
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;
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];
if (chdir(cwd))
die("Cannot come back to cwd");
setenv(GIT_DIR_ENVIRONMENT, cwd, 1);
+ inside_git_dir = 1;
return NULL;
}
if (nongit_ok) {
offset++;
cwd[len++] = '/';
cwd[len] = 0;
+ inside_git_dir = !strncmp(cwd + offset, ".git/", 5);
return cwd + offset;
}
index 4409b87f8d9bf151883c1888ddc64c63b24d85c9..c090c96185c9826a752b87ce81af8d82056ede79 100755 (executable)
--- a/t/t1020-subdirectory.sh
+++ b/t/t1020-subdirectory.sh
cmp ../one ../original.one
'
+test_expect_success 'no file/rev ambuguity check inside .git' '
+ cd $HERE &&
+ git commit -a -m 1 &&
+ cd $HERE/.git &&
+ git show -s HEAD
+'
+
+test_expect_success 'no file/rev ambuguity check inside a bare repo' '
+ cd $HERE &&
+ git clone -s --bare .git foo.git &&
+ cd foo.git && GIT_DIR=. git show -s HEAD
+'
+
+# This still does not work as it should...
+: test_expect_success 'no file/rev ambuguity check inside a bare repo' '
+ cd $HERE &&
+ git clone -s --bare .git foo.git &&
+ cd foo.git && git show -s HEAD
+'
+
+test_expect_success 'detection should not be fooled by a symlink' '
+ cd $HERE &&
+ rm -fr foo.git &&
+ git clone -s .git another &&
+ ln -s another yetanother &&
+ cd yetanother/.git &&
+ git show -s HEAD
+'
+
test_done