aboutsummaryrefslogtreecommitdiffstats
path: root/read-cache.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2019-05-09 00:37:23 +0900
committerJunio C Hamano <gitster@pobox.com>2019-05-09 00:37:23 +0900
commit4ab701b2eec46ab5cbfe8c9732897e5d100184d8 (patch)
tree9e2001084537775407d1e4376ec9a0f5791d32d6 /read-cache.c
parenta1985623415223662a51b240e814d5f22b231830 (diff)
parentf937bc2f86ba2c2956b4228bd2386aaafc9afe83 (diff)
downloadgit-4ab701b2eec46ab5cbfe8c9732897e5d100184d8.tar.gz
Merge branch 'km/empty-repo-is-still-a-repo'
Running "git add" on a repository created inside the current repository is an explicit indication that the user wants to add it as a submodule, but when the HEAD of the inner repository is on an unborn branch, it cannot be added as a submodule. Worse, the files in its working tree can be added as if they are a part of the outer repository, which is not what the user wants. These problems are being addressed. * km/empty-repo-is-still-a-repo: add: error appropriately on repository with no commits dir: do not traverse repositories with no commits submodule: refuse to add repository with no commits
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 d5a74b1861..61b043bac3 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -709,6 +709,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;
@@ -718,6 +719,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--;
}