diff options
| author | Carson Howard <carsonh@axosoft.com> | 2018-03-28 06:48:55 -0700 |
|---|---|---|
| committer | Carson Howard <carsonh@axosoft.com> | 2018-03-28 06:48:55 -0700 |
| commit | 69a282da2713ddf524112910e27f8e874bcabd4d (patch) | |
| tree | fb5457e24b78f46430d536f572b1593368c5f3ef /src | |
| parent | c07abd6509cc1d22bcddd377c0e49de4e7c7ced9 (diff) | |
| download | libgit2-69a282da2713ddf524112910e27f8e874bcabd4d.tar.gz | |
submodule: add more robust error handling when a submodule path is found on add
Diffstat (limited to 'src')
| -rw-r--r-- | src/submodule.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/submodule.c b/src/submodule.c index cfde81a23..37434669c 100644 --- a/src/submodule.c +++ b/src/submodule.c @@ -163,10 +163,12 @@ static int is_path_occupied(bool *occupied, git_repository *repo, const char *pa if ((error = git_repository_index__weakptr(&index, repo)) < 0) goto out; - if ((error = git_index_find(NULL, index, path)) == 0) { - giterr_set(GITERR_SUBMODULE, - "File '%s' already exists in the index", path); - *occupied = true; + if ((error = git_index_find(NULL, index, path)) != GIT_ENOTFOUND) { + if (!error) { + giterr_set(GITERR_SUBMODULE, + "File '%s' already exists in the index", path); + *occupied = true; + } goto out; } @@ -176,14 +178,15 @@ static int is_path_occupied(bool *occupied, git_repository *repo, const char *pa if ((error = git_path_to_dir(&dir)) < 0) goto out; - if ((error = git_index_find_prefix(NULL, index, dir.ptr)) < 0 && error != GIT_ENOTFOUND) - goto out; - - if (!error) { - giterr_set(GITERR_SUBMODULE, - "Directory '%s' already exists in the index", path); - *occupied = true; + if ((error = git_index_find_prefix(NULL, index, dir.ptr)) != GIT_ENOTFOUND) { + if (!error) { + giterr_set(GITERR_SUBMODULE, + "Directory '%s' already exists in the index", path); + *occupied = true; + } + goto out; } + error = 0; out: |
