path: root/builtin/add.c
diff options
authorKyle Meyer <>2019-04-09 23:07:37 (GMT)
committerJunio C Hamano <>2019-04-10 03:52:50 (GMT)
commitf937bc2f86ba2c2956b4228bd2386aaafc9afe83 (patch)
treefa4e2f9e2fd08ab635b2eaede283bc8b649ee900 /builtin/add.c
parentb22827045e0b6c2ae1b12be2820cdc4b7f750895 (diff)
add: error appropriately on repository with no commits
The previous commit made 'git add' abort when given a repository that doesn't have a commit checked out. However, the output upon failure isn't appropriate: % git add repo warning: adding embedded git repository: repo hint: You've added another git repository inside your current repository. hint: [...] error: unable to index file 'repo/' fatal: adding files failed The hint doesn't apply in this case, and the error message doesn't tell the user why 'repo' couldn't be added to the index. Provide better output by teaching add_to_index() to error when given a git directory where HEAD can't be resolved. To avoid the embedded repository warning and hint, call check_embedded_repo() only after add_file_to_index() succeeds because, in general, its output doesn't make sense if adding to the index fails. Signed-off-by: Kyle Meyer <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'builtin/add.c')
1 files changed, 2 insertions, 1 deletions
diff --git a/builtin/add.c b/builtin/add.c
index db2dfa4..dd18e5c 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -374,11 +374,12 @@ static int add_files(struct dir_struct *dir, int flags)
for (i = 0; i < dir->nr; i++) {
- check_embedded_repo(dir->entries[i]->name);
if (add_file_to_index(&the_index, dir->entries[i]->name, flags)) {
if (!ignore_add_errors)
die(_("adding files failed"));
exit_status = 1;
+ } else {
+ check_embedded_repo(dir->entries[i]->name);
return exit_status;