about summary refs log tree commit diff
path: root/cgit.c
diff options
context:
space:
mode:
Diffstat (limited to 'cgit.c')
-rw-r--r--cgit.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/cgit.c b/cgit.c
index b270fdc..2c933dc 100644
--- a/cgit.c
+++ b/cgit.c
@@ -83,20 +83,23 @@ static void cgit_print_repo_page(struct cacheitem *item)
 	char *title, *tmp;
 	int show_search;
 	unsigned char sha1[20];
+	int nongit = 0;
 
-	if (chdir(ctx.repo->path)) {
-		title = fmt("%s - %s", ctx.cfg.root_title, "Bad request");
+	setenv("GIT_DIR", ctx.repo->path, 1);
+	setup_git_directory_gently(&nongit);
+	if (nongit) {
+		title = fmt("%s - %s", ctx.cfg.root_title, "config error");
+		tmp = fmt("Not a git repository: '%s'", ctx.repo->path);
+		ctx.repo = NULL;
 		cgit_print_docstart(title, item);
 		cgit_print_pageheader(title, 0);
-		cgit_print_error(fmt("Unable to scan repository: %s",
-				     strerror(errno)));
+		cgit_print_error(tmp);
 		cgit_print_docend();
 		return;
 	}
 
 	title = fmt("%s - %s", ctx.repo->name, ctx.repo->desc);
 	show_search = 0;
-	setenv("GIT_DIR", ctx.repo->path, 1);
 
 	if (!ctx.qry.head) {
 		ctx.qry.head = xstrdup(find_default_branch(ctx.repo));
@@ -179,10 +182,8 @@ static void cgit_print_repo_page(struct cacheitem *item)
 
 static void cgit_fill_cache(struct cacheitem *item, int use_cache)
 {
-	static char buf[PATH_MAX];
 	int stdout2;
 
-	getcwd(buf, sizeof(buf));
 	item->st.st_mtime = time(NULL);
 
 	if (use_cache) {
@@ -203,8 +204,6 @@ static void cgit_fill_cache(struct cacheitem *item, int use_cache)
 			     "Restoring original STDOUT");
 		chk_zero(close(stdout2), "Closing temporary STDOUT");
 	}
-
-	chdir(buf);
 }
 
 static void cgit_check_cache(struct cacheitem *item)
6 +0200'>2013-04-27git: update to 1.8.2.2John Keeping 2013-04-17scan-tree: fix regression in section-from-path=-1John Keeping 2013-04-15t0001: ignore ".dirty" suffix on Git versionJohn Keeping 2013-04-15tests: set TEST_OUTPUT_DIRECTORY to the CGit test directoryJohn Keeping 2013-04-15t0109: test more URLsJohn Keeping 2013-04-10cgitrc.5.txt: Specify when scan-path must be defined before.Jason A. Donenfeld 2013-04-10ui-snapshot.c: Prepend "V" when guessing ref namesLukas Fleischer 2013-04-10t0107: Skip ZIP tests if unzip(1) isn't availableLukas Fleischer 2013-04-10tests/: Do not use `sed -i`Lukas Fleischer 2013-04-10Add branch-sort and repo.branch-sort options.Jason A. Donenfeld 2013-04-10t0109: chain operations with &&John Keeping 2013-04-10cgit.c: Do not restore unset environment variablesLukas Fleischer 2013-04-09t0107: Use `tar -z` for gzip'ed archivesLukas Fleischer