Skip to contentSkip to conversation

ls-files: Give hints when errors happen.

PATCH New Andreas Ericsson 1 participant 1 message Aug 11, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ls-files: Give hints when errors happen.

Without this patch "git commit file.c file2.c" produces the not so stellar output:

error: pathspec 'file.c' did not match any.
error: pathspec 'file2.c' did not match any.

With this patch, the output is changed to:

error: pathspec 'file.c' did not match any file(s) known to git.
error: pathspec 'file2.c' did not match any file(s) known to git. Did you forget to 'git add'?

---
 builtin-ls-files.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
builtin-ls-files.c +5 -1
index ad8c41e..bc79ce4 100644
@@ -487,10 +487,14 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
 		for (num = 0; pathspec[num]; num++) {
 			if (ps_matched[num])
 				continue;
-			error("pathspec '%s' did not match any.",
+			error("pathspec '%s' did not match any file(s) known to git.",
 			      pathspec[num] + prefix_offset);
 			errors++;
 		}
+
+		if (errors)
+			fprintf(stderr, "Did you forget to 'git add'?\n");
+
 		return errors ? 1 : 0;
 	}
 
Signature · 1 line
1.4.4.1.GIT