diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2015-07-24 23:04:20 +0300 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2015-07-24 23:04:20 +0300 |
commit | 759b2230a522df47640808cb0b21346cc824f6ff (patch) | |
tree | 2b91eae8b3536ddc2ed6c6b88ae175a92fcdc094 /src | |
parent | 91dad181439e0ea59bb84f8af9d7e144646f20c1 (diff) | |
parent | 247d27c2c6868e808191e6090056ecece6da30c4 (diff) |
Merge pull request #3303 from libgit2/cmn/index-add-submodule
Allow adding a submodule through git_index_add_bypath
Diffstat (limited to 'src')
-rw-r--r-- | src/blob.c | 6 | ||||
-rw-r--r-- | src/index.c | 24 |
2 files changed, 28 insertions, 2 deletions
diff --git a/src/blob.c b/src/blob.c index 07c4d92c8..ad0f4ac62 100644 --- a/src/blob.c +++ b/src/blob.c @@ -185,6 +185,12 @@ int git_blob__create_from_paths( (error = git_repository_odb(&odb, repo)) < 0) goto done; + if (S_ISDIR(st.st_mode)) { + giterr_set(GITERR_ODB, "cannot create blob from '%s'; it is a directory", content_path); + error = GIT_EDIRECTORY; + goto done; + } + if (out_st) memcpy(out_st, &st, sizeof(st)); diff --git a/src/index.c b/src/index.c index 5ce5522f8..501498e9e 100644 --- a/src/index.c +++ b/src/index.c @@ -1236,9 +1236,29 @@ int git_index_add_bypath(git_index *index, const char *path) assert(index && path); - if ((ret = index_entry_init(&entry, index, path)) < 0 || - (ret = index_insert(index, &entry, 1, false)) < 0) + if ((ret = index_entry_init(&entry, index, path)) == 0) + ret = index_insert(index, &entry, 1, false); + + /* If we were given a directory, let's see if it's a submodule */ + if (ret < 0 && ret != GIT_EDIRECTORY) + return ret; + + if (ret == GIT_EDIRECTORY) { + git_submodule *sm; + git_error_state err; + + giterr_capture(&err, ret); + + ret = git_submodule_lookup(&sm, INDEX_OWNER(index), path); + if (ret == GIT_ENOTFOUND) + return giterr_restore(&err); + else + git__free(err.error_msg.message); + + ret = git_submodule_add_to_index(sm, false); + git_submodule_free(sm); return ret; + } /* Adding implies conflict was resolved, move conflict entries to REUC */ if ((ret = index_conflict_to_reuc(index, path)) < 0 && ret != GIT_ENOTFOUND) |