summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rw-r--r--cmake/FindLibSSH2.cmake13
-rw-r--r--include/git2/stdint.h6
-rw-r--r--src/CMakeLists.txt7
-rw-r--r--src/blob.c7
-rw-r--r--src/merge.c7
-rw-r--r--src/remote.c15
-rw-r--r--src/util.c2
-rw-r--r--tests/remote/httpproxy.c51
-rw-r--r--tests/resources/revert-rename.git/HEAD1
-rw-r--r--tests/resources/revert-rename.git/config5
-rw-r--r--tests/resources/revert-rename.git/indexbin0 -> 209 bytes
-rw-r--r--tests/resources/revert-rename.git/objects/info/packs2
-rw-r--r--tests/resources/revert-rename.git/objects/pack/pack-4363774fb90141e8aa7a326ace0566366114e869.idxbin0 -> 1296 bytes
-rw-r--r--tests/resources/revert-rename.git/objects/pack/pack-4363774fb90141e8aa7a326ace0566366114e869.packbin0 -> 783 bytes
-rw-r--r--tests/resources/revert-rename.git/packed-refs2
-rw-r--r--tests/resources/revert-rename.git/refs/heads/master1
-rw-r--r--tests/revert/rename.c49
-rw-r--r--tests/win32/longpath.c49
19 files changed, 199 insertions, 19 deletions
diff --git a/README.md b/README.md
index 9ecb706bd..0cbde525b 100644
--- a/README.md
+++ b/README.md
@@ -371,6 +371,7 @@ Here are the bindings to libgit2 that are currently available:
* hgit2 <https://github.com/jwiegley/gitlib>
* Java
* Jagged <https://github.com/ethomson/jagged>
+ * Git24j <https://github.com/git24j/git24j>
* Javascript / WebAssembly ( browser and nodejs )
* WASM-git <https://github.com/petersalomonsen/wasm-git>
* Julia
diff --git a/cmake/FindLibSSH2.cmake b/cmake/FindLibSSH2.cmake
new file mode 100644
index 000000000..ff5893525
--- /dev/null
+++ b/cmake/FindLibSSH2.cmake
@@ -0,0 +1,13 @@
+# LIBSSH2_FOUND - system has the libssh2 library
+# LIBSSH2_INCLUDE_DIR - the libssh2 include directory
+# LIBSSH2_LIBRARY - the libssh2 library name
+
+FIND_PATH(LIBSSH2_INCLUDE_DIR libssh2.h)
+
+FIND_LIBRARY(LIBSSH2_LIBRARY NAMES ssh2 libssh2)
+
+INCLUDE(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(LibSSH2
+ REQUIRED_VARS LIBSSH2_LIBRARY LIBSSH2_INCLUDE_DIR)
+
+MARK_AS_ADVANCED(LIBSSH2_INCLUDE_DIR LIBSSH2_LIBRARY)
diff --git a/include/git2/stdint.h b/include/git2/stdint.h
index c66fbb817..6950427d2 100644
--- a/include/git2/stdint.h
+++ b/include/git2/stdint.h
@@ -29,9 +29,7 @@
//
///////////////////////////////////////////////////////////////////////////////
-#ifndef _MSC_VER // [
-#error "Use this header only with Microsoft Visual C++ compilers!"
-#endif // _MSC_VER ]
+#ifdef _MSC_VER // [
#ifndef _MSC_STDINT_H_ // [
#define _MSC_STDINT_H_
@@ -245,3 +243,5 @@ typedef uint64_t uintmax_t;
#endif // _MSC_STDINT_H_ ]
+
+#endif // _MSC_VER ] \ No newline at end of file
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 45dec2796..fdb367335 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -232,6 +232,13 @@ ENDIF()
# Optional external dependency: libssh2
IF (USE_SSH)
FIND_PKGLIBRARIES(LIBSSH2 libssh2)
+ IF (NOT LIBSSH2_FOUND)
+ FIND_PACKAGE(LibSSH2)
+ SET(LIBSSH2_INCLUDE_DIRS ${LIBSSH2_INCLUDE_DIR})
+ GET_FILENAME_COMPONENT(LIBSSH2_LIBRARY_DIRS "${LIBSSH2_LIBRARY}" DIRECTORY)
+ SET(LIBSSH2_LIBRARIES ${LIBSSH2_LIBRARY})
+ SET(LIBSSH2_LDFLAGS "-lssh2")
+ ENDIF()
ENDIF()
IF (LIBSSH2_FOUND)
SET(GIT_SSH 1)
diff --git a/src/blob.c b/src/blob.c
index 01ebf075e..79096ee95 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -138,12 +138,13 @@ static int write_file_filtered(
git_object_size_t *size,
git_odb *odb,
const char *full_path,
- git_filter_list *fl)
+ git_filter_list *fl,
+ git_repository* repo)
{
int error;
git_buf tgt = GIT_BUF_INIT;
- error = git_filter_list_apply_to_file(&tgt, fl, NULL, full_path);
+ error = git_filter_list_apply_to_file(&tgt, fl, repo, full_path);
/* Write the file to disk if it was properly filtered */
if (!error) {
@@ -238,7 +239,7 @@ int git_blob__create_from_paths(
error = write_file_stream(id, odb, content_path, size);
else {
/* We need to apply one or more filters */
- error = write_file_filtered(id, &size, odb, content_path, fl);
+ error = write_file_filtered(id, &size, odb, content_path, fl, repo);
git_filter_list_free(fl);
}
diff --git a/src/merge.c b/src/merge.c
index 191fb98ba..1c841bdfb 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -816,8 +816,11 @@ static int merge_conflict_resolve_one_renamed(
conflict->type == GIT_MERGE_DIFF_RENAMED_ADDED)
return 0;
- ours_changed = (git_oid__cmp(&conflict->ancestor_entry.id, &conflict->our_entry.id) != 0);
- theirs_changed = (git_oid__cmp(&conflict->ancestor_entry.id, &conflict->their_entry.id) != 0);
+ ours_changed = (git_oid__cmp(&conflict->ancestor_entry.id, &conflict->our_entry.id) != 0) ||
+ (conflict->ancestor_entry.mode != conflict->our_entry.mode);
+
+ theirs_changed = (git_oid__cmp(&conflict->ancestor_entry.id, &conflict->their_entry.id) != 0) ||
+ (conflict->ancestor_entry.mode != conflict->their_entry.mode);
/* if both are modified (and not to a common target) require a merge */
if (ours_changed && theirs_changed &&
diff --git a/src/remote.c b/src/remote.c
index 154300bd2..56d7e42db 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -884,15 +884,22 @@ static void url_config_trim(git_net_url *url)
static int http_proxy_config(char **out, git_remote *remote, git_net_url *url)
{
- git_config *cfg;
+ git_config *cfg = NULL;
git_buf buf = GIT_BUF_INIT;
git_net_url lookup_url = GIT_NET_URL_INIT;
int error;
- if ((error = git_net_url_dup(&lookup_url, url)) < 0 ||
- (error = git_repository_config__weakptr(&cfg, remote->repo)) < 0)
+ if ((error = git_net_url_dup(&lookup_url, url)) < 0)
goto done;
+ if (remote->repo) {
+ if ((error = git_repository_config(&cfg, remote->repo)) < 0)
+ goto done;
+ } else {
+ if ((error = git_config_open_default(&cfg)) < 0)
+ goto done;
+ }
+
/* remote.<name>.proxy config setting */
if (remote->name && remote->name[0]) {
git_buf_clear(&buf);
@@ -922,6 +929,7 @@ static int http_proxy_config(char **out, git_remote *remote, git_net_url *url)
error = lookup_config(out, cfg, "http.proxy");
done:
+ git_config_free(cfg);
git_buf_dispose(&buf);
git_net_url_dispose(&lookup_url);
return error;
@@ -971,7 +979,6 @@ int git_remote__http_proxy(char **out, git_remote *remote, git_net_url *url)
GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(remote);
- GIT_ASSERT_ARG(remote->repo);
*out = NULL;
diff --git a/src/util.c b/src/util.c
index c7af2961a..9b0c45ce8 100644
--- a/src/util.c
+++ b/src/util.c
@@ -755,7 +755,7 @@ int git__getenv(git_buf *out, const char *name)
if (value_len)
error = git_buf_put_w(out, wide_value, value_len);
- else if (GetLastError() == ERROR_ENVVAR_NOT_FOUND)
+ else if (GetLastError() == ERROR_SUCCESS || GetLastError() == ERROR_ENVVAR_NOT_FOUND)
error = GIT_ENOTFOUND;
else
git_error_set(GIT_ERROR_OS, "could not read environment variable '%s'", name);
diff --git a/tests/remote/httpproxy.c b/tests/remote/httpproxy.c
index 097db4cd5..8cd4371f5 100644
--- a/tests/remote/httpproxy.c
+++ b/tests/remote/httpproxy.c
@@ -1,6 +1,7 @@
#include "clar_libgit2.h"
-#include "remote.h"
+#include "futils.h"
#include "net.h"
+#include "remote.h"
static git_repository *repo;
static git_net_url url = GIT_NET_URL_INIT;
@@ -105,6 +106,45 @@ void test_remote_httpproxy__config_empty_overrides(void)
assert_config_match("remote.lg2.proxy", "");
}
+void assert_global_config_match(const char *config, const char *expected)
+{
+ git_remote *remote;
+ char *proxy;
+ git_config* cfg;
+
+ if (config) {
+ cl_git_pass(git_config_open_default(&cfg));
+ git_config_set_string(cfg, config, expected);
+ git_config_free(cfg);
+ }
+
+ cl_git_pass(git_remote_create_detached(&remote, "https://github.com/libgit2/libgit2"));
+ cl_git_pass(git_remote__http_proxy(&proxy, remote, &url));
+
+ if (expected)
+ cl_assert_equal_s(proxy, expected);
+ else
+ cl_assert_equal_p(proxy, expected);
+
+ git_remote_free(remote);
+ git__free(proxy);
+}
+
+void test_remote_httpproxy__config_overrides_detached_remote(void)
+{
+ cl_fake_home();
+
+ assert_global_config_match(NULL, NULL);
+ assert_global_config_match("http.proxy", "http://localhost:1/");
+ assert_global_config_match("http.https://github.com.proxy", "http://localhost:2/");
+ assert_global_config_match("http.https://github.com/.proxy", "http://localhost:3/");
+ assert_global_config_match("http.https://github.com/libgit2.proxy", "http://localhost:4/");
+ assert_global_config_match("http.https://github.com/libgit2/.proxy", "http://localhost:5/");
+ assert_global_config_match("http.https://github.com/libgit2/libgit2.proxy", "http://localhost:6/");
+
+ cl_git_pass(git_futils_rmdir_r("home", NULL, GIT_RMDIR_REMOVE_FILES));
+}
+
void test_remote_httpproxy__env(void)
{
orig_http_proxy = cl_getenv("HTTP_PROXY");
@@ -112,6 +152,11 @@ void test_remote_httpproxy__env(void)
orig_no_proxy = cl_getenv("NO_PROXY");
orig_proxies_need_reset = 1;
+ /* Clear everything for a fresh start */
+ cl_setenv("HTTP_PROXY", NULL);
+ cl_setenv("HTTPS_PROXY", NULL);
+ cl_setenv("NO_PROXY", NULL);
+
/* HTTP proxy is ignored for HTTPS */
cl_setenv("HTTP_PROXY", "http://localhost:9/");
assert_proxy_is(NULL);
@@ -133,7 +178,11 @@ void test_remote_httpproxy__env(void)
cl_setenv("NO_PROXY", "github.dev,github.com,github.foo");
assert_proxy_is(NULL);
+ cl_setenv("HTTPS_PROXY", "");
+ assert_proxy_is(NULL);
+
/* configuration overrides environment variables */
+ cl_setenv("HTTPS_PROXY", "http://localhost:10/");
cl_setenv("NO_PROXY", "github.none");
assert_config_match("http.https://github.com.proxy", "http://localhost:11/");
}
diff --git a/tests/resources/revert-rename.git/HEAD b/tests/resources/revert-rename.git/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests/resources/revert-rename.git/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests/resources/revert-rename.git/config b/tests/resources/revert-rename.git/config
new file mode 100644
index 000000000..a4ef456cb
--- /dev/null
+++ b/tests/resources/revert-rename.git/config
@@ -0,0 +1,5 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = true
+ logallrefupdates = true
diff --git a/tests/resources/revert-rename.git/index b/tests/resources/revert-rename.git/index
new file mode 100644
index 000000000..232325dfb
--- /dev/null
+++ b/tests/resources/revert-rename.git/index
Binary files differ
diff --git a/tests/resources/revert-rename.git/objects/info/packs b/tests/resources/revert-rename.git/objects/info/packs
new file mode 100644
index 000000000..5d971426e
--- /dev/null
+++ b/tests/resources/revert-rename.git/objects/info/packs
@@ -0,0 +1,2 @@
+P pack-4363774fb90141e8aa7a326ace0566366114e869.pack
+
diff --git a/tests/resources/revert-rename.git/objects/pack/pack-4363774fb90141e8aa7a326ace0566366114e869.idx b/tests/resources/revert-rename.git/objects/pack/pack-4363774fb90141e8aa7a326ace0566366114e869.idx
new file mode 100644
index 000000000..3fb48ea94
--- /dev/null
+++ b/tests/resources/revert-rename.git/objects/pack/pack-4363774fb90141e8aa7a326ace0566366114e869.idx
Binary files differ
diff --git a/tests/resources/revert-rename.git/objects/pack/pack-4363774fb90141e8aa7a326ace0566366114e869.pack b/tests/resources/revert-rename.git/objects/pack/pack-4363774fb90141e8aa7a326ace0566366114e869.pack
new file mode 100644
index 000000000..e078ec2aa
--- /dev/null
+++ b/tests/resources/revert-rename.git/objects/pack/pack-4363774fb90141e8aa7a326ace0566366114e869.pack
Binary files differ
diff --git a/tests/resources/revert-rename.git/packed-refs b/tests/resources/revert-rename.git/packed-refs
new file mode 100644
index 000000000..e062909d4
--- /dev/null
+++ b/tests/resources/revert-rename.git/packed-refs
@@ -0,0 +1,2 @@
+# pack-refs with: peeled fully-peeled sorted
+ecef6a85173b6f446873a13f7b5a7b54a85cd912 refs/heads/master
diff --git a/tests/resources/revert-rename.git/refs/heads/master b/tests/resources/revert-rename.git/refs/heads/master
new file mode 100644
index 000000000..3771102fb
--- /dev/null
+++ b/tests/resources/revert-rename.git/refs/heads/master
@@ -0,0 +1 @@
+ecef6a85173b6f446873a13f7b5a7b54a85cd912
diff --git a/tests/revert/rename.c b/tests/revert/rename.c
new file mode 100644
index 000000000..0d713c60f
--- /dev/null
+++ b/tests/revert/rename.c
@@ -0,0 +1,49 @@
+#include "clar.h"
+#include "clar_libgit2.h"
+
+#include "git2/revert.h"
+#include "../merge/merge_helpers.h"
+
+#define TEST_REPO_PATH "revert-rename.git"
+
+static git_repository *repo;
+
+/* Fixture setup and teardown */
+void test_revert_rename__initialize(void)
+{
+ repo = cl_git_sandbox_init(TEST_REPO_PATH);
+}
+
+void test_revert_rename__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+/* Attempt a revert when there is a file rename AND change of file mode,
+ * but the file contents remain the same. Check that the file mode doesn't
+ * change following the revert.
+ */
+void test_revert_rename__automerge(void)
+{
+ git_commit *head_commit, *revert_commit;
+ git_oid revert_oid;
+ git_index *index;
+ git_reference *head_ref;
+
+ struct merge_index_entry merge_index_entries[] = {
+ { 0100644, "f0f64c618e1646d2948a456ed7c4bcfad5536d68", 0, "goodmode" }};
+
+ cl_git_pass(git_repository_head(&head_ref, repo));
+ cl_git_pass(git_reference_peel((git_object **)&head_commit, head_ref, GIT_OBJECT_COMMIT));
+
+ cl_git_pass(git_oid_fromstr(&revert_oid, "7b4d7c3789b3581973c04087cb774c3c3576de2f"));
+ cl_git_pass(git_commit_lookup(&revert_commit, repo, &revert_oid));
+
+ cl_git_pass(git_revert_commit(&index, repo, revert_commit, head_commit, 0, NULL));
+ cl_assert(merge_test_index(index, merge_index_entries, 1));
+
+ git_commit_free(revert_commit);
+ git_commit_free(head_commit);
+ git_index_free(index);
+ git_reference_free(head_ref);
+}
diff --git a/tests/win32/longpath.c b/tests/win32/longpath.c
index ebfcc4d0d..f8b8c4b0a 100644
--- a/tests/win32/longpath.c
+++ b/tests/win32/longpath.c
@@ -64,18 +64,17 @@ void test_win32_longpath__workdir_path_validated(void)
#endif
}
-void test_win32_longpath__status_and_add(void)
-{
#ifdef GIT_WIN32
- git_repository *repo = cl_git_sandbox_init("testrepo");
+static void assert_longpath_status_and_add(git_repository *repo, const char *wddata, const char *repodata) {
git_index *index;
+ git_blob *blob;
git_buf out = GIT_BUF_INIT;
+ const git_index_entry *entry;
unsigned int status_flags;
- cl_repo_set_bool(repo, "core.longpaths", true);
cl_git_pass(git_repository_workdir_path(&out, repo, LONG_FILENAME));
- cl_git_rewritefile(out.ptr, "This is a long path.\r\n");
+ cl_git_rewritefile(out.ptr, wddata);
cl_git_pass(git_status_file(&status_flags, repo, LONG_FILENAME));
cl_assert_equal_i(GIT_STATUS_WT_NEW, status_flags);
@@ -86,7 +85,47 @@ void test_win32_longpath__status_and_add(void)
cl_git_pass(git_status_file(&status_flags, repo, LONG_FILENAME));
cl_assert_equal_i(GIT_STATUS_INDEX_NEW, status_flags);
+ cl_assert((entry = git_index_get_bypath(index, LONG_FILENAME, 0)) != NULL);
+ cl_git_pass(git_blob_lookup(&blob, repo, &entry->id));
+ cl_assert_equal_s(repodata, git_blob_rawcontent(blob));
+
+ git_blob_free(blob);
git_index_free(index);
git_buf_dispose(&out);
+}
+#endif
+
+void test_win32_longpath__status_and_add(void)
+{
+#ifdef GIT_WIN32
+ git_repository *repo = cl_git_sandbox_init("testrepo");
+
+ cl_repo_set_bool(repo, "core.longpaths", true);
+
+ /*
+ * Doing no content filtering, we expect the data we add
+ * to be the data in the repository.
+ */
+ assert_longpath_status_and_add(repo,
+ "This is a long path.\r\n",
+ "This is a long path.\r\n");
+#endif
+}
+
+void test_win32_longpath__status_and_add_with_filter(void)
+{
+#ifdef GIT_WIN32
+ git_repository *repo = cl_git_sandbox_init("testrepo");
+
+ cl_repo_set_bool(repo, "core.longpaths", true);
+ cl_repo_set_bool(repo, "core.autocrlf", true);
+
+ /*
+ * With `core.autocrlf`, we expect the data we add to have
+ * newline conversion performed.
+ */
+ assert_longpath_status_and_add(repo,
+ "This is a long path.\r\n",
+ "This is a long path.\n");
#endif
}