diff options
| author | Carson Howard <carsonh@axosoft.com> | 2018-01-06 10:57:32 -0700 |
|---|---|---|
| committer | Carson Howard <tylerw+systemtest@axosoft.com> | 2018-03-27 07:29:04 -0700 |
| commit | b282ca7958568b0de41895d5cdc2bd8b8068b4a4 (patch) | |
| tree | 5b267fce55b50720cc0d92038b6a9919bc9a48d8 /src | |
| parent | 677d393c0b49238e9fba41b074fb9d7aa822b1aa (diff) | |
| download | libgit2-b282ca7958568b0de41895d5cdc2bd8b8068b4a4.tar.gz | |
submodule: change can_add_submodule to is_path_occupied
Diffstat (limited to 'src')
| -rw-r--r-- | src/submodule.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/submodule.c b/src/submodule.c index d1a0c822b..b9cdb197e 100644 --- a/src/submodule.c +++ b/src/submodule.c @@ -153,11 +153,12 @@ static int find_by_path(const git_config_entry *entry, void *payload) * Checks to see if the submodule shares its name with a file or directory that * already exists on the index. If so, the submodule cannot be added. */ -static int can_add_submodule(git_repository *repo, const char *path) +static int is_path_occupied(bool *occupied, git_repository *repo, const char *path) { int error = 0; git_index *index; git_buf dir = GIT_BUF_INIT; + *occupied = false; if ((error = git_repository_index__weakptr(&index, repo)) < 0) goto out; @@ -165,10 +166,9 @@ static int can_add_submodule(git_repository *repo, const char *path) if ((error = git_index_find(NULL, index, path)) == 0) { giterr_set(GITERR_SUBMODULE, "File '%s' already exists in the index", path); - error = GIT_EEXISTS; + *occupied = true; goto out; } - error = 0; if ((error = git_buf_sets(&dir, path)) < 0) goto out; @@ -179,8 +179,7 @@ static int can_add_submodule(git_repository *repo, const char *path) if ((error = git_index_find_prefix(NULL, index, dir.ptr)) == 0) { giterr_set(GITERR_SUBMODULE, "Directory '%s' already exists in the index", path); - error = GIT_EEXISTS; - goto out; + *occupied = true; } error = 0; @@ -704,6 +703,7 @@ int git_submodule_add_setup( git_submodule *sm = NULL; git_buf name = GIT_BUF_INIT, real_url = GIT_BUF_INIT; git_repository *subrepo = NULL; + bool path_occupied; assert(repo && url && path); @@ -728,9 +728,14 @@ int git_submodule_add_setup( goto cleanup; } - if ((error = can_add_submodule(repo, path)) < 0) + if ((error = is_path_occupied(&path_occupied, repo, path)) < 0) goto cleanup; + if (path_occupied) { + error = GIT_EEXISTS; + goto cleanup; + } + /* update .gitmodules */ if (!(mods = open_gitmodules(repo, GITMODULES_CREATE))) { |
