From 9bda5fb8c1fa5d69616477f43b511b6f717115ec Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Tue, 18 Feb 2014 14:05:30 -0800 Subject: [PATCH 1/2] Improve error propagation in shallow call --- src/repository.c | 9 +++++---- tests/repo/shallow.c | 6 ++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/repository.c b/src/repository.c index 9f0c2f68f..89ae32473 100644 --- a/src/repository.c +++ b/src/repository.c @@ -2001,9 +2001,10 @@ int git_repository_is_shallow(git_repository *repo) error = git_path_lstat(path.ptr, &st); git_buf_free(&path); - if (error == GIT_ENOTFOUND) + if (error == GIT_ENOTFOUND) { + giterr_clear(); return 0; - if (error < 0) - return -1; - return st.st_size == 0 ? 0 : 1; + } + + return error < 0 ? error : st.st_size == 0 ? 0 : 1; } diff --git a/tests/repo/shallow.c b/tests/repo/shallow.c index 1cc66ae40..5aeaf2def 100644 --- a/tests/repo/shallow.c +++ b/tests/repo/shallow.c @@ -31,3 +31,9 @@ void test_repo_shallow__shallow_repo(void) cl_assert_equal_i(1, git_repository_is_shallow(g_repo)); } +void test_repo_shallow__clears_errors(void) +{ + g_repo = cl_git_sandbox_init("testrepo.git"); + cl_assert_equal_i(0, git_repository_is_shallow(g_repo)); + cl_assert_equal_p(NULL, giterr_last()); +} From 864535cf850973378c8283f62347055d2593c685 Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Tue, 18 Feb 2014 14:07:42 -0800 Subject: [PATCH 2/2] Readability --- src/repository.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/repository.c b/src/repository.c index 89ae32473..96ed30666 100644 --- a/src/repository.c +++ b/src/repository.c @@ -2006,5 +2006,7 @@ int git_repository_is_shallow(git_repository *repo) return 0; } - return error < 0 ? error : st.st_size == 0 ? 0 : 1; + if (error < 0) + return error; + return st.st_size == 0 ? 0 : 1; }