summaryrefslogtreecommitdiff
path: root/read-cache.c
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2019-04-09 23:07:37 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-04-10 03:52:50 (GMT)
commitf937bc2f86ba2c2956b4228bd2386aaafc9afe83 (patch)
treefa4e2f9e2fd08ab635b2eaede283bc8b649ee900 /read-cache.c
parentb22827045e0b6c2ae1b12be2820cdc4b7f750895 (diff)
downloadgit-f937bc2f86ba2c2956b4228bd2386aaafc9afe83.zip
git-f937bc2f86ba2c2956b4228bd2386aaafc9afe83.tar.gz
git-f937bc2f86ba2c2956b4228bd2386aaafc9afe83.tar.bz2
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 <kyle@kyleam.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'read-cache.c')
-rw-r--r--read-cache.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/read-cache.c b/read-cache.c
index 0e0c93e..5511a2b 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--;
}