diff options
-rw-r--r-- | builtin/add.c | 3 | ||||
-rw-r--r-- | read-cache.c | 3 | ||||
-rwxr-xr-x | t/t3700-add.sh | 11 |
3 files changed, 16 insertions, 1 deletions
diff --git a/builtin/add.c b/builtin/add.c index db2dfa4350..dd18e5c9b6 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; diff --git a/read-cache.c b/read-cache.c index 0e0c93edc9..5511a2b14c 100644 --- a/read-cache.c +++ b/read-cache.c @@ -702,6 +702,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st, int add_option = (ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE| (intent_only ? ADD_CACHE_NEW_ONLY : 0)); int hash_flags = HASH_WRITE_OBJECT; + struct object_id oid; if (flags & ADD_CACHE_RENORMALIZE) hash_flags |= HASH_RENORMALIZE; @@ -711,6 +712,8 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st, namelen = strlen(path); if (S_ISDIR(st_mode)) { + if (resolve_gitlink_ref(path, "HEAD", &oid) < 0) + return error(_("'%s' does not have a commit checked out"), path); while (namelen && path[namelen-1] == '/') namelen--; } diff --git a/t/t3700-add.sh b/t/t3700-add.sh index 5a8425962b..c325167b90 100755 --- a/t/t3700-add.sh +++ b/t/t3700-add.sh @@ -296,6 +296,17 @@ test_expect_success '"git add ." in empty repo' ' ) ' +test_expect_success 'error on a repository with no commits' ' + rm -fr empty && + git init empty && + test_must_fail git add empty >actual 2>&1 && + cat >expect <<-EOF && + error: '"'empty/'"' does not have a commit checked out + fatal: adding files failed + EOF + test_i18ncmp expect actual +' + test_expect_success 'git add --dry-run of existing changed file' " echo new >>track-this && git add --dry-run track-this >actual 2>&1 && |