diff options
32 files changed, 343 insertions, 104 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a010681b..32bb4502b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.5.1) project(libgit2 VERSION "1.3.0" LANGUAGES C) # Add find modules to the path -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake") # # Build options diff --git a/cmake/IdeSplitSources.cmake b/cmake/IdeSplitSources.cmake index 9e16cbc5f..4f928ac08 100644 --- a/cmake/IdeSplitSources.cmake +++ b/cmake/IdeSplitSources.cmake @@ -8,7 +8,7 @@ function(IDE_SPLIT_SOURCES target) get_target_property(sources ${target} SOURCES) foreach(source ${sources}) if(source MATCHES ".*/") - string(REPLACE ${CMAKE_SOURCE_DIR}/ "" rel ${source}) + string(REPLACE ${PROJECT_SOURCE_DIR}/ "" rel ${source}) if(rel) string(REGEX REPLACE "/([^/]*)$" "" rel ${rel}) if(rel) diff --git a/cmake/SelectHTTPParser.cmake b/cmake/SelectHTTPParser.cmake index ffc897fbc..bb6ef5517 100644 --- a/cmake/SelectHTTPParser.cmake +++ b/cmake/SelectHTTPParser.cmake @@ -12,8 +12,8 @@ if(USE_HTTP_PARSER STREQUAL "system") endif() else() message(STATUS "http-parser version 2 was not found or disabled; using bundled 3rd-party sources.") - add_subdirectory("${CMAKE_SOURCE_DIR}/deps/http-parser" "${CMAKE_BINARY_DIR}/deps/http-parser") - list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${CMAKE_SOURCE_DIR}/deps/http-parser") + add_subdirectory("${PROJECT_SOURCE_DIR}/deps/http-parser" "${PROJECT_BINARY_DIR}/deps/http-parser") + list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/http-parser") list(APPEND LIBGIT2_DEPENDENCY_OBJECTS "$<TARGET_OBJECTS:http-parser>") add_feature_info(http-parser ON "http-parser support (bundled)") endif() diff --git a/cmake/SelectRegex.cmake b/cmake/SelectRegex.cmake index 88aa156b7..2a3a91b8c 100644 --- a/cmake/SelectRegex.cmake +++ b/cmake/SelectRegex.cmake @@ -43,8 +43,8 @@ elseif(REGEX_BACKEND STREQUAL "builtin") add_feature_info(regex ON "using bundled PCRE") set(GIT_REGEX_BUILTIN 1) - add_subdirectory("${CMAKE_SOURCE_DIR}/deps/pcre" "${CMAKE_BINARY_DIR}/deps/pcre") - list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${CMAKE_SOURCE_DIR}/deps/pcre") + add_subdirectory("${PROJECT_SOURCE_DIR}/deps/pcre" "${PROJECT_BINARY_DIR}/deps/pcre") + list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/pcre") list(APPEND LIBGIT2_DEPENDENCY_OBJECTS $<TARGET_OBJECTS:pcre>) else() message(FATAL_ERROR "The REGEX_BACKEND option provided is not supported") diff --git a/cmake/SelectWinHTTP.cmake b/cmake/SelectWinHTTP.cmake index 38642e136..96e0bdbae 100644 --- a/cmake/SelectWinHTTP.cmake +++ b/cmake/SelectWinHTTP.cmake @@ -4,9 +4,9 @@ if(WIN32 AND USE_WINHTTP) # Since MinGW does not come with headers or an import library for winhttp, # we have to include a private header and generate our own import library if(MINGW) - add_subdirectory("${CMAKE_SOURCE_DIR}/deps/winhttp" "${CMAKE_BINARY_DIR}/deps/winhttp") + add_subdirectory("${PROJECT_SOURCE_DIR}/deps/winhttp" "${PROJECT_BINARY_DIR}/deps/winhttp") list(APPEND LIBGIT2_SYSTEM_LIBS winhttp) - list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${CMAKE_SOURCE_DIR}/deps/winhttp") + list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/winhttp") else() list(APPEND LIBGIT2_SYSTEM_LIBS "winhttp") list(APPEND LIBGIT2_PC_LIBS "-lwinhttp") diff --git a/cmake/SelectZlib.cmake b/cmake/SelectZlib.cmake index 0de1d4a98..fb4361abc 100644 --- a/cmake/SelectZlib.cmake +++ b/cmake/SelectZlib.cmake @@ -22,13 +22,13 @@ if(USE_BUNDLED_ZLIB STREQUAL "OFF") endif() endif() if(USE_BUNDLED_ZLIB STREQUAL "Chromium") - add_subdirectory("${CMAKE_SOURCE_DIR}/deps/chromium-zlib" "${CMAKE_BINARY_DIR}/deps/chromium-zlib") - list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${CMAKE_SOURCE_DIR}/deps/chromium-zlib") + add_subdirectory("${PROJECT_SOURCE_DIR}/deps/chromium-zlib" "${PROJECT_BINARY_DIR}/deps/chromium-zlib") + list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/chromium-zlib") list(APPEND LIBGIT2_DEPENDENCY_OBJECTS $<TARGET_OBJECTS:chromium_zlib>) add_feature_info(zlib ON "using (Chromium) bundled zlib") elseif(USE_BUNDLED_ZLIB OR NOT ZLIB_FOUND) - add_subdirectory("${CMAKE_SOURCE_DIR}/deps/zlib" "${CMAKE_BINARY_DIR}/deps/zlib") - list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${CMAKE_SOURCE_DIR}/deps/zlib") + add_subdirectory("${PROJECT_SOURCE_DIR}/deps/zlib" "${PROJECT_BINARY_DIR}/deps/zlib") + list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/zlib") list(APPEND LIBGIT2_DEPENDENCY_OBJECTS $<TARGET_OBJECTS:zlib>) add_feature_info(zlib ON "using bundled zlib") endif() diff --git a/deps/ntlmclient/ntlm.c b/deps/ntlmclient/ntlm.c index 3393be915..ad4de5de5 100644 --- a/deps/ntlmclient/ntlm.c +++ b/deps/ntlmclient/ntlm.c @@ -930,10 +930,10 @@ const char *ntlm_client_target_domain_dns(ntlm_client *ntlm) } #define EVEN_PARITY(a) \ - (!!((a) & 0x01ll) ^ !!((a) & 0x02ll) ^ \ - !!((a) & 0x04ll) ^ !!((a) & 0x08ll) ^ \ - !!((a) & 0x10ll) ^ !!((a) & 0x20ll) ^ \ - !!((a) & 0x40ll) ^ !!((a) & 0x80ll)) + (!!((a) & INT64_C(0x01)) ^ !!((a) & INT64_C(0x02)) ^ \ + !!((a) & INT64_C(0x04)) ^ !!((a) & INT64_C(0x08)) ^ \ + !!((a) & INT64_C(0x10)) ^ !!((a) & INT64_C(0x20)) ^ \ + !!((a) & INT64_C(0x40)) ^ !!((a) & INT64_C(0x80))) static void generate_odd_parity(ntlm_des_block *block) { diff --git a/deps/winhttp/CMakeLists.txt b/deps/winhttp/CMakeLists.txt index c11a867a8..1a87989b9 100644 --- a/deps/winhttp/CMakeLists.txt +++ b/deps/winhttp/CMakeLists.txt @@ -3,7 +3,7 @@ if(NOT DLLTOOL) message(FATAL_ERROR "Could not find dlltool command") endif() -set(LIBWINHTTP_PATH "${CMAKE_BINARY_DIR}/deps/winhttp") +set(LIBWINHTTP_PATH "${PROJECT_BINARY_DIR}/deps/winhttp") set(LIBWINHTTP_PATH ${LIBWINHTTP_PATH} PARENT_SCOPE) file(MAKE_DIRECTORY ${LIBWINHTTP_PATH}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 03609b681..98881b5ad 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,8 +36,8 @@ set(LIBGIT2_PC_LIBS "") set(LIBGIT2_INCLUDES "${CMAKE_CURRENT_BINARY_DIR}" - "${CMAKE_SOURCE_DIR}/src" - "${CMAKE_SOURCE_DIR}/include") + "${PROJECT_SOURCE_DIR}/src" + "${PROJECT_SOURCE_DIR}/include") if(HAVE_FUTIMENS) set(GIT_USE_FUTIMENS 1) @@ -117,8 +117,8 @@ target_sources(git2internal PRIVATE ${SRC_SHA1}) # Optional external dependency: ntlmclient if(USE_NTLMCLIENT) set(GIT_NTLM 1) - add_subdirectory("${CMAKE_SOURCE_DIR}/deps/ntlmclient" "${CMAKE_BINARY_DIR}/deps/ntlmclient") - list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${CMAKE_SOURCE_DIR}/deps/ntlmclient") + add_subdirectory("${PROJECT_SOURCE_DIR}/deps/ntlmclient" "${PROJECT_BINARY_DIR}/deps/ntlmclient") + list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/ntlmclient") list(APPEND LIBGIT2_DEPENDENCY_OBJECTS "$<TARGET_OBJECTS:ntlmclient>") endif() add_feature_info(ntlmclient GIT_NTLM "NTLM authentication support for Unix") @@ -164,9 +164,9 @@ target_compile_definitions(git2internal PRIVATE _FILE_OFFSET_BITS=64) # Collect sourcefiles file(GLOB SRC_H - "${CMAKE_SOURCE_DIR}/include/git2.h" - "${CMAKE_SOURCE_DIR}/include/git2/*.h" - "${CMAKE_SOURCE_DIR}/include/git2/sys/*.h") + "${PROJECT_SOURCE_DIR}/include/git2.h" + "${PROJECT_SOURCE_DIR}/include/git2/*.h" + "${PROJECT_SOURCE_DIR}/include/git2/sys/*.h") list(SORT SRC_H) target_sources(git2internal PRIVATE ${SRC_H}) @@ -225,7 +225,7 @@ configure_file(features.h.in git2/sys/features.h) ide_split_sources(git2internal) list(APPEND LIBGIT2_OBJECTS $<TARGET_OBJECTS:git2internal> ${LIBGIT2_DEPENDENCY_OBJECTS}) -target_include_directories(git2internal PRIVATE ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES} PUBLIC ${CMAKE_SOURCE_DIR}/include) +target_include_directories(git2internal PRIVATE ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES} PUBLIC ${PROJECT_SOURCE_DIR}/include) target_include_directories(git2internal SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES}) set(LIBGIT2_INCLUDES ${LIBGIT2_INCLUDES} PARENT_SCOPE) @@ -247,9 +247,9 @@ add_library(git2 ${WIN_RC} ${LIBGIT2_OBJECTS}) target_link_libraries(git2 ${LIBGIT2_SYSTEM_LIBS}) set_target_properties(git2 PROPERTIES C_STANDARD 90) -set_target_properties(git2 PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) -set_target_properties(git2 PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) -set_target_properties(git2 PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) +set_target_properties(git2 PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) +set_target_properties(git2 PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) +set_target_properties(git2 PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) # Workaround for Cmake bug #0011240 (see http://public.kitware.com/Bug/view.php?id=11240) # Win64+MSVC+static libs = linker error @@ -290,5 +290,5 @@ install(TARGETS git2 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ) -install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/git2 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) -install(FILES ${CMAKE_SOURCE_DIR}/include/git2.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/git2 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +install(FILES ${PROJECT_SOURCE_DIR}/include/git2.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) diff --git a/src/commit.c b/src/commit.c index ceaccb331..b137463f3 100644 --- a/src/commit.c +++ b/src/commit.c @@ -547,7 +547,7 @@ const char *git_commit_message(const git_commit *commit) const char *git_commit_summary(git_commit *commit) { git_str summary = GIT_STR_INIT; - const char *msg, *space; + const char *msg, *space, *next; bool space_contains_newline = false; GIT_ASSERT_ARG_WITH_RETVAL(commit, NULL); @@ -556,10 +556,21 @@ const char *git_commit_summary(git_commit *commit) for (msg = git_commit_message(commit), space = NULL; *msg; ++msg) { char next_character = msg[0]; /* stop processing at the end of the first paragraph */ - if (next_character == '\n' && (!msg[1] || msg[1] == '\n')) - break; + if (next_character == '\n') { + if (!msg[1]) + break; + if (msg[1] == '\n') + break; + /* stop processing if next line contains only whitespace */ + next = msg + 1; + while (*next && git__isspace_nonlf(*next)) { + ++next; + } + if (!*next || *next == '\n') + break; + } /* record the beginning of contiguous whitespace runs */ - else if (git__isspace(next_character)) { + if (git__isspace(next_character)) { if(space == NULL) { space = msg; space_contains_newline = false; diff --git a/src/commit_graph.c b/src/commit_graph.c index 924a3992b..292250f65 100644 --- a/src/commit_graph.c +++ b/src/commit_graph.c @@ -1075,11 +1075,11 @@ static int commit_graph_write( commit_time = (uint64_t)packed_commit->commit_time; if (generation > GIT_COMMIT_GRAPH_GENERATION_NUMBER_MAX) generation = GIT_COMMIT_GRAPH_GENERATION_NUMBER_MAX; - word = ntohl((uint32_t)((generation << 2) | ((commit_time >> 32ull) & 0x3ull))); + word = ntohl((uint32_t)((generation << 2) | (((uint32_t)(commit_time >> 32)) & 0x3) )); error = git_str_put(&commit_data, (const char *)&word, sizeof(word)); if (error < 0) goto cleanup; - word = ntohl((uint32_t)(commit_time & 0xffffffffull)); + word = ntohl((uint32_t)(commit_time & 0xfffffffful)); error = git_str_put(&commit_data, (const char *)&word, sizeof(word)); if (error < 0) goto cleanup; diff --git a/src/config_parse.c b/src/config_parse.c index 3159cbef7..06931368e 100644 --- a/src/config_parse.c +++ b/src/config_parse.c @@ -36,7 +36,7 @@ static int strip_comments(char *line, int in_quotes) char *ptr; for (ptr = line; *ptr; ++ptr) { - if (ptr[0] == '"' && ptr > line && ptr[-1] != '\\') + if (ptr[0] == '"' && ((ptr > line && ptr[-1] != '\\') || ptr == line)) quote_count++; if ((ptr[0] == ';' || ptr[0] == '#') && @@ -325,7 +325,7 @@ done: return 0; } -static int parse_multiline_variable(git_config_parser *reader, git_str *value, int in_quotes) +static int parse_multiline_variable(git_config_parser *reader, git_str *value, int in_quotes, size_t *line_len) { int quote_count; bool multiline = true; @@ -338,6 +338,10 @@ static int parse_multiline_variable(git_config_parser *reader, git_str *value, i git_parse_advance_line(&reader->ctx); line = git__strndup(reader->ctx.line, reader->ctx.line_len); GIT_ERROR_CHECK_ALLOC(line); + if (GIT_ADD_SIZET_OVERFLOW(line_len, *line_len, reader->ctx.line_len)) { + error = -1; + goto out; + } /* * We've reached the end of the file, there is no continuation. @@ -415,7 +419,7 @@ static int parse_name( return 0; } -static int parse_variable(git_config_parser *reader, char **var_name, char **var_value) +static int parse_variable(git_config_parser *reader, char **var_name, char **var_value, size_t *line_len) { const char *value_start = NULL; char *line = NULL, *name = NULL, *value = NULL; @@ -449,7 +453,7 @@ static int parse_variable(git_config_parser *reader, char **var_name, char **var git_str_attach(&multi_value, value, 0); value = NULL; - if (parse_multiline_variable(reader, &multi_value, quote_count % 2) < 0 || + if (parse_multiline_variable(reader, &multi_value, quote_count % 2, line_len) < 0 || git_str_oom(&multi_value)) { error = -1; git_str_dispose(&multi_value); @@ -554,7 +558,7 @@ int git_config_parse( break; default: /* assume variable declaration */ - if ((result = parse_variable(parser, &var_name, &var_value)) == 0 && on_variable) { + if ((result = parse_variable(parser, &var_name, &var_value, &line_len)) == 0 && on_variable) { result = on_variable(parser, current_section, var_name, var_value, line_start, line_len, payload); git__free(var_name); git__free(var_value); diff --git a/src/date.c b/src/date.c index 1529276e2..0e5ffc96b 100644 --- a/src/date.c +++ b/src/date.c @@ -853,7 +853,7 @@ static git_time_t approxidate_str(const char *date, } pending_number(&tm, &number); if (!touched) - *error_ret = 1; + *error_ret = -1; return update_tm(&tm, &now, 0); } @@ -872,7 +872,7 @@ int git_date_parse(git_time_t *out, const char *date) return -1; *out = approxidate_str(date, time_sec, &error_ret); - return error_ret; + return error_ret; } int git_date_rfc2822_fmt(git_str *out, git_time_t time, int offset) diff --git a/src/remote.c b/src/remote.c index bde4ce779..fb9f6f8da 100644 --- a/src/remote.c +++ b/src/remote.c @@ -30,7 +30,7 @@ static int dwim_refspecs(git_vector *out, git_vector *refspecs, git_vector *refs); static int lookup_remote_prune_config(git_remote *remote, git_config *config, const char *name); -char *apply_insteadof(git_config *config, const char *url, int direction); +char *apply_insteadof(bool *matched, git_config *config, const char *url, int direction); static int add_refspec_to(git_vector *vector, const char *string, bool is_fetch) { @@ -210,7 +210,9 @@ int git_remote_create_with_opts(git_remote **out, const char *url, const git_rem git_str var = GIT_STR_INIT; git_str specbuf = GIT_STR_INIT; const git_remote_create_options dummy_opts = GIT_REMOTE_CREATE_OPTIONS_INIT; + char *tmp; int error = -1; + bool matched; GIT_ASSERT_ARG(out); GIT_ASSERT_ARG(url); @@ -245,7 +247,12 @@ int git_remote_create_with_opts(git_remote **out, const char *url, const git_rem goto on_error; if (opts->repository && !(opts->flags & GIT_REMOTE_CREATE_SKIP_INSTEADOF)) { - remote->url = apply_insteadof(config_ro, canonical_url.ptr, GIT_DIRECTION_FETCH); + remote->url = apply_insteadof(&matched, config_ro, canonical_url.ptr, GIT_DIRECTION_FETCH); + tmp = apply_insteadof(&matched, config_ro, canonical_url.ptr, GIT_DIRECTION_PUSH); + if (matched) { + remote->pushurl = tmp; + GIT_ERROR_CHECK_ALLOC(remote->pushurl); + } } else { remote->url = git__strdup(canonical_url.ptr); } @@ -457,7 +464,9 @@ int git_remote_lookup(git_remote **out, git_repository *repo, const char *name) git_remote *remote = NULL; git_str buf = GIT_STR_INIT; const char *val; + char *tmp; int error = 0; + bool matched; git_config *config; struct refspec_cb_data data = { NULL }; bool optional_setting_found = false, found; @@ -498,8 +507,13 @@ int git_remote_lookup(git_remote **out, git_repository *repo, const char *name) remote->download_tags = GIT_REMOTE_DOWNLOAD_TAGS_AUTO; if (found && strlen(val) > 0) { - remote->url = apply_insteadof(config, val, GIT_DIRECTION_FETCH); + remote->url = apply_insteadof(&matched, config, val, GIT_DIRECTION_FETCH); GIT_ERROR_CHECK_ALLOC(remote->url); + tmp = apply_insteadof(&matched, config, val, GIT_DIRECTION_PUSH); + if (matched) { + remote->pushurl = tmp; + GIT_ERROR_CHECK_ALLOC(remote->pushurl); + } } val = NULL; @@ -518,7 +532,10 @@ int git_remote_lookup(git_remote **out, git_repository *repo, const char *name) } if (found && strlen(val) > 0) { - remote->pushurl = apply_insteadof(config, val, GIT_DIRECTION_PUSH); + if (remote->pushurl) { + git__free(remote->pushurl); + } + remote->pushurl = apply_insteadof(&matched, config, val, GIT_DIRECTION_FETCH); GIT_ERROR_CHECK_ALLOC(remote->pushurl); } @@ -2719,7 +2736,7 @@ int git_remote_push(git_remote *remote, const git_strarray *refspecs, const git_ #define SUFFIX_FETCH "insteadof" #define SUFFIX_PUSH "pushinsteadof" -char *apply_insteadof(git_config *config, const char *url, int direction) +char *apply_insteadof(bool *matched, git_config *config, const char *url, int direction) { size_t match_length, prefix_length, suffix_length; char *replacement = NULL; @@ -2732,6 +2749,8 @@ char *apply_insteadof(git_config *config, const char *url, int direction) GIT_ASSERT_ARG_WITH_RETVAL(config, NULL); GIT_ASSERT_ARG_WITH_RETVAL(url, NULL); GIT_ASSERT_ARG_WITH_RETVAL(direction == GIT_DIRECTION_FETCH || direction == GIT_DIRECTION_PUSH, NULL); + GIT_ASSERT_ARG_WITH_RETVAL(matched, NULL); + *matched = 0; /* Add 1 to prefix/suffix length due to the additional escaped dot */ prefix_length = strlen(PREFIX) + 1; @@ -2777,6 +2796,7 @@ char *apply_insteadof(git_config *config, const char *url, int direction) git__free(replacement); + *matched = 1; return result.ptr; } diff --git a/src/revparse.c b/src/revparse.c index 52dd0720b..5d3ff77ed 100644 --- a/src/revparse.c +++ b/src/revparse.c @@ -208,7 +208,7 @@ static int retrieve_oid_from_reflog(git_oid *oid, git_reference *ref, size_t ide { git_reflog *reflog; size_t numentries; - const git_reflog_entry *entry; + const git_reflog_entry *entry = NULL; bool search_by_pos = (identifier <= 100000000); if (git_reflog_read(&reflog, git_reference_owner(ref), git_reference_name(ref)) < 0) @@ -237,8 +237,15 @@ static int retrieve_oid_from_reflog(git_oid *oid, git_reference *ref, size_t ide break; } - if (i == numentries) - goto notfound; + if (i == numentries) { + if (entry == NULL) + goto notfound; + + /* + * TODO: emit a warning (log for 'branch' only goes back to ...) + */ + git_oid_cpy(oid, git_reflog_entry_id_new(entry)); + } } git_reflog_free(reflog); @@ -345,8 +352,10 @@ static int handle_at_syntax(git_object **out, git_reference **ref, const char *s goto cleanup; } - if (git_date_parse(×tamp, curly_braces_content) < 0) + if (git_date_parse(×tamp, curly_braces_content) < 0) { + error = GIT_EINVALIDSPEC; goto cleanup; + } error = retrieve_revobject_from_reflog(out, ref, repo, git_str_cstr(&identifier), (size_t)timestamp); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2272dec98..fdf194d0e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -38,7 +38,7 @@ set_source_files_properties( add_executable(libgit2_tests ${SRC_CLAR} ${SRC_TEST} ${LIBGIT2_OBJECTS}) set_target_properties(libgit2_tests PROPERTIES C_STANDARD 90) -set_target_properties(libgit2_tests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) +set_target_properties(libgit2_tests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) target_include_directories(libgit2_tests PRIVATE ${TEST_INCLUDES} ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES}) target_include_directories(libgit2_tests SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES}) @@ -62,9 +62,9 @@ endif() function(ADD_CLAR_TEST name) if(NOT USE_LEAK_CHECKER STREQUAL "OFF") - add_test(${name} "${CMAKE_SOURCE_DIR}/script/${USE_LEAK_CHECKER}.sh" "${CMAKE_BINARY_DIR}/libgit2_tests" ${ARGN}) + add_test(${name} "${PROJECT_SOURCE_DIR}/script/${USE_LEAK_CHECKER}.sh" "${PROJECT_BINARY_DIR}/libgit2_tests" ${ARGN}) else() - add_test(${name} "${CMAKE_BINARY_DIR}/libgit2_tests" ${ARGN}) + add_test(${name} "${PROJECT_BINARY_DIR}/libgit2_tests" ${ARGN}) endif() endfunction(ADD_CLAR_TEST) diff --git a/tests/commit/commit.c b/tests/commit/commit.c index d4e333b6a..fd574f7f2 100644 --- a/tests/commit/commit.c +++ b/tests/commit/commit.c @@ -139,8 +139,11 @@ void test_commit_commit__summary(void) { assert_commit_summary("One-liner with no trailing newline", "One-liner with no trailing newline"); assert_commit_summary("One-liner with trailing newline", "One-liner with trailing newline\n"); + assert_commit_summary("One-liner with trailing newline and space", "One-liner with trailing newline and space\n "); assert_commit_summary("Trimmed leading&trailing newlines", "\n\nTrimmed leading&trailing newlines\n\n"); assert_commit_summary("First paragraph only", "\nFirst paragraph only\n\n(There are more!)"); + assert_commit_summary("First paragraph only with space in the next line", "\nFirst paragraph only with space in the next line\n \n(There are more!)"); + assert_commit_summary("First paragraph only with spaces in the next line", "\nFirst paragraph only with spaces in the next line\n \n(There are more!)"); assert_commit_summary("First paragraph with unwrapped trailing\tlines", "\nFirst paragraph\nwith unwrapped\ntrailing\tlines\n\n(Yes, unwrapped!)"); assert_commit_summary("\tLeading tabs", "\tLeading\n\ttabs\n\nare preserved"); /* tabs around newlines are collapsed down to a single space */ assert_commit_summary(" Leading Spaces", " Leading\n Spaces\n\nare preserved"); /* spaces around newlines are collapsed down to a single space */ diff --git a/tests/config/read.c b/tests/config/read.c index 3c96f8519..a2e668c20 100644 --- a/tests/config/read.c +++ b/tests/config/read.c @@ -209,6 +209,21 @@ void test_config_read__symbol_headers(void) { git_config *cfg; cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config20"))); + cl_git_pass(git_config_get_string_buf(&buf, cfg, "valid.[subsection].something")); + cl_assert_equal_s("a", buf.ptr); + git_buf_dispose(&buf); + cl_git_pass(git_config_get_string_buf(&buf, cfg, "sec.[subsec]/child.parent")); + cl_assert_equal_s("grand", buf.ptr); + git_buf_dispose(&buf); + cl_git_pass(git_config_get_string_buf(&buf, cfg, "sec2.[subsec2]/child2.type")); + cl_assert_equal_s("dvcs", buf.ptr); + git_buf_dispose(&buf); + cl_git_pass(git_config_get_string_buf(&buf, cfg, "sec3.escape\"quote.vcs")); + cl_assert_equal_s("git", buf.ptr); + git_buf_dispose(&buf); + cl_git_pass(git_config_get_string_buf(&buf, cfg, "sec4.escaping\\slash.lib")); + cl_assert_equal_s("git2", buf.ptr); + git_buf_dispose(&buf); git_config_free(cfg); } @@ -219,6 +234,19 @@ void test_config_read__multiline_multiple_quoted_comment_chars(void) git_config_free(cfg); } +void test_config_read__multiline_multiple_quoted_quote_at_beginning_of_line(void) +{ + git_config* cfg; + cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config22"))); + cl_git_pass(git_config_get_string_buf(&buf, cfg, "alias.m")); + cl_assert_equal_s("cmd ;; ;; bar", buf.ptr); + git_buf_dispose(&buf); + cl_git_pass(git_config_get_string_buf(&buf, cfg, "alias.m2")); + cl_assert_equal_s("'; ; something '", buf.ptr); + git_buf_dispose(&buf); + git_config_free(cfg); +} + void test_config_read__header_in_last_line(void) { git_config *cfg; diff --git a/tests/config/write.c b/tests/config/write.c index 4ee83833f..9d8c3fe94 100644 --- a/tests/config/write.c +++ b/tests/config/write.c @@ -8,6 +8,7 @@ void test_config_write__initialize(void) cl_fixture_sandbox("config/config9"); cl_fixture_sandbox("config/config15"); cl_fixture_sandbox("config/config17"); + cl_fixture_sandbox("config/config22"); } void test_config_write__cleanup(void) @@ -15,6 +16,7 @@ void test_config_write__cleanup(void) cl_fixture_cleanup("config9"); cl_fixture_cleanup("config15"); cl_fixture_cleanup("config17"); + cl_fixture_cleanup("config22"); } void test_config_write__replace_value(void) @@ -743,3 +745,20 @@ void test_config_write__preserve_case(void) git_config_free(cfg); } + +void test_config_write__write_config_file_with_multi_line_value(void) +{ + git_config* cfg; + git_buf buf = GIT_BUF_INIT; + + cl_git_pass(git_config_open_ondisk(&cfg, "config22")); + cl_git_pass(git_config_get_string_buf(&buf, cfg, "alias.m")); + cl_assert_equal_s("cmd ;; ;; bar", buf.ptr); + cl_git_pass(git_config_set_string(cfg, "sOMe.ThInG", "foo")); + git_buf_dispose(&buf); + cl_git_pass(git_config_get_string_buf(&buf, cfg, "alias.m")); + cl_assert_equal_s("cmd ;; ;; bar", buf.ptr); + git_buf_dispose(&buf); + + git_config_free(cfg); +} diff --git a/tests/date/date.c b/tests/date/date.c index f70b4fea9..82b5c6728 100644 --- a/tests/date/date.c +++ b/tests/date/date.c @@ -13,3 +13,10 @@ void test_date_date__overflow(void) cl_assert(d2038 < d2039); #endif } + +void test_date_date__invalid_date(void) +{ + git_time_t d; + cl_git_fail(git_date_parse(&d, "")); + cl_git_fail(git_date_parse(&d, "NEITHER_INTEGER_NOR_DATETIME")); +} diff --git a/tests/fetchhead/nonetwork.c b/tests/fetchhead/nonetwork.c index 0e446d94e..ab31d3610 100644 --- a/tests/fetchhead/nonetwork.c +++ b/tests/fetchhead/nonetwork.c @@ -508,7 +508,7 @@ void test_fetchhead_nonetwork__create_with_multiple_refspecs(void) int i; struct prefix_count prefix_counts[] = { {"refs/notes/", 0, 1}, - {"refs/heads/", 0, 12}, + {"refs/heads/", 0, 13}, {"refs/tags/", 0, 7}, {NULL, 0, 0}, }; diff --git a/tests/network/fetchlocal.c b/tests/network/fetchlocal.c index e299d3ec8..c54f45472 100644 --- a/tests/network/fetchlocal.c +++ b/tests/network/fetchlocal.c @@ -45,7 +45,7 @@ void test_network_fetchlocal__complete(void) cl_git_pass(git_remote_fetch(origin, NULL, &options, NULL)); cl_git_pass(git_reference_list(&refnames, repo)); - cl_assert_equal_i(19, (int)refnames.count); + cl_assert_equal_i(20, (int)refnames.count); cl_assert(callcount > 0); git_strarray_dispose(&refnames); @@ -74,7 +74,7 @@ void test_network_fetchlocal__prune(void) cl_git_pass(git_remote_fetch(origin, NULL, &options, NULL)); cl_git_pass(git_reference_list(&refnames, repo)); - cl_assert_equal_i(19, (int)refnames.count); + cl_assert_equal_i(20, (int)refnames.count); cl_assert(callcount > 0); git_strarray_dispose(&refnames); git_remote_free(origin); @@ -88,7 +88,7 @@ void test_network_fetchlocal__prune(void) cl_git_pass(git_remote_prune(origin, &options.callbacks)); cl_git_pass(git_reference_list(&refnames, repo)); - cl_assert_equal_i(18, (int)refnames.count); + cl_assert_equal_i(19, (int)refnames.count); git_strarray_dispose(&refnames); git_remote_free(origin); @@ -101,7 +101,7 @@ void test_network_fetchlocal__prune(void) cl_git_pass(git_remote_prune(origin, &options.callbacks)); cl_git_pass(git_reference_list(&refnames, repo)); - cl_assert_equal_i(17, (int)refnames.count); + cl_assert_equal_i(18, (int)refnames.count); git_strarray_dispose(&refnames); git_remote_free(origin); @@ -166,7 +166,7 @@ void test_network_fetchlocal__prune_overlapping(void) assert_ref_exists(repo, "refs/remotes/origin/master"); assert_ref_exists(repo, "refs/remotes/origin/pr/42"); cl_git_pass(git_reference_list(&refnames, repo)); - cl_assert_equal_i(20, (int)refnames.count); + cl_assert_equal_i(21, (int)refnames.count); git_strarray_dispose(&refnames); cl_git_pass(git_config_delete_multivar(config, "remote.origin.fetch", "refs")); @@ -181,7 +181,7 @@ void test_network_fetchlocal__prune_overlapping(void) assert_ref_exists(repo, "refs/remotes/origin/master"); assert_ref_exists(repo, "refs/remotes/origin/pr/42"); cl_git_pass(git_reference_list(&refnames, repo)); - cl_assert_equal_i(20, (int)refnames.count); + cl_assert_equal_i(21, (int)refnames.count); git_strarray_dispose(&refnames); cl_git_pass(git_config_delete_multivar(config, "remote.origin.fetch", "refs")); @@ -221,7 +221,7 @@ void test_network_fetchlocal__fetchprune(void) cl_git_pass(git_remote_fetch(origin, NULL, &options, NULL)); cl_git_pass(git_reference_list(&refnames, repo)); - cl_assert_equal_i(19, (int)refnames.count); + cl_assert_equal_i(20, (int)refnames.count); cl_assert(callcount > 0); git_strarray_dispose(&refnames); git_remote_free(origin); @@ -235,7 +235,7 @@ void test_network_fetchlocal__fetchprune(void) cl_git_pass(git_remote_prune(origin, &options.callbacks)); cl_git_pass(git_reference_list(&refnames, repo)); - cl_assert_equal_i(18, (int)refnames.count); + cl_assert_equal_i(19, (int)refnames.count); git_strarray_dispose(&refnames); git_remote_free(origin); @@ -251,7 +251,7 @@ void test_network_fetchlocal__fetchprune(void) cl_git_pass(git_remote_fetch(origin, NULL, &options, NULL)); cl_git_pass(git_reference_list(&refnames, repo)); - cl_assert_equal_i(17, (int)refnames.count); + cl_assert_equal_i(18, (int)refnames.count); git_strarray_dispose(&refnames); git_remote_free(origin); @@ -335,7 +335,7 @@ void test_network_fetchlocal__partial(void) git_strarray_dispose(&refnames); cl_git_pass(git_reference_list(&refnames, repo)); - cl_assert_equal_i(20, (int)refnames.count); /* 18 remote + 1 local */ + cl_assert_equal_i(21, (int)refnames.count); /* 18 remote + 1 local */ cl_assert(callcount > 0); git_strarray_dispose(&refnames); @@ -418,7 +418,7 @@ void test_network_fetchlocal__multi_remotes(void) cl_git_pass(git_remote_fetch(test, NULL, &options, NULL)); cl_git_pass(git_reference_list(&refnames, repo)); - cl_assert_equal_i(33, (int)refnames.count); + cl_assert_equal_i(35, (int)refnames.count); git_strarray_dispose(&refnames); cl_git_pass(git_remote_set_url(repo, "test_with_pushurl", cl_git_fixture_url("testrepo.git"))); @@ -426,7 +426,7 @@ void test_network_fetchlocal__multi_remotes(void) cl_git_pass(git_remote_fetch(test2, NULL, &options, NULL)); cl_git_pass(git_reference_list(&refnames, repo)); - cl_assert_equal_i(45, (int)refnames.count); + cl_assert_equal_i(48, (int)refnames.count); git_strarray_dispose(&refnames); git_remote_free(test); diff --git a/tests/network/remote/local.c b/tests/network/remote/local.c index f174044d7..2007f3776 100644 --- a/tests/network/remote/local.c +++ b/tests/network/remote/local.c @@ -61,7 +61,7 @@ void test_network_remote_local__retrieve_advertised_references(void) cl_git_pass(git_remote_ls(&refs, &refs_len, remote)); - cl_assert_equal_i(refs_len, 29); + cl_assert_equal_i(refs_len, 30); } void test_network_remote_local__retrieve_advertised_before_connect(void) @@ -85,7 +85,7 @@ void test_network_remote_local__retrieve_advertised_references_after_disconnect( cl_git_pass(git_remote_ls(&refs, &refs_len, remote)); - cl_assert_equal_i(refs_len, 29); + cl_assert_equal_i(refs_len, 30); } void test_network_remote_local__retrieve_advertised_references_from_spaced_repository(void) @@ -100,7 +100,7 @@ void test_network_remote_local__retrieve_advertised_references_from_spaced_repos cl_git_pass(git_remote_ls(&refs, &refs_len, remote)); - cl_assert_equal_i(refs_len, 29); + cl_assert_equal_i(refs_len, 30); git_remote_free(remote); /* Disconnect from the "spaced repo" before the cleanup */ remote = NULL; diff --git a/tests/refs/branches/iterator.c b/tests/refs/branches/iterator.c index ca366c9f3..e086681e5 100644 --- a/tests/refs/branches/iterator.c +++ b/tests/refs/branches/iterator.c @@ -48,7 +48,7 @@ static void assert_retrieval(unsigned int flags, unsigned int expected_count) void test_refs_branches_iterator__retrieve_all_branches(void) { - assert_retrieval(GIT_BRANCH_ALL, 14); + assert_retrieval(GIT_BRANCH_ALL, 15); } void test_refs_branches_iterator__retrieve_remote_branches(void) @@ -58,7 +58,7 @@ void test_refs_branches_iterator__retrieve_remote_branches(void) void test_refs_branches_iterator__retrieve_local_branches(void) { - assert_retrieval(GIT_BRANCH_LOCAL, 12); + assert_retrieval(GIT_BRANCH_LOCAL, 13); } struct expectations { diff --git a/tests/refs/foreachglob.c b/tests/refs/foreachglob.c index 3ff18a27a..b208a95a2 100644 --- a/tests/refs/foreachglob.c +++ b/tests/refs/foreachglob.c @@ -48,8 +48,8 @@ static void assert_retrieval(const char *glob, int expected_count) void test_refs_foreachglob__retrieve_all_refs(void) { - /* 12 heads (including one packed head) + 1 note + 2 remotes + 7 tags + 1 blob */ - assert_retrieval("*", 23); + /* 13 heads (including one packed head) + 1 note + 2 remotes + 7 tags + 1 blob */ + assert_retrieval("*", 24); } void test_refs_foreachglob__retrieve_remote_branches(void) @@ -59,7 +59,7 @@ void test_refs_foreachglob__retrieve_remote_branches(void) void test_refs_foreachglob__retrieve_local_branches(void) { - assert_retrieval("refs/heads/*", 12); + assert_retrieval("refs/heads/*", 13); } void test_refs_foreachglob__retrieve_nonexistant(void) diff --git a/tests/refs/iterator.c b/tests/refs/iterator.c index 8d52755c2..a4f9e62ec 100644 --- a/tests/refs/iterator.c +++ b/tests/refs/iterator.c @@ -28,6 +28,7 @@ static const char *refnames[] = { "refs/heads/test", "refs/heads/track-local", "refs/heads/trailing", + "refs/heads/with-empty-log", "refs/notes/fanout", "refs/remotes/test/master", "refs/tags/annotated_tag_to_blob", @@ -58,6 +59,7 @@ static const char *refnames_with_symlink[] = { "refs/heads/test", "refs/heads/track-local", "refs/heads/trailing", + "refs/heads/with-empty-log", "refs/notes/fanout", "refs/remotes/test/master", "refs/tags/annotated_tag_to_blob", diff --git a/tests/refs/revparse.c b/tests/refs/revparse.c index d02249754..5fb758504 100644 --- a/tests/refs/revparse.c +++ b/tests/refs/revparse.c @@ -399,7 +399,7 @@ void test_refs_revparse__date(void) * a65fedf HEAD@{1335806603 -0900}: commit: * be3563a HEAD@{1335806563 -0700}: clone: from /Users/ben/src/libgit2/tests/resour */ - test_object("HEAD@{10 years ago}", NULL); + test_object("HEAD@{10 years ago}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); test_object("HEAD@{1 second}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); test_object("HEAD@{1 second ago}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); @@ -417,11 +417,12 @@ void test_refs_revparse__date(void) /* - * $ git reflog -1 "master@{2012-04-30 17:22:42 +0000}" - * warning: Log for 'master' only goes back to Mon, 30 Apr 2012 09:22:43 -0800. + * $ git rev-parse "master@{2012-04-30 17:22:42 +0000}" + * warning: log for 'master' only goes back to Mon, 30 Apr 2012 09:22:43 -0800 + * be3563ae3f795b2b4353bcce3a527ad0a4f7f644 */ - test_object("master@{2012-04-30 17:22:42 +0000}", NULL); - test_object("master@{2012-04-30 09:22:42 -0800}", NULL); + test_object("master@{2012-04-30 17:22:42 +0000}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); + test_object("master@{2012-04-30 09:22:42 -0800}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); /* * $ git reflog -1 "master@{2012-04-30 17:22:43 +0000}" @@ -451,6 +452,25 @@ void test_refs_revparse__date(void) */ test_object("master@{1335806603}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); test_object("master@{1335806602}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); + + /* + * $ git rev-parse "with-empty-log@{2 days ago}" -- + * fatal: log for refs/heads/with-empty-log is empty + */ + test_object("with-empty-log@{2 days ago}", NULL); +} + +void test_refs_revparse__invalid_date(void) +{ + /* + * $ git rev-parse HEAD@{} -- + * fatal: bad revision 'HEAD@{}' + * + * $ git rev-parse HEAD@{NEITHER_INTEGER_NOR_DATETIME} -- + * fatal: bad revision 'HEAD@{NEITHER_INTEGER_NOR_DATETIME}' + */ + test_object("HEAD@{}", NULL); + test_object("HEAD@{NEITHER_INTEGER_NOR_DATETIME}", NULL); } void test_refs_revparse__colon(void) diff --git a/tests/remote/insteadof.c b/tests/remote/insteadof.c index 05d4757cf..c39df4be7 100644 --- a/tests/remote/insteadof.c +++ b/tests/remote/insteadof.c @@ -4,7 +4,12 @@ #define REPO_PATH "testrepo2/.gitted" #define REMOTE_ORIGIN "origin" -#define REMOTE_INSTEADOF "insteadof-test" +#define REMOTE_INSTEADOF_URL_FETCH "insteadof-url-fetch" +#define REMOTE_INSTEADOF_URL_PUSH "insteadof-url-push" +#define REMOTE_INSTEADOF_URL_BOTH "insteadof-url-both" +#define REMOTE_INSTEADOF_PUSHURL_FETCH "insteadof-pushurl-fetch" +#define REMOTE_INSTEADOF_PUSHURL_PUSH "insteadof-pushurl-push" +#define REMOTE_INSTEADOF_PUSHURL_BOTH "insteadof-pushurl-both" static git_repository *g_repo; static git_remote *g_remote; @@ -21,7 +26,7 @@ void test_remote_insteadof__cleanup(void) git_remote_free(g_remote); } -void test_remote_insteadof__url_insteadof_not_applicable(void) +void test_remote_insteadof__not_applicable(void) { cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH))); cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_ORIGIN)); @@ -29,44 +34,121 @@ void test_remote_insteadof__url_insteadof_not_applicable(void) cl_assert_equal_s( git_remote_url(g_remote), "https://github.com/libgit2/false.git"); + cl_assert_equal_p(git_remote_pushurl(g_remote), NULL); } -void test_remote_insteadof__url_insteadof_applicable(void) +void test_remote_insteadof__url_insteadof_fetch(void) { cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH))); - cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF)); + cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF_URL_FETCH)); cl_assert_equal_s( git_remote_url(g_remote), - "http://github.com/libgit2/libgit2"); + "http://github.com/url/fetch/libgit2"); + cl_assert_equal_p(git_remote_pushurl(g_remote), NULL); } -void test_remote_insteadof__pushurl_insteadof_not_applicable(void) +void test_remote_insteadof__url_insteadof_push(void) { cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH))); - cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_ORIGIN)); + cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF_URL_PUSH)); - cl_assert_equal_p(git_remote_pushurl(g_remote), NULL); + cl_assert_equal_s( + git_remote_url(g_remote), + "http://example.com/url/push/libgit2"); + cl_assert_equal_s( + git_remote_pushurl(g_remote), + "git@github.com:url/push/libgit2"); } -void test_remote_insteadof__pushurl_insteadof_applicable(void) +void test_remote_insteadof__url_insteadof_both(void) { cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH))); - cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF)); + cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF_URL_BOTH)); cl_assert_equal_s( + git_remote_url(g_remote), + "http://github.com/url/both/libgit2"); + cl_assert_equal_s( git_remote_pushurl(g_remote), - "git@github.com:libgit2/libgit2"); + "git@github.com:url/both/libgit2"); } -void test_remote_insteadof__anonymous_remote(void) +void test_remote_insteadof__pushurl_insteadof_fetch(void) +{ + cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH))); + cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF_PUSHURL_FETCH)); + + cl_assert_equal_s( + git_remote_url(g_remote), + "http://github.com/url/fetch/libgit2"); + cl_assert_equal_s( + git_remote_pushurl(g_remote), + "http://github.com/url/fetch/libgit2-push"); +} + +void test_remote_insteadof__pushurl_insteadof_push(void) +{ + cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH))); + cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF_PUSHURL_PUSH)); + + cl_assert_equal_s( + git_remote_url(g_remote), + "http://example.com/url/push/libgit2"); + cl_assert_equal_s( + git_remote_pushurl(g_remote), + "http://example.com/url/push/libgit2-push"); +} + +void test_remote_insteadof__pushurl_insteadof_both(void) +{ + cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH))); + cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF_PUSHURL_BOTH)); + + cl_assert_equal_s( + git_remote_url(g_remote), + "http://github.com/url/both/libgit2"); + cl_assert_equal_s( + git_remote_pushurl(g_remote), + "http://github.com/url/both/libgit2-push"); +} + +void test_remote_insteadof__anonymous_remote_fetch(void) { cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH))); cl_git_pass(git_remote_create_anonymous(&g_remote, g_repo, - "http://example.com/libgit2/libgit2")); + "http://example.com/url/fetch/libgit2")); cl_assert_equal_s( git_remote_url(g_remote), - "http://github.com/libgit2/libgit2"); + "http://github.com/url/fetch/libgit2"); cl_assert_equal_p(git_remote_pushurl(g_remote), NULL); } + +void test_remote_insteadof__anonymous_remote_push(void) +{ + cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH))); + cl_git_pass(git_remote_create_anonymous(&g_remote, g_repo, + "http://example.com/url/push/libgit2")); + + cl_assert_equal_s( + git_remote_url(g_remote), + "http://example.com/url/push/libgit2"); + cl_assert_equal_s( + git_remote_pushurl(g_remote), + "git@github.com:url/push/libgit2"); +} + +void test_remote_insteadof__anonymous_remote_both(void) +{ + cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH))); + cl_git_pass(git_remote_create_anonymous(&g_remote, g_repo, + "http://example.com/url/both/libgit2")); + + cl_assert_equal_s( + git_remote_url(g_remote), + "http://github.com/url/both/libgit2"); + cl_assert_equal_s( + git_remote_pushurl(g_remote), + "git@github.com:url/both/libgit2"); +} diff --git a/tests/resources/config/config22 b/tests/resources/config/config22 new file mode 100644 index 000000000..2a8e528ff --- /dev/null +++ b/tests/resources/config/config22 @@ -0,0 +1,10 @@ +[alias] + m = cmd \ +";;" \ +";;" \ +bar + m2 = '\ +";" \ +";" \ +something \ +' diff --git a/tests/resources/testrepo.git/logs/refs/heads/with-empty-log b/tests/resources/testrepo.git/logs/refs/heads/with-empty-log new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/resources/testrepo.git/logs/refs/heads/with-empty-log diff --git a/tests/resources/testrepo.git/refs/heads/with-empty-log b/tests/resources/testrepo.git/refs/heads/with-empty-log new file mode 100644 index 000000000..dae4cb2b0 --- /dev/null +++ b/tests/resources/testrepo.git/refs/heads/with-empty-log @@ -0,0 +1 @@ +8496071c1b46c854b31185ea97743be6a8774479 diff --git a/tests/resources/testrepo2/.gitted/config b/tests/resources/testrepo2/.gitted/config index 4af067f04..6966b8a5d 100644 --- a/tests/resources/testrepo2/.gitted/config +++ b/tests/resources/testrepo2/.gitted/config @@ -8,19 +8,42 @@ [remote "origin"] url = https://github.com/libgit2/false.git fetch = +refs/heads/*:refs/remotes/origin/* -[remote "insteadof-test"] - url = http://example.com/libgit2/libgit2 - pushurl = http://github.com/libgit2/libgit2 +[remote "insteadof-url-fetch"] + url = http://example.com/url/fetch/libgit2 + fetch = +refs/heads/*:refs/remotes/test/* +[remote "insteadof-url-push"] + url = http://example.com/url/push/libgit2 + fetch = +refs/heads/*:refs/remotes/test/* +[remote "insteadof-url-both"] + url = http://example.com/url/both/libgit2 + fetch = +refs/heads/*:refs/remotes/test/* +[remote "insteadof-pushurl-fetch"] + url = http://example.com/url/fetch/libgit2 + pushurl = http://example.com/url/fetch/libgit2-push + fetch = +refs/heads/*:refs/remotes/test/* +[remote "insteadof-pushurl-push"] + url = http://example.com/url/push/libgit2 + pushurl = http://example.com/url/push/libgit2-push + fetch = +refs/heads/*:refs/remotes/test/* +[remote "insteadof-pushurl-both"] + url = http://example.com/url/both/libgit2 + pushurl = http://example.com/url/both/libgit2-push fetch = +refs/heads/*:refs/remotes/test/* [branch "master"] remote = origin merge = refs/heads/master rebase = true [url "longer-non-prefix-match"] - insteadOf = ttp://example.com/li + # not applicable because it's not a prefix match + insteadOf = ttp://example.com/url/fetch/li [url "shorter-prefix"] - insteadOf = http://example.co -[url "http://github.com"] - insteadOf = http://example.com -[url "git@github.com:"] - pushInsteadOf = http://github.com/ + # not applicable because the matched prefix is shorter + insteadOf = http://example.com/url/fe +[url "http://github.com/url/fetch"] + insteadOf = http://example.com/url/fetch +[url "http://github.com/url/both"] + insteadOf = http://example.com/url/both +[url "git@github.com:url/push"] + pushInsteadOf = http://example.com/url/push +[url "git@github.com:url/both"] + pushInsteadOf = http://example.com/url/both |