git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git-add says 'pathspec did not match any files' for git repository in /

From
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Date
Mar 25, 2011, 12:56 UTC
Message-ID
<20110325125635.GA28118@do>
In-Reply-To
<20110325100254.GH30350@login.drsnuggles.stderr.nl>
On Fri, Mar 25, 2011 at 11:02:54AM +0100, Matthijs Kooijman wrote:
Show 7 quoted lines
> Hey folks,
> 
> I've been using git for keeping config files using a repository in /.
> In 1.7.4.1, this seems to be broken again. Committing, diffing and
> status work this time, but git add gives a pathspec did not match any
> files error when adding a file while the current working directory is
> not /.

We have t1509 to guard these cases (and it does indeed show breakages). The problem is that the test requires chroot and cannot be run automatically. I need to think of writing better tests.

The following makes t1509 pass again for me. You may want to try and see if it fixes it for you.

diff --git a/setup.c b/setup.c
index 03cd84f..c18ea9c 100644
--- a/setup.c
+++ b/setup.c
@@ -390,15 +390,25 @@ static const char *setup_explicit_git_dir(const char *gitdirenv,
 		return NULL;
 	}
 
-	if (!prefixcmp(cwd, worktree) &&
-	    cwd[strlen(worktree)] == '/') { /* cwd inside worktree */
-		set_git_dir(real_path(gitdirenv));
-		if (chdir(worktree))
-			die_errno("Could not chdir to '%s'", worktree);
-		cwd[len++] = '/';
-		cwd[len] = '\0';
-		free(gitfile);
-		return cwd + strlen(worktree) + 1;
+	if (!prefixcmp(cwd, worktree)) {
+		if (strlen(worktree) == offset_1st_component(worktree)) {
+			set_git_dir(real_path(gitdirenv));
+			if (chdir(worktree))
+				die_errno("Could not chdir to '%s'", worktree);
+			cwd[len++] = '/';
+			cwd[len] = '\0';
+			free(gitfile);
+			return cwd + offset_1st_component(worktree);
+		}
+		if (cwd[strlen(worktree)] == '/') { /* cwd inside worktree */
+			set_git_dir(real_path(gitdirenv));
+			if (chdir(worktree))
+				die_errno("Could not chdir to '%s'", worktree);
+			cwd[len++] = '/';
+			cwd[len] = '\0';
+			free(gitfile);
+			return cwd + strlen(worktree) + 1;
+		}
 	}
 
 	/* cwd outside worktree */
-- 
Duy
Previous: Matthijs KooijmanNext: Nguyễn Thái Ngọc Duy
Message 2 of 7 in “git-add says 'pathspec did not match any files' for git repository in /”
  1. Matthijs KooijmanMar 25, 2011
  2. Nguyen Thai Ngoc DuyMar 25, 2011
  3. setup: return correct prefix if worktree is '/'Nguyễn Thái Ngọc Duy, Mar 25, 2011
  4. Michael J GruberMar 25, 2011
  5. Nguyen Thai Ngoc DuyMar 25, 2011
  6. dir.c: do not trip over difference in "/"Michael J Gruber, Mar 25, 2011
  7. Nguyen Thai Ngoc DuyMar 26, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.