summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md49
-rw-r--r--CMakeLists.txt8
-rw-r--r--README.md5
-rw-r--r--appveyor.yml21
-rw-r--r--examples/describe.c30
-rw-r--r--examples/network/clone.c2
-rw-r--r--examples/network/fetch.c2
-rw-r--r--include/git2/branch.h18
-rw-r--r--include/git2/checkout.h27
-rw-r--r--include/git2/clone.h14
-rw-r--r--include/git2/config.h40
-rw-r--r--include/git2/rebase.h7
-rw-r--r--include/git2/refs.h48
-rw-r--r--include/git2/remote.h16
-rw-r--r--include/git2/repository.h43
-rw-r--r--include/git2/reset.h11
-rw-r--r--include/git2/submodule.h12
-rw-r--r--include/git2/sys/config.h4
-rw-r--r--include/git2/version.h1
-rwxr-xr-xscript/appveyor-mingw.sh23
-rw-r--r--src/attrcache.c3
-rw-r--r--src/branch.c81
-rw-r--r--src/checkout.c28
-rw-r--r--src/cherrypick.c2
-rw-r--r--src/clone.c48
-rw-r--r--src/commit.c4
-rw-r--r--src/common.h1
-rw-r--r--src/config.c119
-rw-r--r--src/config.h4
-rw-r--r--src/config_cache.c3
-rw-r--r--src/config_file.c24
-rw-r--r--src/config_file.h2
-rw-r--r--src/diff.c3
-rw-r--r--src/diff_driver.c3
-rw-r--r--src/diff_tform.c4
-rw-r--r--src/filter.c3
-rw-r--r--src/global.c47
-rw-r--r--src/hashsig.c17
-rw-r--r--src/openssl_stream.c17
-rw-r--r--src/push.c9
-rw-r--r--src/push.h7
-rw-r--r--src/rebase.c28
-rw-r--r--src/refdb_fs.c2
-rw-r--r--src/refs.c164
-rw-r--r--src/refs.h4
-rw-r--r--src/refspec.c3
-rw-r--r--src/remote.c37
-rw-r--r--src/repository.c147
-rw-r--r--src/repository.h3
-rw-r--r--src/reset.c18
-rw-r--r--src/revert.c2
-rw-r--r--src/stash.c8
-rw-r--r--src/submodule.c5
-rw-r--r--src/tag.c4
-rw-r--r--src/transports/http.c5
-rw-r--r--src/transports/local.c2
-rw-r--r--src/win32/git2.rc4
-rw-r--r--src/win32/mingw-compat.h7
-rw-r--r--src/win32/msvc-compat.h3
-rw-r--r--src/win32/posix.h4
-rw-r--r--src/win32/posix_w32.c24
-rw-r--r--tests/checkout/crlf.c32
-rw-r--r--tests/checkout/index.c49
-rw-r--r--tests/checkout/tree.c84
-rw-r--r--tests/checkout/typechange.c6
-rw-r--r--tests/cherrypick/workdir.c20
-rw-r--r--tests/clar.c33
-rw-r--r--tests/clar.h42
-rw-r--r--tests/clar_libgit2_timer.c31
-rw-r--r--tests/clar_libgit2_timer.h35
-rw-r--r--tests/clar_libgit2_trace.c229
-rw-r--r--tests/clar_libgit2_trace.h7
-rw-r--r--tests/clone/nonetwork.c16
-rw-r--r--tests/commit/write.c2
-rw-r--r--tests/config/config_helpers.c13
-rw-r--r--tests/config/configlevel.c14
-rw-r--r--tests/config/global.c8
-rw-r--r--tests/config/include.c51
-rw-r--r--tests/config/new.c12
-rw-r--r--tests/config/read.c78
-rw-r--r--tests/config/rename.c8
-rw-r--r--tests/config/stress.c58
-rw-r--r--tests/config/validkeyname.c5
-rw-r--r--tests/config/write.c63
-rw-r--r--tests/core/ftruncate.c48
-rw-r--r--tests/describe/t6120.c2
-rw-r--r--tests/diff/rename.c106
-rw-r--r--tests/fetchhead/nonetwork.c2
-rw-r--r--tests/filter/file.c97
-rw-r--r--tests/index/names.c4
-rw-r--r--tests/index/reuc.c8
-rw-r--r--tests/main.c4
-rw-r--r--tests/merge/merge_helpers.c2
-rw-r--r--tests/merge/workdir/dirty.c8
-rw-r--r--tests/merge/workdir/simple.c6
-rw-r--r--tests/merge/workdir/submodules.c4
-rw-r--r--tests/merge/workdir/trivial.c2
-rw-r--r--tests/network/fetchlocal.c36
-rw-r--r--tests/network/remote/defaultbranch.c10
-rw-r--r--tests/network/remote/local.c41
-rw-r--r--tests/network/remote/remotes.c20
-rw-r--r--tests/network/remote/rename.c4
-rw-r--r--tests/online/clone.c2
-rw-r--r--tests/online/fetch.c8
-rw-r--r--tests/online/fetchhead.c2
-rw-r--r--tests/online/push.c11
-rw-r--r--tests/perf/helper__perf__do_merge.c11
-rw-r--r--tests/rebase/abort.c16
-rw-r--r--tests/rebase/iterator.c2
-rw-r--r--tests/rebase/merge.c16
-rw-r--r--tests/rebase/setup.c20
-rw-r--r--tests/refs/branches/create.c50
-rw-r--r--tests/refs/branches/delete.c4
-rw-r--r--tests/refs/branches/ishead.c6
-rw-r--r--tests/refs/branches/iterator.c4
-rw-r--r--tests/refs/branches/move.c108
-rw-r--r--tests/refs/branches/upstream.c27
-rw-r--r--tests/refs/crashes.c2
-rw-r--r--tests/refs/create.c18
-rw-r--r--tests/refs/createwithlog.c6
-rw-r--r--tests/refs/delete.c2
-rw-r--r--tests/refs/foreachglob.c2
-rw-r--r--tests/refs/overwrite.c26
-rw-r--r--tests/refs/pack.c4
-rw-r--r--tests/refs/races.c34
-rw-r--r--tests/refs/reflog/reflog.c20
-rw-r--r--tests/refs/rename.c39
-rw-r--r--tests/refs/revparse.c10
-rw-r--r--tests/refs/settargetwithlog.c6
-rw-r--r--tests/refs/setter.c10
-rw-r--r--tests/refs/unicode.c2
-rw-r--r--tests/refs/update.c2
-rw-r--r--tests/repo/head.c94
-rw-r--r--tests/repo/headtree.c2
-rw-r--r--tests/repo/init.c15
-rw-r--r--tests/repo/new.c27
-rw-r--r--tests/repo/repo_helpers.c2
-rw-r--r--tests/repo/setters.c8
-rw-r--r--tests/repo/state.c2
-rw-r--r--tests/reset/hard.c28
-rw-r--r--tests/reset/mixed.c26
-rw-r--r--tests/reset/reset_helpers.c4
-rw-r--r--tests/reset/soft.c26
-rw-r--r--tests/revert/workdir.c28
-rw-r--r--tests/stash/save.c23
-rw-r--r--tests/status/submodules.c4
-rw-r--r--tests/submodule/add.c15
-rw-r--r--tests/submodule/init.c14
-rw-r--r--tests/submodule/lookup.c7
-rw-r--r--tests/submodule/modify.c17
-rw-r--r--tests/submodule/repository_init.c8
-rw-r--r--tests/submodule/update.c6
-rw-r--r--tests/threads/refdb.c6
-rw-r--r--tests/trace/trace.c19
154 files changed, 2201 insertions, 1234 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fd697087a..71112bfaa 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,12 +8,30 @@ v0.22 + 1
* Rename and copy detection is enabled for small files.
+* Checkout can now handle an initial checkout of a repository, making
+ `GIT_CHECKOUT_SAFE_CREATE` unnecessary for users of clone.
+
+* The signature parameter in the ref-modifying functions has been
+ removed. Use `git_repository_set_ident()` and
+ `git_repository_ident()` to override the signature to be used.
+
### API additions
* Parsing and retrieving a configuration value as a path is exposed
via `git_config_parse_path()` and `git_config_get_path()`
respectively.
+* `git_repository_set_ident()` and `git_repository_ident()` serve to
+ set and query which identity will be used when writing to the
+ reflog.
+
+* `git_config_entry_free()` frees a config entry.
+
+* `git_config_get_string_buf()` provides a way to safely retrieve a
+ string from a non-snapshot configuration.
+
+* Reference renaming now uses the right id for the old value.
+
* `git_index_add_frombuffer()` can now create a blob from memory
buffer and add it to the index which is attached to a repository.
@@ -21,6 +39,37 @@ v0.22 + 1
### Breaking API changes
+* `GIT_CHECKOUT_SAFE_CREATE` has been removed. Most users will generally
+ be able to switch to `GIT_CHECKOUT_SAFE`, but if you require missing
+ file handling during checkout, you may now use `GIT_CHECKOUT_SAFE |
+ GIT_CHECKOUT_RECREATE_MISSING`.
+
+* The `git_clone_options` and `git_submodule_update_options`
+ structures no longer have a `signature` field.
+
+* The following functions have removed the signature and/or log message
+ parameters in favour of git-emulating ones.
+
+ * `git_branch_create()`, `git_branch_move()`
+ * `git_rebase_init()`, `git_rebase_abort()`
+ * `git_reference_symbolic_create_matching()`,
+ `git_reference_symbolic_create()`, `git_reference_create()`,
+ `git_reference_create_matching()`,
+ `git_reference_symbolic_set_target()`,
+ `git_reference_set_target()`, `git_reference_rename()`
+ * `git_remote_update_tips()`, `git_remote_fetch()`, `git_remote_push()`
+ * `git_repository_set_head()`,
+ `git_repository_set_head_detached()`,
+ `git_repository_detach_head()`
+ * `git_reset()`
+
+* `git_config_get_entry()` now gives back a ref-counted
+ `git_config_entry`. You must free it when you no longer need it.
+
+* `git_config_get_string()` will return an error if used on a
+ non-snapshot configuration, as there can be no guarantee that the
+ returned pointer is valid.
+
v0.22
------
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 81dc4c24a..1948fc88b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -465,7 +465,7 @@ IF (BUILD_CLAR)
INCLUDE_DIRECTORIES(${CLAR_PATH})
FILE(GLOB_RECURSE SRC_TEST ${CLAR_PATH}/*/*.c ${CLAR_PATH}/*/*.h)
- SET(SRC_CLAR "${CLAR_PATH}/main.c" "${CLAR_PATH}/clar_libgit2.c" "${CLAR_PATH}/clar.c")
+ SET(SRC_CLAR "${CLAR_PATH}/main.c" "${CLAR_PATH}/clar_libgit2.c" "${CLAR_PATH}/clar_libgit2_trace.c" "${CLAR_PATH}/clar_libgit2_timer.c" "${CLAR_PATH}/clar.c")
ADD_CUSTOM_COMMAND(
OUTPUT ${CLAR_PATH}/clar.suite
@@ -493,7 +493,11 @@ IF (BUILD_CLAR)
ENDIF ()
ENABLE_TESTING()
- ADD_TEST(libgit2_clar libgit2_clar -ionline)
+ IF (WINHTTP OR OPENSSL_FOUND)
+ ADD_TEST(libgit2_clar libgit2_clar -ionline)
+ ELSE ()
+ ADD_TEST(libgit2_clar libgit2_clar -v)
+ ENDIF ()
ENDIF ()
IF (TAGS)
diff --git a/README.md b/README.md
index b9a42d76d..882924231 100644
--- a/README.md
+++ b/README.md
@@ -70,7 +70,10 @@ before calling any other libgit2 functions. You can call this function many time
git_libgit2_shutdown();
-will free the resources.
+will free the resources. Note that if you have worker threads, you should
+call `git_libgit2_shutdown` *after* those threads have exited. If you
+require assistance coordinating this, simply have the worker threads call
+`git_libgit2_init` at startup and `git_libgit2_shutdown` at shutdown.
Threading
=========
diff --git a/appveyor.yml b/appveyor.yml
index d155485fd..cf9564b6d 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -11,11 +11,28 @@ environment:
ARCH: 32
- GENERATOR: "Visual Studio 11 Win64"
ARCH: 64
+ - GENERATOR: "MSYS Makefiles"
+ ARCH: 32
+ - GENERATOR: "MSYS Makefiles"
+ ARCH: i686 # this is for 32-bit MinGW-w64
+ - GENERATOR: "MSYS Makefiles"
+ ARCH: 64
+matrix:
+ allow_failures:
+ - GENERATOR: "MSYS Makefiles"
+ ARCH: 32
+cache:
+- i686-4.9.2-release-win32-sjlj-rt_v3-rev1.7z
+- x86_64-4.9.2-release-win32-seh-rt_v3-rev1.7z
build_script:
- ps: |
mkdir build
cd build
- cmake -D ENABLE_TRACE=ON -D BUILD_CLAR=ON .. -G"$env:GENERATOR"
- cmake --build . --config RelWithDebInfo
+ if ($env:GENERATOR -ne "MSYS Makefiles") {
+ cmake -D ENABLE_TRACE=ON -D BUILD_CLAR=ON .. -G"$env:GENERATOR"
+ cmake --build . --config RelWithDebInfo
+ }
+- cmd: |
+ if "%GENERATOR%"=="MSYS Makefiles" (C:\MinGW\msys\1.0\bin\sh --login /c/projects/libgit2/script/appveyor-mingw.sh)
test_script:
- ps: ctest -V .
diff --git a/examples/describe.c b/examples/describe.c
index 72d981153..f7b4b1c20 100644
--- a/examples/describe.c
+++ b/examples/describe.c
@@ -13,6 +13,7 @@
*/
#include "common.h"
+#include <assert.h>
/**
* The following example partially reimplements the `git describe` command
@@ -46,6 +47,27 @@ typedef struct {
typedef struct args_info args_info;
+static void *xrealloc(void *oldp, size_t newsz)
+{
+ void *p = realloc(oldp, newsz);
+ if (p == NULL) {
+ fprintf(stderr, "Cannot allocate memory, exiting.\n");
+ exit(1);
+ }
+ return p;
+}
+
+static void opts_add_commit(describe_options *opts, const char *commit)
+{
+ size_t sz;
+
+ assert(opts != NULL);
+
+ sz = ++opts->commit_count * sizeof(opts->commits[0]);
+ opts->commits = xrealloc(opts->commits, sz);
+ opts->commits[opts->commit_count - 1] = commit;
+}
+
static void do_describe_single(git_repository *repo, describe_options *opts, const char *rev)
{
git_object *commit;
@@ -96,9 +118,7 @@ static void parse_options(describe_options *opts, int argc, char **argv)
const char *curr = argv[args.pos];
if (curr[0] != '-') {
- size_t newsz = ++opts->commit_count * sizeof(opts->commits[0]);
- opts->commits = (const char **)realloc((void *)opts->commits, newsz);
- opts->commits[opts->commit_count - 1] = curr;
+ opts_add_commit(opts, curr);
} else if (!strcmp(curr, "--all")) {
opts->describe_options.describe_strategy = GIT_DESCRIBE_ALL;
} else if (!strcmp(curr, "--tags")) {
@@ -124,9 +144,7 @@ static void parse_options(describe_options *opts, int argc, char **argv)
}
else {
if (!opts->format_options.dirty_suffix || !opts->format_options.dirty_suffix[0]) {
- size_t sz = ++opts->commit_count * sizeof(opts->commits[0]);
- opts->commits = (const char **)malloc(sz);
- opts->commits[0] = "HEAD";
+ opts_add_commit(opts, "HEAD");
}
}
}
diff --git a/examples/network/clone.c b/examples/network/clone.c
index 6144e217e..270bb68be 100644
--- a/examples/network/clone.c
+++ b/examples/network/clone.c
@@ -82,7 +82,7 @@ int do_clone(git_repository *repo, int argc, char **argv)
}
// Set up options
- checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
checkout_opts.progress_cb = checkout_progress;
checkout_opts.progress_payload = &pd;
clone_opts.checkout_opts = checkout_opts;
diff --git a/examples/network/fetch.c b/examples/network/fetch.c
index adde73c17..a4bec032e 100644
--- a/examples/network/fetch.c
+++ b/examples/network/fetch.c
@@ -156,7 +156,7 @@ int fetch(git_repository *repo, int argc, char **argv)
// right commits. This may be needed even if there was no packfile
// to download, which can happen e.g. when the branches have been
// changed but all the needed objects are available locally.
- if (git_remote_update_tips(remote, NULL, NULL) < 0)
+ if (git_remote_update_tips(remote, NULL) < 0)
return -1;
git_remote_free(remote);
diff --git a/include/git2/branch.h b/include/git2/branch.h
index 43aa20f77..06f4d2c68 100644
--- a/include/git2/branch.h
+++ b/include/git2/branch.h
@@ -43,12 +43,6 @@ GIT_BEGIN_DECL
*
* @param force Overwrite existing branch.
*
- * @param signature The identity that will used to populate the reflog entry
- *
- * @param log_message The one line long message to be appended to the reflog.
- * If NULL, the default is "Branch: created"; if you want something more
- * useful, provide a message.
- *
* @return 0, GIT_EINVALIDSPEC or an error code.
* A proper reference is written in the refs/heads namespace
* pointing to the provided target commit.
@@ -58,9 +52,7 @@ GIT_EXTERN(int) git_branch_create(
git_repository *repo,
const char *branch_name,
const git_commit *target,
- int force,
- const git_signature *signature,
- const char *log_message);
+ int force);
/**
* Delete an existing branch reference.
@@ -123,19 +115,13 @@ GIT_EXTERN(void) git_branch_iterator_free(git_branch_iterator *iter);
*
* @param force Overwrite existing branch.
*
- * @param signature The identity that will used to populate the reflog entry
- *
- * @param log_message The one line long message to be appended to the reflog
- *
* @return 0 on success, GIT_EINVALIDSPEC or an error code.
*/
GIT_EXTERN(int) git_branch_move(
git_reference **out,
git_reference *branch,
const char *new_branch_name,
- int force,
- const git_signature *signature,
- const char *log_message);
+ int force);
/**
* Lookup a branch by its name in a repository.
diff --git a/include/git2/checkout.h b/include/git2/checkout.h
index 4fe1340b9..ed39bd3cb 100644
--- a/include/git2/checkout.h
+++ b/include/git2/checkout.h
@@ -31,7 +31,7 @@ GIT_BEGIN_DECL
* check out, the "baseline" tree of what was checked out previously, the
* working directory for actual files, and the index for staged changes.
*
- * You give checkout one of four strategies for update:
+ * You give checkout one of three strategies for update:
*
* - `GIT_CHECKOUT_NONE` is a dry-run strategy that checks for conflicts,
* etc., but doesn't make any actual changes.
@@ -40,8 +40,8 @@ GIT_BEGIN_DECL
* make the working directory match the target (including potentially
* discarding modified files).
*
- * In between those are `GIT_CHECKOUT_SAFE` and `GIT_CHECKOUT_SAFE_CREATE`
- * both of which only make modifications that will not lose changes.
+ * - `GIT_CHECKOUT_SAFE` is between these two options, it will only make
+ * modifications that will not lose changes.
*
* | target == baseline | target != baseline |
* ---------------------|-----------------------|----------------------|
@@ -51,28 +51,21 @@ GIT_BEGIN_DECL
* workdir exists and | no action | conflict (notify |
* is != baseline | notify dirty MODIFIED | and cancel checkout) |
* ---------------------|-----------------------|----------------------|
- * workdir missing, | create if SAFE_CREATE | create file |
- * baseline present | notify dirty DELETED | |
+ * workdir missing, | notify dirty DELETED | create file |
+ * baseline present | | |
* ---------------------|-----------------------|----------------------|
*
- * The only difference between SAFE and SAFE_CREATE is that SAFE_CREATE
- * will cause a file to be checked out if it is missing from the working
- * directory even if it is not modified between the target and baseline.
- *
- *
* To emulate `git checkout`, use `GIT_CHECKOUT_SAFE` with a checkout
* notification callback (see below) that displays information about dirty
* files. The default behavior will cancel checkout on conflicts.
*
- * To emulate `git checkout-index`, use `GIT_CHECKOUT_SAFE_CREATE` with a
+ * To emulate `git checkout-index`, use `GIT_CHECKOUT_SAFE` with a
* notification callback that cancels the operation if a dirty-but-existing
* file is found in the working directory. This core git command isn't
* quite "force" but is sensitive about some types of changes.
*
* To emulate `git checkout -f`, use `GIT_CHECKOUT_FORCE`.
*
- * To emulate `git clone` use `GIT_CHECKOUT_SAFE_CREATE` in the options.
- *
*
* There are some additional flags to modified the behavior of checkout:
*
@@ -116,12 +109,12 @@ typedef enum {
/** Allow safe updates that cannot overwrite uncommitted data */
GIT_CHECKOUT_SAFE = (1u << 0),
- /** Allow safe updates plus creation of missing files */
- GIT_CHECKOUT_SAFE_CREATE = (1u << 1),
-
/** Allow all updates to force working directory to look like index */
- GIT_CHECKOUT_FORCE = (1u << 2),
+ GIT_CHECKOUT_FORCE = (1u << 1),
+
+ /** Allow checkout to recreate missing files */
+ GIT_CHECKOUT_RECREATE_MISSING = (1u << 2),
/** Allow checkout to make safe updates even if conflicts are found */
GIT_CHECKOUT_ALLOW_CONFLICTS = (1u << 4),
diff --git a/include/git2/clone.h b/include/git2/clone.h
index 464408534..d3bd42485 100644
--- a/include/git2/clone.h
+++ b/include/git2/clone.h
@@ -106,9 +106,7 @@ typedef struct git_clone_options {
/**
* These options are passed to the checkout step. To disable
* checkout, set the `checkout_strategy` to
- * `GIT_CHECKOUT_NONE`. Generally you will want the use
- * GIT_CHECKOUT_SAFE_CREATE to create all files in the working
- * directory for the newly cloned repository.
+ * `GIT_CHECKOUT_NONE`.
*/
git_checkout_options checkout_opts;
@@ -139,12 +137,6 @@ typedef struct git_clone_options {
const char* checkout_branch;
/**
- * The identity used when updating the reflog. NULL means to
- * use the default signature using the config.
- */
- git_signature *signature;
-
- /**
* A callback used to create the new repository into which to
* clone. If NULL, the 'bare' field will be used to determine
* whether to create a bare repository.
@@ -173,7 +165,9 @@ typedef struct git_clone_options {
} git_clone_options;
#define GIT_CLONE_OPTIONS_VERSION 1
-#define GIT_CLONE_OPTIONS_INIT {GIT_CLONE_OPTIONS_VERSION, {GIT_CHECKOUT_OPTIONS_VERSION, GIT_CHECKOUT_SAFE_CREATE}, GIT_REMOTE_CALLBACKS_INIT}
+#define GIT_CLONE_OPTIONS_INIT { GIT_CLONE_OPTIONS_VERSION, \
+ { GIT_CHECKOUT_OPTIONS_VERSION, GIT_CHECKOUT_SAFE }, \
+ GIT_REMOTE_CALLBACKS_INIT }
/**
* Initializes a `git_clone_options` with default values. Equivalent to
diff --git a/include/git2/config.h b/include/git2/config.h
index 70c8beade..6d3fdb0c2 100644
--- a/include/git2/config.h
+++ b/include/git2/config.h
@@ -58,12 +58,19 @@ typedef enum {
/**
* An entry in a configuration file
*/
-typedef struct {
+typedef struct git_config_entry {
const char *name; /**< Name of the entry (normalised) */
const char *value; /**< String value of the entry */
git_config_level_t level; /**< Which config file this was found in */
+ void (*free)(struct git_config_entry *entry); /**< Free function for this entry */
+ void *payload; /**< Opaque value for the free function. Do not read or write */
} git_config_entry;
+/**
+ * Free a config entry
+ */
+GIT_EXTERN(void) git_config_entry_free(git_config_entry *);
+
typedef int (*git_config_foreach_cb)(const git_config_entry *, void *);
typedef struct git_config_iterator git_config_iterator;
@@ -261,16 +268,15 @@ GIT_EXTERN(void) git_config_free(git_config *cfg);
/**
* Get the git_config_entry of a config variable.
*
- * The git_config_entry is owned by the config and should not be freed by the
- * user.
-
+ * Free the git_config_entry after use with `git_config_entry_free()`.
+ *
* @param out pointer to the variable git_config_entry
* @param cfg where to look for the variable
* @param name the variable's name
* @return 0 or an error code
*/
GIT_EXTERN(int) git_config_get_entry(
- const git_config_entry **out,
+ git_config_entry **out,
const git_config *cfg,
const char *name);
@@ -340,15 +346,15 @@ GIT_EXTERN(int) git_config_get_path(git_buf *out, const git_config *cfg, const c
/**
* Get the value of a string config variable.
*
- * The string is owned by the variable and should not be freed by the
- * user. The pointer will be valid until the next operation on this
- * config object.
+ * This function can only be used on snapshot config objects. The
+ * string is owned by the config and should not be freed by the
+ * user. The pointer will be valid until the config is freed.
*
* All config files will be looked into, in the order of their
* defined level. A higher level means a higher priority. The
* first occurrence of the variable will be returned here.
*
- * @param out pointer to the variable's value
+ * @param out pointer to the string
* @param cfg where to look for the variable
* @param name the variable's name
* @return 0 or an error code
@@ -356,6 +362,22 @@ GIT_EXTERN(int) git_config_get_path(git_buf *out, const git_config *cfg, const c
GIT_EXTERN(int) git_config_get_string(const char **out, const git_config *cfg, const char *name);
/**
+ * Get the value of a string config variable.
+ *
+ * The value of the config will be copied into the buffer.
+ *
+ * All config files will be looked into, in the order of their
+ * defined level. A higher level means a higher priority. The
+ * first occurrence of the variable will be returned here.
+ *
+ * @param out buffer in which to store the string
+ * @param cfg where to look for the variable
+ * @param name the variable's name
+ * @return 0 or an error code
+ */
+GIT_EXTERN(int) git_config_get_string_buf(git_buf *out, const git_config *cfg, const char *name);
+
+/**
* Get each value of a multivar in a foreach callback
*
* The callback will be called on each variable found
diff --git a/include/git2/rebase.h b/include/git2/rebase.h
index 19f5cb8c9..58b66b7fa 100644
--- a/include/git2/rebase.h
+++ b/include/git2/rebase.h
@@ -139,7 +139,6 @@ GIT_EXTERN(int) git_rebase_init_options(
* reachable commits
* @param onto The branch to rebase onto, or NULL to rebase onto the given
* upstream
- * @param signature The signature of the rebaser (optional)
* @param opts Options to specify how rebase is performed
* @return Zero on success; -1 on failure.
*/
@@ -149,7 +148,6 @@ GIT_EXTERN(int) git_rebase_init(
const git_annotated_commit *branch,
const git_annotated_commit *upstream,
const git_annotated_commit *onto,
- const git_signature *signature,
const git_rebase_options *opts);
/**
@@ -241,13 +239,10 @@ GIT_EXTERN(int) git_rebase_commit(
* and working directory to their state before rebase began.
*
* @param rebase The rebase that is in-progress
- * @param signature The identity that is aborting the rebase
* @return Zero on success; GIT_ENOTFOUND if a rebase is not in progress,
* -1 on other errors.
*/
-GIT_EXTERN(int) git_rebase_abort(
- git_rebase *rebase,
- const git_signature *signature);
+GIT_EXTERN(int) git_rebase_abort(git_rebase *rebase);
/**
* Finishes a rebase that is currently in progress once all patches have
diff --git a/include/git2/refs.h b/include/git2/refs.h
index 43dda7ca4..db84ed03a 100644
--- a/include/git2/refs.h
+++ b/include/git2/refs.h
@@ -89,9 +89,9 @@ GIT_EXTERN(int) git_reference_dwim(git_reference **out, git_repository *repo, co
* This function will return an error if a reference already exists with the
* given name unless `force` is true, in which case it will be overwritten.
*
- * The signature and message for the reflog will be ignored if the
- * reference does not belong in the standard set (HEAD, branches and
- * remote-tracking branches) and it does not have a reflog.
+ * The message for the reflog will be ignored if the reference does
+ * not belong in the standard set (HEAD, branches and remote-tracking
+ * branches) and it does not have a reflog.
*
* It will return GIT_EMODIFIED if the reference's value at the time
* of updating does not match the one passed through `current_value`
@@ -103,11 +103,10 @@ GIT_EXTERN(int) git_reference_dwim(git_reference **out, git_repository *repo, co
* @param target The target of the reference
* @param force Overwrite existing references
* @param current_value The expected value of the reference when updating
- * @param signature The identity that will used to populate the reflog entry
* @param log_message The one line long message to be appended to the reflog
* @return 0 on success, GIT_EEXISTS, GIT_EINVALIDSPEC, GIT_EMODIFIED or an error code
*/
-GIT_EXTERN(int) git_reference_symbolic_create_matching(git_reference **out, git_repository *repo, const char *name, const char *target, int force, const char *current_value, const git_signature *signature, const char *log_message);
+GIT_EXTERN(int) git_reference_symbolic_create_matching(git_reference **out, git_repository *repo, const char *name, const char *target, int force, const char *current_value, const char *log_message);
/**
* Create a new symbolic reference.
@@ -131,20 +130,19 @@ GIT_EXTERN(int) git_reference_symbolic_create_matching(git_reference **out, git_
* This function will return an error if a reference already exists with the
* given name unless `force` is true, in which case it will be overwritten.
*
- * The signature and message for the reflog will be ignored if the
- * reference does not belong in the standard set (HEAD, branches and
- * remote-tracking branches) and it does not have a reflog.
+ * The message for the reflog will be ignored if the reference does
+ * not belong in the standard set (HEAD, branches and remote-tracking
+ * branches) and it does not have a reflog.
*
* @param out Pointer to the newly created reference
* @param repo Repository where that reference will live
* @param name The name of the reference
* @param target The target of the reference
* @param force Overwrite existing references
- * @param signature The identity that will used to populate the reflog entry
* @param log_message The one line long message to be appended to the reflog
* @return 0 on success, GIT_EEXISTS, GIT_EINVALIDSPEC or an error code
*/
-GIT_EXTERN(int) git_reference_symbolic_create(git_reference **out, git_repository *repo, const char *name, const char *target, int force, const git_signature *signature, const char *log_message);
+GIT_EXTERN(int) git_reference_symbolic_create(git_reference **out, git_repository *repo, const char *name, const char *target, int force, const char *log_message);
/**
* Create a new direct reference.
@@ -169,20 +167,19 @@ GIT_EXTERN(int) git_reference_symbolic_create(git_reference **out, git_repositor
* This function will return an error if a reference already exists with the
* given name unless `force` is true, in which case it will be overwritten.
*
- * The signature and message for the reflog will be ignored if the
- * reference does not belong in the standard set (HEAD, branches and
- * remote-tracking branches) and and it does not have a reflog.
+ * The message for the reflog will be ignored if the reference does
+ * not belong in the standard set (HEAD, branches and remote-tracking
+ * branches) and and it does not have a reflog.
*
* @param out Pointer to the newly created reference
* @param repo Repository where that reference will live
* @param name The name of the reference
* @param id The object id pointed to by the reference.
* @param force Overwrite existing references
- * @param signature The identity that will used to populate the reflog entry
* @param log_message The one line long message to be appended to the reflog
* @return 0 on success, GIT_EEXISTS, GIT_EINVALIDSPEC or an error code
*/
-GIT_EXTERN(int) git_reference_create(git_reference **out, git_repository *repo, const char *name, const git_oid *id, int force, const git_signature *signature, const char *log_message);
+GIT_EXTERN(int) git_reference_create(git_reference **out, git_repository *repo, const char *name, const git_oid *id, int force, const char *log_message);
/**
* Conditionally create new direct reference
@@ -207,9 +204,9 @@ GIT_EXTERN(int) git_reference_create(git_reference **out, git_repository *repo,
* This function will return an error if a reference already exists with the
* given name unless `force` is true, in which case it will be overwritten.
*
- * The signature and message for the reflog will be ignored if the
- * reference does not belong in the standard set (HEAD, branches and
- * remote-tracking branches) and and it does not have a reflog.
+ * The message for the reflog will be ignored if the reference does
+ * not belong in the standard set (HEAD, branches and remote-tracking
+ * branches) and and it does not have a reflog.
*
* It will return GIT_EMODIFIED if the reference's value at the time
* of updating does not match the one passed through `current_id`
@@ -221,12 +218,11 @@ GIT_EXTERN(int) git_reference_create(git_reference **out, git_repository *repo,
* @param id The object id pointed to by the reference.
* @param force Overwrite existing references
* @param current_id The expected value of the reference at the time of update
- * @param signature The identity that will used to populate the reflog entry
* @param log_message The one line long message to be appended to the reflog
* @return 0 on success, GIT_EMODIFIED if the value of the reference
* has changed, GIT_EEXISTS, GIT_EINVALIDSPEC or an error code
*/
-GIT_EXTERN(int) git_reference_create_matching(git_reference **out, git_repository *repo, const char *name, const git_oid *id, int force, const git_oid *current_id, const git_signature *signature, const char *log_message);
+GIT_EXTERN(int) git_reference_create_matching(git_reference **out, git_repository *repo, const char *name, const git_oid *id, int force, const git_oid *current_id, const char *log_message);
/**
* Get the OID pointed to by a direct reference.
@@ -320,14 +316,13 @@ GIT_EXTERN(git_repository *) git_reference_owner(const git_reference *ref);
* The target name will be checked for validity.
* See `git_reference_symbolic_create()` for rules about valid names.
*
- * The signature and message for the reflog will be ignored if the
- * reference does not belong in the standard set (HEAD, branches and
- * remote-tracking branches) and and it does not have a reflog.
+ * The message for the reflog will be ignored if the reference does
+ * not belong in the standard set (HEAD, branches and remote-tracking
+ * branches) and and it does not have a reflog.
*
* @param out Pointer to the newly created reference
* @param ref The reference
* @param target The new target for the reference
- * @param signature The identity that will used to populate the reflog entry
* @param log_message The one line long message to be appended to the reflog
* @return 0 on success, GIT_EINVALIDSPEC or an error code
*/
@@ -335,7 +330,6 @@ GIT_EXTERN(int) git_reference_symbolic_set_target(
git_reference **out,
git_reference *ref,
const char *target,
- const git_signature *signature,
const char *log_message);
/**
@@ -348,7 +342,6 @@ GIT_EXTERN(int) git_reference_symbolic_set_target(
* @param out Pointer to the newly created reference
* @param ref The reference
* @param id The new target OID for the reference
- * @param signature The identity that will used to populate the reflog entry
* @param log_message The one line long message to be appended to the reflog
* @return 0 on success, GIT_EMODIFIED if the value of the reference
* has changed since it was read, or an error code
@@ -357,7 +350,6 @@ GIT_EXTERN(int) git_reference_set_target(
git_reference **out,
git_reference *ref,
const git_oid *id,
- const git_signature *signature,
const char *log_message);
/**
@@ -379,7 +371,6 @@ GIT_EXTERN(int) git_reference_set_target(
* @param ref The reference to rename
* @param new_name The new name for the reference
* @param force Overwrite an existing reference
- * @param signature The identity that will used to populate the reflog entry
* @param log_message The one line long message to be appended to the reflog
* @return 0 on success, GIT_EINVALIDSPEC, GIT_EEXISTS or an error code
*
@@ -389,7 +380,6 @@ GIT_EXTERN(int) git_reference_rename(
git_reference *ref,
const char *new_name,
int force,
- const git_signature *signature,
const char *log_message);
/**
diff --git a/include/git2/remote.h b/include/git2/remote.h
index 2bfc35f4b..f85c38429 100644
--- a/include/git2/remote.h
+++ b/include/git2/remote.h
@@ -376,15 +376,14 @@ GIT_EXTERN(void) git_remote_free(git_remote *remote);
* Update the tips to the new state
*
* @param remote the remote to update
- * @param signature The identity to use when updating reflogs
- * @param reflog_message The message to insert into the reflogs. If NULL, the
- * default is "fetch <name>", where <name> is the name of
- * the remote (or its url, for in-memory remotes).
+ * @param reflog_message The message to insert into the reflogs. If
+ * NULL and fetching, the default is "fetch <name>", where <name> is
+ * the name of the remote (or its url, for in-memory remotes). This
+ * parameter is ignored when pushing.
* @return 0 or an error code
*/
GIT_EXTERN(int) git_remote_update_tips(
git_remote *remote,
- const git_signature *signature,
const char *reflog_message);
/**
@@ -404,7 +403,6 @@ GIT_EXTERN(int) git_remote_prune(git_remote *remote);
* @param remote the remote to fetch from
* @param refspecs the refspecs to use for this fetch. Pass NULL or an
* empty array to use the base refspecs.
- * @param signature The identity to use when updating reflogs
* @param reflog_message The message to insert into the reflogs. If NULL, the
* default is "fetch"
* @return 0 or an error code
@@ -412,7 +410,6 @@ GIT_EXTERN(int) git_remote_prune(git_remote *remote);
GIT_EXTERN(int) git_remote_fetch(
git_remote *remote,
const git_strarray *refspecs,
- const git_signature *signature,
const char *reflog_message);
/**
@@ -424,13 +421,10 @@ GIT_EXTERN(int) git_remote_fetch(
* @param refspecs the refspecs to use for pushing. If none are
* passed, the configured refspecs will be used
* @param opts the options
- * @param signature signature to use for the reflog of updated references
- * @param reflog_message message to use for the reflog of upated references
*/
GIT_EXTERN(int) git_remote_push(git_remote *remote,
const git_strarray *refspecs,
- const git_push_options *opts,
- const git_signature *signature, const char *reflog_message);
+ const git_push_options *opts);
/**
* Get a list of the configured remotes for a repo
diff --git a/include/git2/repository.h b/include/git2/repository.h
index 2fb381316..e3ff3b375 100644
--- a/include/git2/repository.h
+++ b/include/git2/repository.h
@@ -603,15 +603,11 @@ GIT_EXTERN(int) git_repository_hashfile(
*
* @param repo Repository pointer
* @param refname Canonical name of the reference the HEAD should point at
- * @param signature The identity that will used to populate the reflog entry
- * @param log_message The one line long message to be appended to the reflog
* @return 0 on success, or an error code
*/
GIT_EXTERN(int) git_repository_set_head(
git_repository* repo,
- const char* refname,
- const git_signature *signature,
- const char *log_message);
+ const char* refname);
/**
* Make the repository HEAD directly point to the Commit.
@@ -627,15 +623,11 @@ GIT_EXTERN(int) git_repository_set_head(
*
* @param repo Repository pointer
* @param commitish Object id of the Commit the HEAD should point to
- * @param signature The identity that will used to populate the reflog entry
- * @param log_message The one line long message to be appended to the reflog
* @return 0 on success, or an error code
*/
GIT_EXTERN(int) git_repository_set_head_detached(
git_repository* repo,
- const git_oid* commitish,
- const git_signature *signature,
- const char *log_message);
+ const git_oid* commitish);
/**
* Detach the HEAD.
@@ -651,15 +643,11 @@ GIT_EXTERN(int) git_repository_set_head_detached(
* Otherwise, the HEAD will be detached and point to the peeled Commit.
*
* @param repo Repository pointer
- * @param signature The identity that will used to populate the reflog entry
- * @param reflog_message The one line long message to be appended to the reflog
* @return 0 on success, GIT_EUNBORNBRANCH when HEAD points to a non existing
* branch or an error code
*/
GIT_EXTERN(int) git_repository_detach_head(
- git_repository* repo,
- const git_signature *signature,
- const char *reflog_message);
+ git_repository* repo);
/**
* Repository state
@@ -720,6 +708,31 @@ GIT_EXTERN(const char *) git_repository_get_namespace(git_repository *repo);
*/
GIT_EXTERN(int) git_repository_is_shallow(git_repository *repo);
+/**
+ * Retrieve the configured identity to use for reflogs
+ *
+ * The memory is owned by the repository and must not be freed by the
+ * user.
+ *
+ * @param name where to store the pointer to the name
+ * @param email where to store the pointer to the email
+ * @param repo the repository
+ */
+GIT_EXTERN(int) git_repository_ident(const char **name, const char **email, const git_repository *repo);
+
+/**
+ * Set the identity to be used for writing reflogs
+ *
+ * If both are set, this name and email will be used to write to the
+ * reflog. Pass NULL to unset. When unset, the identity will be taken
+ * from the repository's configuration.
+ *
+ * @param repo the repository to configure
+ * @param name the name to use for the reflog entries
+ * @param name the email to use for the reflog entries
+ */
+GIT_EXTERN(int) git_repository_set_ident(git_repository *repo, const char *name, const char *email);
+
/** @} */
GIT_END_DECL
#endif
diff --git a/include/git2/reset.h b/include/git2/reset.h
index 53f3e891e..93ac0b29c 100644
--- a/include/git2/reset.h
+++ b/include/git2/reset.h
@@ -56,22 +56,13 @@ typedef enum {
* The checkout_strategy field will be overridden (based on reset_type).
* This parameter can be used to propagate notify and progress callbacks.
*
- * @param signature The identity that will used to populate the reflog entry
- *
- * @param log_message The one line long message to be appended to the reflog.
- * The reflog is only updated if the affected direct reference is actually
- * changing. If NULL, the default is "reset: moving"; if you want something more
- * useful, provide a message.
- *
* @return 0 on success or an error code
*/
GIT_EXTERN(int) git_reset(
git_repository *repo,
git_object *target,
git_reset_t reset_type,
- git_checkout_options *checkout_opts,
- const git_signature *signature,
- const char *log_message);
+ git_checkout_options *checkout_opts);
/**
* Updates some entries in the index from the target commit tree.
diff --git a/include/git2/submodule.h b/include/git2/submodule.h
index f03ea2da8..245b2a2c1 100644
--- a/include/git2/submodule.h
+++ b/include/git2/submodule.h
@@ -137,23 +137,17 @@ typedef struct git_submodule_update_options {
/**
* The checkout strategy to use when the sub repository needs to
- * be cloned. Use GIT_CHECKOUT_SAFE_CREATE to create all files
+ * be cloned. Use GIT_CHECKOUT_SAFE to create all files
* in the working directory for the newly cloned repository.
*/
unsigned int clone_checkout_strategy;
-
- /**
- * The identity used when updating the reflog. NULL means to
- * use the default signature using the config.
- */
- git_signature *signature;
} git_submodule_update_options;
#define GIT_SUBMODULE_UPDATE_OPTIONS_VERSION 1
#define GIT_SUBMODULE_UPDATE_OPTIONS_INIT \
{ GIT_CHECKOUT_OPTIONS_VERSION, \
- { GIT_CHECKOUT_OPTIONS_VERSION, GIT_CHECKOUT_SAFE}, \
- GIT_REMOTE_CALLBACKS_INIT, GIT_CHECKOUT_SAFE_CREATE }
+ { GIT_CHECKOUT_OPTIONS_VERSION, GIT_CHECKOUT_SAFE }, \
+ GIT_REMOTE_CALLBACKS_INIT, GIT_CHECKOUT_SAFE }
/**
* Initializes a `git_submodule_update_options` with default values.
diff --git a/include/git2/sys/config.h b/include/git2/sys/config.h
index 9136635ef..b5b7df15f 100644
--- a/include/git2/sys/config.h
+++ b/include/git2/sys/config.h
@@ -53,11 +53,13 @@ struct git_config_iterator {
*/
struct git_config_backend {
unsigned int version;
+ /** True if this backend is for a snapshot */
+ int readonly;
struct git_config *cfg;
/* Open means open the file/database and parse if necessary */
int (*open)(struct git_config_backend *, git_config_level_t level);
- int (*get)(struct git_config_backend *, const char *key, const git_config_entry **entry);
+ int (*get)(struct git_config_backend *, const char *key, git_config_entry **entry);
int (*set)(struct git_config_backend *, const char *key, const char *value);
int (*set_multivar)(git_config_backend *cfg, const char *name, const char *regexp, const char *value);
int (*del)(struct git_config_backend *, const char *key);
diff --git a/include/git2/version.h b/include/git2/version.h
index a330685e0..456bbe258 100644
--- a/include/git2/version.h
+++ b/include/git2/version.h
@@ -11,6 +11,7 @@
#define LIBGIT2_VER_MAJOR 0
#define LIBGIT2_VER_MINOR 22
#define LIBGIT2_VER_REVISION 0
+#define LIBGIT2_VER_PATCH 0
#define LIBGIT2_SOVERSION 22
diff --git a/script/appveyor-mingw.sh b/script/appveyor-mingw.sh
new file mode 100755
index 000000000..48e0bad0a
--- /dev/null
+++ b/script/appveyor-mingw.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+set -e
+cd `dirname "$0"`/..
+if [ "$ARCH" = "32" ]; then
+ echo 'C:\MinGW\ /MinGW' > /etc/fstab
+elif [ "$ARCH" = "i686" ]; then
+ f=i686-4.9.2-release-win32-sjlj-rt_v3-rev1.7z
+ if ! [ -e $f ]; then
+ curl -LsSO http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/4.9.2/threads-win32/sjlj/$f
+ fi
+ 7z x $f > /dev/null
+ mv mingw32 /MinGW
+else
+ f=x86_64-4.9.2-release-win32-seh-rt_v3-rev1.7z
+ if ! [ -e $f ]; then
+ curl -LsSO http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/4.9.2/threads-win32/seh/$f
+ fi
+ 7z x $f > /dev/null
+ mv mingw64 /MinGW
+fi
+cd build
+cmake -D ENABLE_TRACE=ON -D BUILD_CLAR=ON .. -G"$GENERATOR"
+cmake --build . --config RelWithDebInfo
diff --git a/src/attrcache.c b/src/attrcache.c
index 018fa4874..5bc260460 100644
--- a/src/attrcache.c
+++ b/src/attrcache.c
@@ -276,7 +276,7 @@ static int attr_cache__lookup_path(
{
git_buf buf = GIT_BUF_INIT;
int error;
- const git_config_entry *entry = NULL;
+ git_config_entry *entry = NULL;
*out = NULL;
@@ -296,6 +296,7 @@ static int attr_cache__lookup_path(
else if (!git_sysdir_find_xdg_file(&buf, fallback))
*out = git_buf_detach(&buf);
+ git_config_entry_free(entry);
git_buf_free(&buf);
return error;
diff --git a/src/branch.c b/src/branch.c
index b4e4b0564..a16d3a3f9 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -54,14 +54,12 @@ int git_branch_create(
git_repository *repository,
const char *branch_name,
const git_commit *commit,
- int force,
- const git_signature *signature,
- const char *log_message)
+ int force)
{
int is_head = 0;
git_reference *branch = NULL;
git_buf canonical_branch_name = GIT_BUF_INIT,
- log_message_buf = GIT_BUF_INIT;
+ log_message = GIT_BUF_INIT;
int error = -1;
assert(branch_name && commit && ref_out);
@@ -84,23 +82,23 @@ int git_branch_create(
error = -1;
goto cleanup;
}
-
+
if (git_buf_joinpath(&canonical_branch_name, GIT_REFS_HEADS_DIR, branch_name) < 0)
goto cleanup;
- if (git_buf_sets(&log_message_buf, log_message ? log_message : "Branch: created") < 0)
+ if (git_buf_printf(&log_message, "branch: Created from %s", git_oid_tostr_s(git_commit_id(commit))) < 0)
goto cleanup;
error = git_reference_create(&branch, repository,
- git_buf_cstr(&canonical_branch_name), git_commit_id(commit), force, signature,
- git_buf_cstr(&log_message_buf));
+ git_buf_cstr(&canonical_branch_name), git_commit_id(commit), force,
+ git_buf_cstr(&log_message));
if (!error)
*ref_out = branch;
cleanup:
git_buf_free(&canonical_branch_name);
- git_buf_free(&log_message_buf);
+ git_buf_free(&log_message);
return error;
}
@@ -138,8 +136,13 @@ int git_branch_delete(git_reference *branch)
if (git_reference_delete(branch) < 0)
goto on_error;
- if (git_reflog_delete(git_reference_owner(branch), git_reference_name(branch)) < 0)
+ if ((error = git_reflog_delete(git_reference_owner(branch), git_reference_name(branch))) < 0) {
+ if (error == GIT_ENOTFOUND) {
+ giterr_clear();
+ error = 0;
+ }
goto on_error;
+ }
error = 0;
@@ -217,14 +220,12 @@ int git_branch_move(
git_reference **out,
git_reference *branch,
const char *new_branch_name,
- int force,
- const git_signature *signature,
- const char *log_message)
+ int force)
{
git_buf new_reference_name = GIT_BUF_INIT,
old_config_section = GIT_BUF_INIT,
new_config_section = GIT_BUF_INIT,
- log_message_buf = GIT_BUF_INIT;
+ log_message = GIT_BUF_INIT;
int error;
assert(branch && new_branch_name);
@@ -235,20 +236,15 @@ int git_branch_move(
if ((error = git_buf_joinpath(&new_reference_name, GIT_REFS_HEADS_DIR, new_branch_name)) < 0)
goto done;
- if (log_message) {
- if ((error = git_buf_sets(&log_message_buf, log_message)) < 0)
- goto done;
- } else {
- if ((error = git_buf_printf(&log_message_buf, "Branch: renamed %s to %s",
- git_reference_name(branch), git_buf_cstr(&new_reference_name))) < 0)
+ if ((error = git_buf_printf(&log_message, "branch: renamed %s to %s",
+ git_reference_name(branch), git_buf_cstr(&new_reference_name))) < 0)
goto done;
- }
/* first update ref then config so failure won't trash config */
error = git_reference_rename(
out, branch, git_buf_cstr(&new_reference_name), force,
- signature, git_buf_cstr(&log_message_buf));
+ git_buf_cstr(&log_message));
if (error < 0)
goto done;
@@ -265,7 +261,7 @@ done:
git_buf_free(&new_reference_name);
git_buf_free(&old_config_section);
git_buf_free(&new_config_section);
- git_buf_free(&log_message_buf);
+ git_buf_free(&log_message);
return error;
}
@@ -305,7 +301,7 @@ int git_branch_name(
}
static int retrieve_upstream_configuration(
- const char **out,
+ git_buf *out,
const git_config *config,
const char *canonical_branch_name,
const char *format)
@@ -317,7 +313,7 @@ static int retrieve_upstream_configuration(
canonical_branch_name + strlen(GIT_REFS_HEADS_DIR)) < 0)
return -1;
- error = git_config_get_string(out, config, git_buf_cstr(&buf));
+ error = git_config_get_string_buf(out, config, git_buf_cstr(&buf));
git_buf_free(&buf);
return error;
}
@@ -327,7 +323,8 @@ int git_branch_upstream_name(
git_repository *repo,
const char *refname)
{
- const char *remote_name, *merge_name;
+ git_buf remote_name = GIT_BUF_INIT;
+ git_buf merge_name = GIT_BUF_INIT;
git_buf buf = GIT_BUF_INIT;
int error = -1;
git_remote *remote = NULL;
@@ -352,27 +349,27 @@ int git_branch_upstream_name(
&merge_name, config, refname, "branch.%s.merge")) < 0)
goto cleanup;
- if (!*remote_name || !*merge_name) {
+ if (git_buf_len(&remote_name) == 0 || git_buf_len(&merge_name) == 0) {
giterr_set(GITERR_REFERENCE,
"branch '%s' does not have an upstream", refname);
error = GIT_ENOTFOUND;
goto cleanup;
}
- if (strcmp(".", remote_name) != 0) {
- if ((error = git_remote_lookup(&remote, repo, remote_name)) < 0)
+ if (strcmp(".", git_buf_cstr(&remote_name)) != 0) {
+ if ((error = git_remote_lookup(&remote, repo, git_buf_cstr(&remote_name))) < 0)
goto cleanup;
- refspec = git_remote__matching_refspec(remote, merge_name);
+ refspec = git_remote__matching_refspec(remote, git_buf_cstr(&merge_name));
if (!refspec) {
error = GIT_ENOTFOUND;
goto cleanup;
}
- if (git_refspec_transform(&buf, refspec, merge_name) < 0)
+ if (git_refspec_transform(&buf, refspec, git_buf_cstr(&merge_name)) < 0)
goto cleanup;
} else
- if (git_buf_sets(&buf, merge_name) < 0)
+ if (git_buf_set(&buf, git_buf_cstr(&merge_name), git_buf_len(&merge_name)) < 0)
goto cleanup;
error = git_buf_set(out, git_buf_cstr(&buf), git_buf_len(&buf));
@@ -380,6 +377,8 @@ int git_branch_upstream_name(
cleanup:
git_config_free(config);
git_remote_free(remote);
+ git_buf_free(&remote_name);
+ git_buf_free(&merge_name);
git_buf_free(&buf);
return error;
}
@@ -387,29 +386,25 @@ cleanup:
int git_branch_upstream_remote(git_buf *buf, git_repository *repo, const char *refname)
{
int error;
- const char *str;
git_config *cfg;
if (!git_reference__is_branch(refname))
return not_a_local_branch(refname);
- git_buf_sanitize(buf);
- if ((error = git_repository_config_snapshot(&cfg, repo)) < 0)
+ if ((error = git_repository_config__weakptr(&cfg, repo)) < 0)
return error;
- if ((error = retrieve_upstream_configuration(&str, cfg, refname, "branch.%s.remote")) < 0)
- goto cleanup;
+ git_buf_sanitize(buf);
+
+ if ((error = retrieve_upstream_configuration(buf, cfg, refname, "branch.%s.remote")) < 0)
+ return error;
- if (!*str) {
+ if (git_buf_len(buf) == 0) {
giterr_set(GITERR_REFERENCE, "branch '%s' does not have an upstream remote", refname);
error = GIT_ENOTFOUND;
- goto cleanup;
+ git_buf_clear(buf);
}
- error = git_buf_puts(buf, str);
-
-cleanup:
- git_config_free(cfg);
return error;
}
diff --git a/src/checkout.c b/src/checkout.c
index f71be26f9..b106c110c 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -255,13 +255,13 @@ static int checkout_action_no_wd(
error = checkout_notify(data, GIT_CHECKOUT_NOTIFY_DIRTY, delta, NULL);
if (error)
return error;
- *action = CHECKOUT_ACTION_IF(SAFE_CREATE, UPDATE_BLOB, NONE);
+ *action = CHECKOUT_ACTION_IF(RECREATE_MISSING, UPDATE_BLOB, NONE);
break;
case GIT_DELTA_ADDED: /* case 2 or 28 (and 5 but not really) */
*action = CHECKOUT_ACTION_IF(SAFE, UPDATE_BLOB, NONE);
break;
case GIT_DELTA_MODIFIED: /* case 13 (and 35 but not really) */
- *action = CHECKOUT_ACTION_IF(SAFE_CREATE, UPDATE_BLOB, CONFLICT);
+ *action = CHECKOUT_ACTION_IF(RECREATE_MISSING, UPDATE_BLOB, CONFLICT);
break;
case GIT_DELTA_TYPECHANGE: /* case 21 (B->T) and 28 (T->B)*/
if (delta->new_file.mode == GIT_FILEMODE_TREE)
@@ -2346,11 +2346,17 @@ static int checkout_data_init(
}
}
- /* if you are forcing, definitely allow safe updates */
+ /* if you are forcing, allow all safe updates, plus recreate missing */
if ((data->opts.checkout_strategy & GIT_CHECKOUT_FORCE) != 0)
- data->opts.checkout_strategy |= GIT_CHECKOUT_SAFE_CREATE;
- if ((data->opts.checkout_strategy & GIT_CHECKOUT_SAFE_CREATE) != 0)
- data->opts.checkout_strategy |= GIT_CHECKOUT_SAFE;
+ data->opts.checkout_strategy |= GIT_CHECKOUT_SAFE |
+ GIT_CHECKOUT_RECREATE_MISSING;
+
+ /* if the repository does not actually have an index file, then this
+ * is an initial checkout (perhaps from clone), so we allow safe updates
+ */
+ if (!data->index->on_disk &&
+ (data->opts.checkout_strategy & GIT_CHECKOUT_SAFE) != 0)
+ data->opts.checkout_strategy |= GIT_CHECKOUT_RECREATE_MISSING;
data->strategy = data->opts.checkout_strategy;
@@ -2384,25 +2390,27 @@ static int checkout_data_init(
if ((data->opts.checkout_strategy &
(GIT_CHECKOUT_CONFLICT_STYLE_MERGE | GIT_CHECKOUT_CONFLICT_STYLE_DIFF3)) == 0) {
- const char *conflict_style;
+ git_config_entry *conflict_style = NULL;
git_config *cfg = NULL;
if ((error = git_repository_config__weakptr(&cfg, repo)) < 0 ||
- (error = git_config_get_string(&conflict_style, cfg, "merge.conflictstyle")) < 0 ||
+ (error = git_config_get_entry(&conflict_style, cfg, "merge.conflictstyle")) < 0 ||
error == GIT_ENOTFOUND)
;
else if (error)
goto cleanup;
- else if (strcmp(conflict_style, "merge") == 0)
+ else if (strcmp(conflict_style->value, "merge") == 0)
data->opts.checkout_strategy |= GIT_CHECKOUT_CONFLICT_STYLE_MERGE;
- else if (strcmp(conflict_style, "diff3") == 0)
+ else if (strcmp(conflict_style->value, "diff3") == 0)
data->opts.checkout_strategy |= GIT_CHECKOUT_CONFLICT_STYLE_DIFF3;
else {
giterr_set(GITERR_CHECKOUT, "unknown style '%s' given for 'merge.conflictstyle'",
conflict_style);
error = -1;
+ git_config_entry_free(conflict_style);
goto cleanup;
}
+ git_config_entry_free(conflict_style);
}
if ((error = git_vector_init(&data->removes, 0, git__strcmp_cb)) < 0 ||
diff --git a/src/cherrypick.c b/src/cherrypick.c
index ebc9fcdd8..c92975194 100644
--- a/src/cherrypick.c
+++ b/src/cherrypick.c
@@ -72,7 +72,7 @@ static int cherrypick_normalize_opts(
const char *their_label)
{
int error = 0;
- unsigned int default_checkout_strategy = GIT_CHECKOUT_SAFE_CREATE |
+ unsigned int default_checkout_strategy = GIT_CHECKOUT_SAFE |
GIT_CHECKOUT_ALLOW_CONFLICTS;
GIT_UNUSED(repo);
diff --git a/src/clone.c b/src/clone.c
index f18f07611..7e5d3302e 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -24,18 +24,18 @@
#include "repository.h"
#include "odb.h"
-static int clone_local_into(git_repository *repo, git_remote *remote, const git_checkout_options *co_opts, const char *branch, int link, const git_signature *signature);
+static int clone_local_into(git_repository *repo, git_remote *remote, const git_checkout_options *co_opts, const char *branch, int link);
static int create_branch(
git_reference **branch,
git_repository *repo,
const git_oid *target,
const char *name,
- const git_signature *signature,
const char *log_message)
{
git_commit *head_obj = NULL;
git_reference *branch_ref = NULL;
+ git_buf refname = GIT_BUF_INIT;
int error;
/* Find the target commit */
@@ -43,8 +43,11 @@ static int create_branch(
return error;
/* Create the new branch */
- error = git_branch_create(&branch_ref, repo, name, head_obj, 0, signature, log_message);
+ if ((error = git_buf_printf(&refname, GIT_REFS_HEADS_DIR "%s", name)) < 0)
+ return error;
+ error = git_reference_create(&branch_ref, repo, git_buf_cstr(&refname), target, 0, log_message);
+ git_buf_free(&refname);
git_commit_free(head_obj);
if (!error)
@@ -93,12 +96,11 @@ static int create_tracking_branch(
git_repository *repo,
const git_oid *target,
const char *branch_name,
- const git_signature *signature,
const char *log_message)
{
int error;
- if ((error = create_branch(branch, repo, target, branch_name, signature, log_message)) < 0)
+ if ((error = create_branch(branch, repo, target, branch_name, log_message)) < 0)
return error;
return setup_tracking_config(
@@ -112,7 +114,6 @@ static int update_head_to_new_branch(
git_repository *repo,
const git_oid *target,
const char *name,
- const git_signature *signature,
const char *reflog_message)
{
git_reference *tracking_branch = NULL;
@@ -122,12 +123,11 @@ static int update_head_to_new_branch(
name += strlen(GIT_REFS_HEADS_DIR);
error = create_tracking_branch(&tracking_branch, repo, target, name,
- signature, reflog_message);
+ reflog_message);
if (!error)
error = git_repository_set_head(
- repo, git_reference_name(tracking_branch),
- signature, reflog_message);
+ repo, git_reference_name(tracking_branch));
git_reference_free(tracking_branch);
@@ -141,7 +141,6 @@ static int update_head_to_new_branch(
static int update_head_to_remote(
git_repository *repo,
git_remote *remote,
- const git_signature *signature,
const char *reflog_message)
{
int error = 0;
@@ -169,7 +168,7 @@ static int update_head_to_remote(
error = git_remote_default_branch(&branch, remote);
if (error == GIT_ENOTFOUND) {
error = git_repository_set_head_detached(
- repo, remote_head_id, signature, reflog_message);
+ repo, remote_head_id);
goto cleanup;
}
@@ -192,7 +191,7 @@ static int update_head_to_remote(
repo,
remote_head_id,
git_buf_cstr(&branch),
- signature, reflog_message);
+ reflog_message);
cleanup:
git_buf_free(&remote_master_name);
@@ -205,7 +204,6 @@ static int update_head_to_branch(
git_repository *repo,
const char *remote_name,
const char *branch,
- const git_signature *signature,
const char *reflog_message)
{
int retcode;
@@ -222,7 +220,7 @@ static int update_head_to_branch(
goto cleanup;
retcode = update_head_to_new_branch(repo, git_reference_target(remote_ref), branch,
- signature, reflog_message);
+ reflog_message);
cleanup:
git_reference_free(remote_ref);
@@ -313,16 +311,16 @@ static bool should_checkout(
return !git_repository_head_unborn(repo);
}
-static int checkout_branch(git_repository *repo, git_remote *remote, const git_checkout_options *co_opts, const char *branch, const git_signature *signature, const char *reflog_message)
+static int checkout_branch(git_repository *repo, git_remote *remote, const git_checkout_options *co_opts, const char *branch, const char *reflog_message)
{
int error;
if (branch)
error = update_head_to_branch(repo, git_remote_name(remote), branch,
- signature, reflog_message);
+ reflog_message);
/* Point HEAD to the same ref as the remote's head */
else
- error = update_head_to_remote(repo, remote, signature, reflog_message);
+ error = update_head_to_remote(repo, remote, reflog_message);
if (!error && should_checkout(repo, git_repository_is_bare(repo), co_opts))
error = git_checkout_head(repo, co_opts);
@@ -330,7 +328,7 @@ static int checkout_branch(git_repository *repo, git_remote *remote, const git_c
return error;
}
-static int clone_into(git_repository *repo, git_remote *_remote, const git_checkout_options *co_opts, const char *branch, const git_signature *signature)
+static int clone_into(git_repository *repo, git_remote *_remote, const git_checkout_options *co_opts, const char *branch)
{
int error;
git_buf reflog_message = GIT_BUF_INIT;
@@ -358,10 +356,10 @@ static int clone_into(git_repository *repo, git_remote *_remote, const git_check
git_remote_set_update_fetchhead(remote, 0);
git_buf_printf(&reflog_message, "clone: from %s", git_remote_url(remote));
- if ((error = git_remote_fetch(remote, NULL, signature, git_buf_cstr(&reflog_message))) != 0)
+ if ((error = git_remote_fetch(remote, NULL, git_buf_cstr(&reflog_message))) != 0)
goto cleanup;
- error = checkout_branch(repo, remote, co_opts, branch, signature, git_buf_cstr(&reflog_message));
+ error = checkout_branch(repo, remote, co_opts, branch, git_buf_cstr(&reflog_message));
cleanup:
git_remote_free(remote);
@@ -442,11 +440,11 @@ int git_clone(
if (clone_local == 1)
error = clone_local_into(
repo, origin, &options.checkout_opts,
- options.checkout_branch, link, options.signature);
+ options.checkout_branch, link);
else if (clone_local == 0)
error = clone_into(
repo, origin, &options.checkout_opts,
- options.checkout_branch, options.signature);
+ options.checkout_branch);
else
error = -1;
@@ -508,7 +506,7 @@ static bool can_link(const char *src, const char *dst, int link)
#endif
}
-static int clone_local_into(git_repository *repo, git_remote *remote, const git_checkout_options *co_opts, const char *branch, int link, const git_signature *signature)
+static int clone_local_into(git_repository *repo, git_remote *remote, const git_checkout_options *co_opts, const char *branch, int link)
{
int error, flags;
git_repository *src;
@@ -553,10 +551,10 @@ static int clone_local_into(git_repository *repo, git_remote *remote, const git_
git_buf_printf(&reflog_message, "clone: from %s", git_remote_url(remote));
- if ((error = git_remote_fetch(remote, NULL, signature, git_buf_cstr(&reflog_message))) != 0)
+ if ((error = git_remote_fetch(remote, NULL, git_buf_cstr(&reflog_message))) != 0)
goto cleanup;
- error = checkout_branch(repo, remote, co_opts, branch, signature, git_buf_cstr(&reflog_message));
+ error = checkout_branch(repo, remote, co_opts, branch, git_buf_cstr(&reflog_message));
cleanup:
git_buf_free(&reflog_message);
diff --git a/src/commit.c b/src/commit.c
index beb2c64c3..84f24c6cf 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -104,7 +104,7 @@ int git_commit_create_from_callback(
if (update_ref != NULL) {
error = git_reference__update_for_commit(
- repo, ref, update_ref, id, committer, "commit");
+ repo, ref, update_ref, id, "commit");
git_reference_free(ref);
return error;
}
@@ -295,7 +295,7 @@ int git_commit_amend(
if (!error && update_ref) {
error = git_reference__update_for_commit(
- repo, ref, NULL, id, committer, "commit");
+ repo, ref, NULL, id, "commit");
git_reference_free(ref);
}
diff --git a/src/common.h b/src/common.h
index 98109ae3a..cdfc13657 100644
--- a/src/common.h
+++ b/src/common.h
@@ -38,6 +38,7 @@
# include <direct.h>
# include <winsock2.h>
# include <windows.h>
+# include <ws2tcpip.h>
# include "win32/msvc-compat.h"
# include "win32/mingw-compat.h"
# include "win32/error.h"
diff --git a/src/config.c b/src/config.c
index f80770138..d116a9d80 100644
--- a/src/config.c
+++ b/src/config.c
@@ -19,6 +19,14 @@
#include <ctype.h>
+void git_config_entry_free(git_config_entry *entry)
+{
+ if (!entry)
+ return;
+
+ entry->free(entry);
+}
+
typedef struct {
git_refcount rc;
@@ -638,7 +646,7 @@ int git_config__update_entry(
bool only_if_existing)
{
int error = 0;
- const git_config_entry *ce = NULL;
+ git_config_entry *ce = NULL;
if ((error = git_config__lookup_entry(&ce, config, key, false)) < 0)
return error;
@@ -657,6 +665,7 @@ int git_config__update_entry(
else
error = git_config_set_string(config, key, value);
+ git_config_entry_free(ce);
return error;
}
@@ -677,7 +686,7 @@ enum {
};
static int get_entry(
- const git_config_entry **out,
+ git_config_entry **out,
const git_config *cfg,
const char *name,
bool normalize_name,
@@ -721,13 +730,13 @@ cleanup:
}
int git_config_get_entry(
- const git_config_entry **out, const git_config *cfg, const char *name)
+ git_config_entry **out, const git_config *cfg, const char *name)
{
return get_entry(out, cfg, name, true, GET_ALL_ERRORS);
}
int git_config__lookup_entry(
- const git_config_entry **out,
+ git_config_entry **out,
const git_config *cfg,
const char *key,
bool no_errors)
@@ -743,87 +752,154 @@ int git_config_get_mapped(
const git_cvar_map *maps,
size_t map_n)
{
- const git_config_entry *entry;
+ git_config_entry *entry;
int ret;
if ((ret = get_entry(&entry, cfg, name, true, GET_ALL_ERRORS)) < 0)
return ret;
- return git_config_lookup_map_value(out, maps, map_n, entry->value);
+ ret = git_config_lookup_map_value(out, maps, map_n, entry->value);
+ git_config_entry_free(entry);
+
+ return ret;
}
int git_config_get_int64(int64_t *out, const git_config *cfg, const char *name)
{
- const git_config_entry *entry;
+ git_config_entry *entry;
int ret;
if ((ret = get_entry(&entry, cfg, name, true, GET_ALL_ERRORS)) < 0)
return ret;
- return git_config_parse_int64(out, entry->value);
+ ret = git_config_parse_int64(out, entry->value);
+ git_config_entry_free(entry);
+
+ return ret;
}
int git_config_get_int32(int32_t *out, const git_config *cfg, const char *name)
{
- const git_config_entry *entry;
+ git_config_entry *entry;
int ret;
if ((ret = get_entry(&entry, cfg, name, true, GET_ALL_ERRORS)) < 0)
return ret;
- return git_config_parse_int32(out, entry->value);
+ ret = git_config_parse_int32(out, entry->value);
+ git_config_entry_free(entry);
+
+ return ret;
}
int git_config_get_bool(int *out, const git_config *cfg, const char *name)
{
- const git_config_entry *entry;
+ git_config_entry *entry;
int ret;
if ((ret = get_entry(&entry, cfg, name, true, GET_ALL_ERRORS)) < 0)
return ret;
- return git_config_parse_bool(out, entry->value);
+ ret = git_config_parse_bool(out, entry->value);
+ git_config_entry_free(entry);
+
+ return ret;
+}
+
+static int is_readonly(const git_config *cfg)
+{
+ size_t i;
+ file_internal *internal;
+
+ git_vector_foreach(&cfg->files, i, internal) {
+ if (!internal || !internal->file)
+ continue;
+
+ if (!internal->file->readonly)
+ return 0;
+ }
+
+ return 1;
}
int git_config_get_path(git_buf *out, const git_config *cfg, const char *name)
{
- const git_config_entry *entry;
+ git_config_entry *entry;
int error;
if ((error = get_entry(&entry, cfg, name, true, GET_ALL_ERRORS)) < 0)
return error;
- return git_config_parse_path(out, entry->value);
+ error = git_config_parse_path(out, entry->value);
+ git_config_entry_free(entry);
+
+ return error;
}
int git_config_get_string(
const char **out, const git_config *cfg, const char *name)
{
- const git_config_entry *entry;
- int ret = get_entry(&entry, cfg, name, true, GET_ALL_ERRORS);
+ git_config_entry *entry;
+ int ret;
+
+ if (!is_readonly(cfg)) {
+ giterr_set(GITERR_CONFIG, "get_string called on a live config object");
+ return -1;
+ }
+
+ ret = get_entry(&entry, cfg, name, true, GET_ALL_ERRORS);
*out = !ret ? (entry->value ? entry->value : "") : NULL;
+
+ git_config_entry_free(entry);
+
return ret;
}
-const char *git_config__get_string_force(
+int git_config_get_string_buf(
+ git_buf *out, const git_config *cfg, const char *name)
+{
+ git_config_entry *entry;
+ int ret;
+ const char *str;
+
+ git_buf_sanitize(out);
+
+ ret = get_entry(&entry, cfg, name, true, GET_ALL_ERRORS);
+ str = !ret ? (entry->value ? entry->value : "") : NULL;
+
+ if (str)
+ ret = git_buf_puts(out, str);
+
+ git_config_entry_free(entry);
+
+ return ret;
+}
+
+char *git_config__get_string_force(
const git_config *cfg, const char *key, const char *fallback_value)
{
- const git_config_entry *entry;
+ git_config_entry *entry;
+ char *ret;
+
get_entry(&entry, cfg, key, false, GET_NO_ERRORS);
- return (entry && entry->value) ? entry->value : fallback_value;
+ ret = (entry && entry->value) ? git__strdup(entry->value) : fallback_value ? git__strdup(fallback_value) : NULL;
+ git_config_entry_free(entry);
+
+ return ret;
}
int git_config__get_bool_force(
const git_config *cfg, const char *key, int fallback_value)
{
int val = fallback_value;
- const git_config_entry *entry;
+ git_config_entry *entry;
get_entry(&entry, cfg, key, false, GET_NO_ERRORS);
if (entry && git_config_parse_bool(&val, entry->value) < 0)
giterr_clear();
+ git_config_entry_free(entry);
return val;
}
@@ -831,13 +907,14 @@ int git_config__get_int_force(
const git_config *cfg, const char *key, int fallback_value)
{
int32_t val = (int32_t)fallback_value;
- const git_config_entry *entry;
+ git_config_entry *entry;
get_entry(&entry, cfg, key, false, GET_NO_ERRORS);
if (entry && git_config_parse_int32(&val, entry->value) < 0)
giterr_clear();
+ git_config_entry_free(entry);
return (int)val;
}
diff --git a/src/config.h b/src/config.h
index b0dcb49ac..691868b1d 100644
--- a/src/config.h
+++ b/src/config.h
@@ -48,7 +48,7 @@ extern int git_config__normalize_name(const char *in, char **out);
/* internal only: does not normalize key and sets out to NULL if not found */
extern int git_config__lookup_entry(
- const git_config_entry **out,
+ git_config_entry **out,
const git_config *cfg,
const char *key,
bool no_errors);
@@ -67,7 +67,7 @@ extern int git_config__update_entry(
* failures occur while trying to access the value.
*/
-extern const char *git_config__get_string_force(
+extern char *git_config__get_string_force(
const git_config *cfg, const char *key, const char *fallback_value);
extern int git_config__get_bool_force(
diff --git a/src/config_cache.c b/src/config_cache.c
index d397a4bab..c859ec148 100644
--- a/src/config_cache.c
+++ b/src/config_cache.c
@@ -84,7 +84,7 @@ int git_config__cvar(int *out, git_config *config, git_cvar_cached cvar)
{
int error = 0;
struct map_data *data = &_cvar_maps[(int)cvar];
- const git_config_entry *entry;
+ git_config_entry *entry;
git_config__lookup_entry(&entry, config, data->cvar_name, false);
@@ -96,6 +96,7 @@ int git_config__cvar(int *out, git_config *config, git_cvar_cached cvar)
else
error = git_config_parse_bool(out, entry->value);
+ git_config_entry_free(entry);
return error;
}
diff --git a/src/config_file.c b/src/config_file.c
index 168dd5483..732705687 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -96,7 +96,6 @@ typedef struct {
/* mutex to coordinate accessing the values */
git_mutex values_mutex;
refcounted_strmap *values;
- int readonly;
} diskfile_header;
typedef struct {
@@ -504,19 +503,26 @@ out:
return ret;
}
+/* release the map containing the entry as an equivalent to freeing it */
+static void release_map(git_config_entry *entry)
+{
+ refcounted_strmap *map = (refcounted_strmap *) entry->payload;
+ refcounted_strmap_free(map);
+}
+
/*
* Internal function that actually gets the value in string form
*/
-static int config_get(git_config_backend *cfg, const char *key, const git_config_entry **out)
+static int config_get(git_config_backend *cfg, const char *key, git_config_entry **out)
{
diskfile_header *h = (diskfile_header *)cfg;
refcounted_strmap *map;
git_strmap *values;
khiter_t pos;
cvar_t *var;
- int error;
+ int error = 0;
- if (!h->readonly && ((error = config_refresh(cfg)) < 0))
+ if (!h->parent.readonly && ((error = config_refresh(cfg)) < 0))
return error;
map = refcounted_strmap_take(h);
@@ -534,9 +540,11 @@ static int config_get(git_config_backend *cfg, const char *key, const git_config
while (var->next)
var = var->next;
- refcounted_strmap_free(map);
*out = var->entry;
- return 0;
+ (*out)->free = release_map;
+ (*out)->payload = map;
+
+ return error;
}
static int config_set_multivar(
@@ -763,7 +771,7 @@ static int config_readonly_open(git_config_backend *cfg, git_config_level_t leve
refcounted_strmap *src_map;
int error;
- if (!src_header->readonly && (error = config_refresh(&src_header->parent)) < 0)
+ if (!src_header->parent.readonly && (error = config_refresh(&src_header->parent)) < 0)
return error;
/* We're just copying data, don't care about the level */
@@ -787,7 +795,7 @@ int git_config_file__snapshot(git_config_backend **out, diskfile_backend *in)
backend->snapshot_from = in;
- backend->header.readonly = 1;
+ backend->header.parent.readonly = 1;
backend->header.parent.version = GIT_CONFIG_BACKEND_VERSION;
backend->header.parent.open = config_readonly_open;
backend->header.parent.get = config_get;
diff --git a/src/config_file.h b/src/config_file.h
index fcccbd5cc..0d8bf740f 100644
--- a/src/config_file.h
+++ b/src/config_file.h
@@ -21,7 +21,7 @@ GIT_INLINE(void) git_config_file_free(git_config_backend *cfg)
}
GIT_INLINE(int) git_config_file_get_string(
- const git_config_entry **out, git_config_backend *cfg, const char *name)
+ git_config_entry **out, git_config_backend *cfg, const char *name)
{
return cfg->get(cfg, name, out);
}
diff --git a/src/diff.c b/src/diff.c
index 815351b21..9432b0467 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -461,12 +461,13 @@ static int diff_list_apply_options(
/* if ignore_submodules not explicitly set, check diff config */
if (diff->opts.ignore_submodules <= 0) {
- const git_config_entry *entry;
+ git_config_entry *entry;
git_config__lookup_entry(&entry, cfg, "diff.ignoresubmodules", true);
if (entry && git_submodule_parse_ignore(
&diff->opts.ignore_submodules, entry->value) < 0)
giterr_clear();
+ git_config_entry_free(entry);
}
/* if either prefix is not set, figure out appropriate value */
diff --git a/src/diff_driver.c b/src/diff_driver.c
index 049e6ef2a..69eef0f7a 100644
--- a/src/diff_driver.c
+++ b/src/diff_driver.c
@@ -242,7 +242,7 @@ static int git_diff_driver_load(
khiter_t pos;
git_config *cfg = NULL;
git_buf name = GIT_BUF_INIT;
- const git_config_entry *ce;
+ git_config_entry *ce = NULL;
bool found_driver = false;
if ((reg = git_repository_driver_registry(repo)) == NULL)
@@ -341,6 +341,7 @@ static int git_diff_driver_load(
*out = drv;
done:
+ git_config_entry_free(ce);
git_buf_free(&name);
git_config_free(cfg);
diff --git a/src/diff_tform.c b/src/diff_tform.c
index 8ee568cf4..06c12308b 100644
--- a/src/diff_tform.c
+++ b/src/diff_tform.c
@@ -277,7 +277,7 @@ static int normalize_find_opts(
if (!given ||
(given->flags & GIT_DIFF_FIND_ALL) == GIT_DIFF_FIND_BY_CONFIG)
{
- const char *rule =
+ char *rule =
git_config__get_string_force(cfg, "diff.renames", "true");
int boolval;
@@ -287,6 +287,8 @@ static int normalize_find_opts(
opts->flags |= GIT_DIFF_FIND_RENAMES | GIT_DIFF_FIND_COPIES;
else
opts->flags |= GIT_DIFF_FIND_RENAMES;
+
+ git__free(rule);
}
/* some flags imply others */
diff --git a/src/filter.c b/src/filter.c
index 4fbf84f6a..6d0d48015 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -874,7 +874,6 @@ void stream_list_free(git_vector *streams)
#define STREAM_BUFSIZE 10240
-/* TODO: maybe not use filter_stream as a target but create one */
int git_filter_list_stream_file(
git_filter_list *filters,
git_repository *repo,
@@ -894,7 +893,7 @@ int git_filter_list_stream_file(
(error = git_path_join_unrooted(&abspath, path, base, NULL)) < 0)
goto done;
- if ((fd = git_futils_open_ro(path)) < 0) {
+ if ((fd = git_futils_open_ro(abspath.ptr)) < 0) {
error = fd;
goto done;
}
diff --git a/src/global.c b/src/global.c
index fcbcbb176..1f3432d09 100644
--- a/src/global.c
+++ b/src/global.c
@@ -36,16 +36,25 @@ void git__on_shutdown(git_global_shutdown_fn callback)
git__shutdown_callbacks[count - 1] = callback;
}
+static void git__global_state_cleanup(git_global_st *st)
+{
+ if (!st)
+ return;
+
+ git__free(st->error_t.message);
+ st->error_t.message = NULL;
+}
+
static void git__shutdown(void)
{
int pos;
+ /* Shutdown subsystems that have registered */
for (pos = git_atomic_get(&git__n_shutdown_callbacks); pos > 0; pos = git_atomic_dec(&git__n_shutdown_callbacks)) {
git_global_shutdown_fn cb = git__swap(git__shutdown_callbacks[pos - 1], NULL);
if (cb != NULL)
cb();
}
-
}
#if defined(GIT_THREADS) && defined(GIT_SSL)
@@ -214,8 +223,14 @@ int git_libgit2_init(void)
static void synchronized_threads_shutdown(void)
{
+ void *ptr;
+
/* Shut down any subsystems that have global state */
git__shutdown();
+
+ ptr = TlsGetValue(_tls_index);
+ git__global_state_cleanup(ptr);
+
TlsFree(_tls_index);
git_mutex_free(&git__mwindow_mutex);
}
@@ -255,6 +270,17 @@ git_global_st *git__global_state(void)
return ptr;
}
+BOOL WINAPI DllMain(HINSTANCE dll, DWORD reason, LPVOID reserved)
+{
+ if (reason == DLL_THREAD_DETACH) {
+ void *ptr = TlsGetValue(_tls_index);
+ git__global_state_cleanup(ptr);
+ git__free(ptr);
+ }
+
+ return TRUE;
+}
+
#elif defined(GIT_THREADS) && defined(_POSIX_THREADS)
static pthread_key_t _tls_key;
@@ -263,9 +289,7 @@ int init_error = 0;
static void cb__free_status(void *st)
{
- git_global_st *state = (git_global_st *) st;
- git__free(state->error_t.message);
-
+ git__global_state_cleanup(st);
git__free(st);
}
@@ -302,7 +326,7 @@ int git_libgit2_shutdown(void)
pthread_once_t new_once = PTHREAD_ONCE_INIT;
int ret;
- if ((ret = git_atomic_dec(&git__n_inits)) > 0)
+ if ((ret = git_atomic_dec(&git__n_inits)) != 0)
return ret;
/* Shut down any subsystems that have global state */
@@ -310,13 +334,15 @@ int git_libgit2_shutdown(void)
ptr = pthread_getspecific(_tls_key);
pthread_setspecific(_tls_key, NULL);
+
+ git__global_state_cleanup(ptr);
git__free(ptr);
pthread_key_delete(_tls_key);
git_mutex_free(&git__mwindow_mutex);
_once_init = new_once;
- return ret;
+ return 0;
}
git_global_st *git__global_state(void)
@@ -358,10 +384,13 @@ int git_libgit2_shutdown(void)
int ret;
/* Shut down any subsystems that have global state */
- if (ret = git_atomic_dec(&git__n_inits))
- git__shutdown();
+ if ((ret = git_atomic_dec(&git__n_inits)) != 0)
+ return ret;
- return ret;
+ git__shutdown();
+ git__global_state_cleanup(&__state);
+
+ return 0;
}
git_global_st *git__global_state(void)
diff --git a/src/hashsig.c b/src/hashsig.c
index 0ddfed902..e99637d8b 100644
--- a/src/hashsig.c
+++ b/src/hashsig.c
@@ -34,6 +34,7 @@ typedef struct {
struct git_hashsig {
hashsig_heap mins;
hashsig_heap maxs;
+ size_t lines;
git_hashsig_option_t opt;
};
@@ -185,8 +186,10 @@ static int hashsig_add_hashes(
++scan;
/* check run terminator */
- if (ch == '\n' || ch == '\0')
+ if (ch == '\n' || ch == '\0') {
+ sig->lines++;
break;
+ }
++len;
HASHSIG_HASH_MIX(state, ch);
@@ -333,6 +336,18 @@ static int hashsig_heap_compare(const hashsig_heap *a, const hashsig_heap *b)
int git_hashsig_compare(const git_hashsig *a, const git_hashsig *b)
{
+ /* if we have no elements in either file then each file is either
+ * empty or blank. if we're ignoring whitespace then the files are
+ * similar, otherwise they're dissimilar.
+ */
+ if (a->mins.size == 0 && b->mins.size == 0) {
+ if ((!a->lines && !b->lines) ||
+ (a->opt & GIT_HASHSIG_IGNORE_WHITESPACE))
+ return HASHSIG_SCALE;
+ else
+ return 0;
+ }
+
/* if we have fewer than the maximum number of elements, then just use
* one array since the two arrays will be the same
*/
diff --git a/src/openssl_stream.c b/src/openssl_stream.c
index 2a17a3abf..9ddf6e4be 100644
--- a/src/openssl_stream.c
+++ b/src/openssl_stream.c
@@ -7,14 +7,7 @@
#ifdef GIT_SSL
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-#include <openssl/x509v3.h>
-
#include <ctype.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
#include "global.h"
#include "posix.h"
@@ -23,6 +16,16 @@
#include "netops.h"
#include "git2/transport.h"
+#ifndef GIT_WIN32
+# include <sys/types.h>
+# include <sys/socket.h>
+# include <netinet/in.h>
+#endif
+
+#include <openssl/ssl.h>
+#include <openssl/err.h>
+#include <openssl/x509v3.h>
+
static int ssl_set_error(SSL *ssl, int error)
{
int err;
diff --git a/src/push.c b/src/push.c
index fb51383cb..c6a93ba2f 100644
--- a/src/push.c
+++ b/src/push.c
@@ -167,10 +167,7 @@ int git_push_add_refspec(git_push *push, const char *refspec)
return 0;
}
-int git_push_update_tips(
- git_push *push,
- const git_signature *signature,
- const char *reflog_message)
+int git_push_update_tips(git_push *push)
{
git_buf remote_ref_name = GIT_BUF_INIT;
size_t i, j;
@@ -213,8 +210,8 @@ int git_push_update_tips(
}
} else {
error = git_reference_create(NULL, push->remote->repo,
- git_buf_cstr(&remote_ref_name), &push_spec->loid, 1, signature,
- reflog_message ? reflog_message : "update by push");
+ git_buf_cstr(&remote_ref_name), &push_spec->loid, 1,
+ "update by push");
}
}
diff --git a/src/push.h b/src/push.h
index 264ecad8c..b19d40e03 100644
--- a/src/push.h
+++ b/src/push.h
@@ -109,15 +109,10 @@ int git_push_add_refspec(git_push *push, const char *refspec);
*
* @param push The push object
* @param signature The identity to use when updating reflogs
- * @param reflog_message The message to insert into the reflogs. If NULL, the
- * default is "update by push".
*
* @return 0 or an error code
*/
-int git_push_update_tips(
- git_push *push,
- const git_signature *signature,
- const char *reflog_message);
+int git_push_update_tips(git_push *push);
/**
* Perform the push
diff --git a/src/rebase.c b/src/rebase.c
index 8078eedc3..eb25d4c3a 100644
--- a/src/rebase.c
+++ b/src/rebase.c
@@ -466,11 +466,11 @@ static int rebase_normalize_opts(
opts->rewrite_notes_ref = git__strdup(given_opts->rewrite_notes_ref);
GITERR_CHECK_ALLOC(opts->rewrite_notes_ref);
} else if (git_config__get_bool_force(config, "notes.rewrite.rebase", 1)) {
- const char *rewrite_ref = git_config__get_string_force(
+ char *rewrite_ref = git_config__get_string_force(
config, "notes.rewriteref", NOTES_DEFAULT_REF);
if (rewrite_ref) {
- opts->rewrite_notes_ref = git__strdup(rewrite_ref);
+ opts->rewrite_notes_ref = rewrite_ref;
GITERR_CHECK_ALLOC(opts->rewrite_notes_ref);
}
}
@@ -576,6 +576,7 @@ static int rebase_init_operations(
continue;
operation = rebase_operation_alloc(rebase, GIT_REBASE_OPERATION_PICK, &id, NULL);
+ GITERR_CHECK_ALLOC(operation);
}
error = 0;
@@ -654,7 +655,6 @@ int git_rebase_init(
const git_annotated_commit *branch,
const git_annotated_commit *upstream,
const git_annotated_commit *onto,
- const git_signature *signature,
const git_rebase_options *given_opts)
{
git_rebase *rebase = NULL;
@@ -662,6 +662,7 @@ int git_rebase_init(
git_buf reflog = GIT_BUF_INIT;
git_commit *onto_commit = NULL;
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
+ git_reference *head_ref = NULL;
int error;
assert(repo && (upstream || onto));
@@ -693,13 +694,14 @@ int git_rebase_init(
"rebase: checkout %s", rebase_onto_name(onto))) < 0 ||
(error = git_checkout_tree(
repo, (git_object *)onto_commit, &checkout_opts)) < 0 ||
- (error = git_repository_set_head_detached(
- repo, git_annotated_commit_id(onto), signature, reflog.ptr)) < 0)
+ (error = git_reference_create(&head_ref, repo, GIT_HEAD_FILE,
+ git_annotated_commit_id(onto), 1, reflog.ptr)) < 0)
goto done;
*out = rebase;
done:
+ git_reference_free(head_ref);
if (error < 0) {
rebase_cleanup(rebase);
git_rebase_free(rebase);
@@ -901,7 +903,7 @@ static int rebase_commit_merge(
(const git_commit **)&head_commit)) < 0 ||
(error = git_commit_lookup(&commit, rebase->repo, commit_id)) < 0 ||
(error = git_reference__update_for_commit(
- rebase->repo, NULL, "HEAD", commit_id, committer, "rebase")) < 0)
+ rebase->repo, NULL, "HEAD", commit_id, "rebase")) < 0)
goto done;
git_oid_fmt(old_idstr, git_commit_id(current_commit));
@@ -948,20 +950,20 @@ int git_rebase_commit(
return error;
}
-int git_rebase_abort(git_rebase *rebase, const git_signature *signature)
+int git_rebase_abort(git_rebase *rebase)
{
git_reference *orig_head_ref = NULL;
git_commit *orig_head_commit = NULL;
int error;
- assert(rebase && signature);
+ assert(rebase);
error = rebase->head_detached ?
git_reference_create(&orig_head_ref, rebase->repo, GIT_HEAD_FILE,
- &rebase->orig_head_id, 1, signature, "rebase: aborting") :
+ &rebase->orig_head_id, 1, "rebase: aborting") :
git_reference_symbolic_create(
&orig_head_ref, rebase->repo, GIT_HEAD_FILE, rebase->orig_head_name, 1,
- signature, "rebase: aborting");
+ "rebase: aborting");
if (error < 0)
goto done;
@@ -969,7 +971,7 @@ int git_rebase_abort(git_rebase *rebase, const git_signature *signature)
if ((error = git_commit_lookup(
&orig_head_commit, rebase->repo, &rebase->orig_head_id)) < 0 ||
(error = git_reset(rebase->repo, (git_object *)orig_head_commit,
- GIT_RESET_HARD, NULL, signature, NULL)) < 0)
+ GIT_RESET_HARD, NULL)) < 0)
goto done;
error = rebase_cleanup(rebase);
@@ -1114,10 +1116,10 @@ int git_rebase_finish(
terminal_ref, GIT_OBJ_COMMIT)) < 0 ||
(error = git_reference_create_matching(&branch_ref,
rebase->repo, rebase->orig_head_name, git_commit_id(terminal_commit), 1,
- &rebase->orig_head_id, signature, branch_msg.ptr)) < 0 ||
+ &rebase->orig_head_id, branch_msg.ptr)) < 0 ||
(error = git_reference_symbolic_create(&head_ref,
rebase->repo, GIT_HEAD_FILE, rebase->orig_head_name, 1,
- signature, head_msg.ptr)) < 0 ||
+ head_msg.ptr)) < 0 ||
(error = rebase_copy_notes(rebase, signature, &opts)) < 0)
goto done;
diff --git a/src/refdb_fs.c b/src/refdb_fs.c
index 77cb1a8ce..e1a77f3ff 100644
--- a/src/refdb_fs.c
+++ b/src/refdb_fs.c
@@ -1324,7 +1324,7 @@ static int refdb_fs_backend__rename(
/* Try to rename the refog; it's ok if the old doesn't exist */
error = refdb_reflog_fs__rename(_backend, old_name, new_name);
if (((error == 0) || (error == GIT_ENOTFOUND)) &&
- ((error = reflog_append(backend, new, NULL, NULL, who, message)) < 0)) {
+ ((error = reflog_append(backend, new, git_reference_target(new), NULL, who, message)) < 0)) {
git_reference_free(new);
git_filebuf_cleanup(&file);
return error;
diff --git a/src/refs.c b/src/refs.c
index e3157529b..360e65373 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -416,12 +416,22 @@ static int reference__create(
return 0;
}
+int configured_ident(git_signature **out, const git_repository *repo)
+{
+ if (repo->ident_name && repo->ident_email)
+ return git_signature_now(out, repo->ident_name, repo->ident_email);
+
+ /* if not configured let us fall-through to the next method */
+ return -1;
+}
+
int git_reference__log_signature(git_signature **out, git_repository *repo)
{
int error;
git_signature *who;
- if(((error = git_signature_default(&who, repo)) < 0) &&
+ if(((error = configured_ident(&who, repo)) < 0) &&
+ ((error = git_signature_default(&who, repo)) < 0) &&
((error = git_signature_now(&who, "unknown", "unknown")) < 0))
return error;
@@ -436,7 +446,6 @@ int git_reference_create_matching(
const git_oid *id,
int force,
const git_oid *old_id,
- const git_signature *signature,
const char *log_message)
{
@@ -445,15 +454,11 @@ int git_reference_create_matching(
assert(id);
- if (!signature) {
- if ((error = git_reference__log_signature(&who, repo)) < 0)
- return error;
- else
- signature = who;
- }
+ if ((error = git_reference__log_signature(&who, repo)) < 0)
+ return error;
error = reference__create(
- ref_out, repo, name, id, NULL, force, signature, log_message, old_id, NULL);
+ ref_out, repo, name, id, NULL, force, who, log_message, old_id, NULL);
git_signature_free(who);
return error;
@@ -465,10 +470,9 @@ int git_reference_create(
const char *name,
const git_oid *id,
int force,
- const git_signature *signature,
const char *log_message)
{
- return git_reference_create_matching(ref_out, repo, name, id, force, NULL, signature, log_message);
+ return git_reference_create_matching(ref_out, repo, name, id, force, NULL, log_message);
}
int git_reference_symbolic_create_matching(
@@ -478,7 +482,6 @@ int git_reference_symbolic_create_matching(
const char *target,
int force,
const char *old_target,
- const git_signature *signature,
const char *log_message)
{
int error;
@@ -486,15 +489,11 @@ int git_reference_symbolic_create_matching(
assert(target);
- if (!signature) {
- if ((error = git_reference__log_signature(&who, repo)) < 0)
- return error;
- else
- signature = who;
- }
+ if ((error = git_reference__log_signature(&who, repo)) < 0)
+ return error;
error = reference__create(
- ref_out, repo, name, NULL, target, force, signature, log_message, NULL, old_target);
+ ref_out, repo, name, NULL, target, force, who, log_message, NULL, old_target);
git_signature_free(who);
return error;
@@ -506,10 +505,9 @@ int git_reference_symbolic_create(
const char *name,
const char *target,
int force,
- const git_signature *signature,
const char *log_message)
{
- return git_reference_symbolic_create_matching(ref_out, repo, name, target, force, NULL, signature, log_message);
+ return git_reference_symbolic_create_matching(ref_out, repo, name, target, force, NULL, log_message);
}
static int ensure_is_an_updatable_direct_reference(git_reference *ref)
@@ -525,7 +523,6 @@ int git_reference_set_target(
git_reference **out,
git_reference *ref,
const git_oid *id,
- const git_signature *signature,
const char *log_message)
{
int error;
@@ -538,7 +535,7 @@ int git_reference_set_target(
if ((error = ensure_is_an_updatable_direct_reference(ref)) < 0)
return error;
- return git_reference_create_matching(out, repo, ref->name, id, 1, &ref->target.oid, signature, log_message);
+ return git_reference_create_matching(out, repo, ref->name, id, 1, &ref->target.oid, log_message);
}
static int ensure_is_an_updatable_symbolic_reference(git_reference *ref)
@@ -554,7 +551,6 @@ int git_reference_symbolic_set_target(
git_reference **out,
git_reference *ref,
const char *target,
- const git_signature *signature,
const char *log_message)
{
int error;
@@ -565,7 +561,7 @@ int git_reference_symbolic_set_target(
return error;
return git_reference_symbolic_create_matching(
- out, ref->db->repo, ref->name, target, 1, ref->target.symbolic, signature, log_message);
+ out, ref->db->repo, ref->name, target, 1, ref->target.symbolic, log_message);
}
static int reference__rename(git_reference **out, git_reference *ref, const char *new_name, int force,
@@ -593,7 +589,7 @@ static int reference__rename(git_reference **out, git_reference *ref, const char
/* Update HEAD it was pointing to the reference being renamed */
if (should_head_be_updated &&
- (error = git_repository_set_head(ref->db->repo, normalized, signature, message)) < 0) {
+ (error = git_repository_set_head(ref->db->repo, normalized)) < 0) {
giterr_set(GITERR_REFERENCE, "Failed to update HEAD after renaming reference");
return error;
}
@@ -607,23 +603,16 @@ int git_reference_rename(
git_reference *ref,
const char *new_name,
int force,
- const git_signature *signature,
const char *log_message)
{
- git_signature *who = (git_signature*)signature;
+ git_signature *who;
int error;
- /* Should we return an error if there is no default? */
- if (!who &&
- ((error = git_signature_default(&who, ref->db->repo)) < 0) &&
- ((error = git_signature_now(&who, "unknown", "unknown")) < 0)) {
+ if ((error = git_reference__log_signature(&who, ref->db->repo)) < 0)
return error;
- }
error = reference__rename(out, ref, new_name, force, who, log_message);
-
- if (!signature)
- git_signature_free(who);
+ git_signature_free(who);
return error;
}
@@ -1038,13 +1027,11 @@ int git_reference_cmp(
return git_oid__cmp(&ref1->target.oid, &ref2->target.oid);
}
-static int reference__update_terminal(
- git_repository *repo,
- const char *ref_name,
- const git_oid *oid,
- int nesting,
- const git_signature *signature,
- const char *log_message)
+/**
+ * Get the end of a chain of references. If the final one is not
+ * found, we return the reference just before that.
+ */
+static int get_terminal(git_reference **out, git_repository *repo, const char *ref_name, int nesting)
{
git_reference *ref;
int error = 0;
@@ -1054,27 +1041,23 @@ static int reference__update_terminal(
return GIT_ENOTFOUND;
}
- error = git_reference_lookup(&ref, repo, ref_name);
-
- /* If we haven't found the reference at all, create a new reference. */
- if (error == GIT_ENOTFOUND) {
- giterr_clear();
- return git_reference_create(NULL, repo, ref_name, oid, 0, signature, log_message);
- }
-
- if (error < 0)
+ /* set to NULL to let the caller know that they're at the end of the chain */
+ if ((error = git_reference_lookup(&ref, repo, ref_name)) < 0) {
+ *out = NULL;
return error;
+ }
- /* If the ref is a symbolic reference, follow its target. */
- if (git_reference_type(ref) == GIT_REF_SYMBOLIC) {
- error = reference__update_terminal(repo, git_reference_symbolic_target(ref), oid,
- nesting+1, signature, log_message);
- git_reference_free(ref);
+ if (git_reference_type(ref) == GIT_REF_OID) {
+ *out = ref;
+ error = 0;
} else {
- /* If we're not moving the target, don't recreate the ref */
- if (0 != git_oid_cmp(git_reference_target(ref), oid))
- error = git_reference_create(NULL, repo, ref_name, oid, 1, signature, log_message);
- git_reference_free(ref);
+ error = get_terminal(out, repo, git_reference_symbolic_target(ref), nesting + 1);
+ if (error == GIT_ENOTFOUND) {
+ if (!*out) /* set by the error case in lookup above */
+ *out = ref;
+ } else {
+ git_reference_free(ref);
+ }
}
return error;
@@ -1089,10 +1072,40 @@ int git_reference__update_terminal(
git_repository *repo,
const char *ref_name,
const git_oid *oid,
- const git_signature *signature,
+ const git_signature *sig,
const char *log_message)
{
- return reference__update_terminal(repo, ref_name, oid, 0, signature, log_message);
+ git_reference *ref = NULL, *ref2 = NULL;
+ git_signature *who = NULL;
+ const git_signature *to_use;
+ int error = 0;
+
+ if (!sig && (error = git_reference__log_signature(&who, repo)) < 0)
+ return error;
+
+ to_use = sig ? sig : who;
+ error = get_terminal(&ref, repo, ref_name, 0);
+
+ /* found a dangling symref */
+ if (error == GIT_ENOTFOUND && ref) {
+ assert(git_reference_type(ref) == GIT_REF_SYMBOLIC);
+ giterr_clear();
+ error = reference__create(&ref2, repo, ref->target.symbolic, oid, NULL, 0, to_use,
+ log_message, NULL, NULL);
+ } else if (error == GIT_ENOTFOUND) {
+ giterr_clear();
+ error = reference__create(&ref2, repo, ref_name, oid, NULL, 0, to_use,
+ log_message, NULL, NULL);
+ } else if (error == 0) {
+ assert(git_reference_type(ref) == GIT_REF_OID);
+ error = reference__create(&ref2, repo, ref->name, oid, NULL, 1, to_use,
+ log_message, &ref->target.oid, NULL);
+ }
+
+ git_reference_free(ref2);
+ git_reference_free(ref);
+ git_signature_free(who);
+ return error;
}
int git_reference__update_for_commit(
@@ -1100,12 +1113,12 @@ int git_reference__update_for_commit(
git_reference *ref,
const char *ref_name,
const git_oid *id,
- const git_signature *committer,
const char *operation)
{
git_reference *ref_new = NULL;
git_commit *commit = NULL;
git_buf reflog_msg = GIT_BUF_INIT;
+ const git_signature *who;
int error;
if ((error = git_commit_lookup(&commit, repo, id)) < 0 ||
@@ -1115,12 +1128,18 @@ int git_reference__update_for_commit(
git_commit_summary(commit))) < 0)
goto done;
- if (ref)
- error = git_reference_set_target(
- &ref_new, ref, id, committer, git_buf_cstr(&reflog_msg));
+ who = git_commit_committer(commit);
+
+ if (ref) {
+ if ((error = ensure_is_an_updatable_direct_reference(ref)) < 0)
+ return error;
+
+ error = reference__create(&ref_new, repo, ref->name, id, NULL, 1, who,
+ git_buf_cstr(&reflog_msg), &ref->target.oid, NULL);
+ }
else
error = git_reference__update_terminal(
- repo, ref_name, id, committer, git_buf_cstr(&reflog_msg));
+ repo, ref_name, id, who, git_buf_cstr(&reflog_msg));
done:
git_reference_free(ref_new);
@@ -1267,10 +1286,8 @@ int git_reference_is_valid_name(const char *refname)
return git_reference__is_valid_name(refname, GIT_REF_FORMAT_ALLOW_ONELEVEL);
}
-const char *git_reference_shorthand(const git_reference *ref)
+const char *git_reference__shorthand(const char *name)
{
- const char *name = ref->name;
-
if (!git__prefixcmp(name, GIT_REFS_HEADS_DIR))
return name + strlen(GIT_REFS_HEADS_DIR);
else if (!git__prefixcmp(name, GIT_REFS_TAGS_DIR))
@@ -1283,3 +1300,8 @@ const char *git_reference_shorthand(const git_reference *ref)
/* No shorthands are avaiable, so just return the name */
return name;
}
+
+const char *git_reference_shorthand(const git_reference *ref)
+{
+ return git_reference__shorthand(ref->name);
+}
diff --git a/src/refs.h b/src/refs.h
index 5f48efc41..f78ea06b0 100644
--- a/src/refs.h
+++ b/src/refs.h
@@ -69,11 +69,12 @@ struct git_reference {
git_reference *git_reference__set_name(git_reference *ref, const char *name);
int git_reference__normalize_name(git_buf *buf, const char *name, unsigned int flags);
-int git_reference__update_terminal(git_repository *repo, const char *ref_name, const git_oid *oid, const git_signature *signature, const char *log_message);
+int git_reference__update_terminal(git_repository *repo, const char *ref_name, const git_oid *oid, const git_signature *sig, const char *log_message);
int git_reference__is_valid_name(const char *refname, unsigned int flags);
int git_reference__is_branch(const char *ref_name);
int git_reference__is_remote(const char *ref_name);
int git_reference__is_tag(const char *ref_name);
+const char *git_reference__shorthand(const char *name);
/**
* Lookup a reference by name and try to resolve to an OID.
@@ -106,7 +107,6 @@ int git_reference__update_for_commit(
git_reference *ref,
const char *ref_name,
const git_oid *id,
- const git_signature *committer,
const char *operation);
#endif
diff --git a/src/refspec.c b/src/refspec.c
index a56c44cc0..ad8141248 100644
--- a/src/refspec.c
+++ b/src/refspec.c
@@ -133,6 +133,9 @@ int git_refspec__parse(git_refspec *refspec, const char *input, bool is_fetch)
return 0;
invalid:
+ giterr_set(
+ GITERR_INVALID,
+ "'%s' is not a valid refspec.", input);
return -1;
}
diff --git a/src/remote.c b/src/remote.c
index d96274f1d..4924bf83a 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -52,7 +52,7 @@ static int add_refspec(git_remote *remote, const char *string, bool is_fetch)
static int download_tags_value(git_remote *remote, git_config *cfg)
{
- const git_config_entry *ce;
+ git_config_entry *ce;
git_buf buf = GIT_BUF_INIT;
int error;
@@ -70,6 +70,7 @@ static int download_tags_value(git_remote *remote, git_config *cfg)
remote->download_tags = GIT_REMOTE_DOWNLOAD_TAGS_ALL;
}
+ git_config_entry_free(ce);
return error;
}
@@ -548,7 +549,7 @@ int git_remote_save(const git_remote *remote)
git_config *cfg;
const char *tagopt = NULL;
git_buf buf = GIT_BUF_INIT;
- const git_config_entry *existing;
+ git_config_entry *existing = NULL;
assert(remote);
@@ -618,6 +619,7 @@ int git_remote_save(const git_remote *remote)
cfg, git_buf_cstr(&buf), tagopt, true, false);
cleanup:
+ git_config_entry_free(existing);
git_buf_free(&buf);
return error;
}
@@ -753,7 +755,7 @@ int git_remote_ls(const git_remote_head ***out, size_t *size, git_remote *remote
int git_remote__get_http_proxy(git_remote *remote, bool use_ssl, char **proxy_url)
{
git_config *cfg;
- const git_config_entry *ce;
+ git_config_entry *ce = NULL;
const char *val = NULL;
int error;
@@ -805,6 +807,7 @@ found:
*proxy_url = git__strdup(val);
GITERR_CHECK_ALLOC(*proxy_url);
}
+ git_config_entry_free(ce);
return 0;
}
@@ -924,7 +927,6 @@ on_error:
int git_remote_fetch(
git_remote *remote,
const git_strarray *refspecs,
- const git_signature *signature,
const char *reflog_message)
{
int error;
@@ -952,7 +954,7 @@ int git_remote_fetch(
}
/* Create "remote/foo" branches for all remote branches */
- error = git_remote_update_tips(remote, signature, git_buf_cstr(&reflog_msg_buf));
+ error = git_remote_update_tips(remote, git_buf_cstr(&reflog_msg_buf));
git_buf_free(&reflog_msg_buf);
if (error < 0)
return error;
@@ -1257,7 +1259,6 @@ static int update_tips_for_spec(
git_remote *remote,
git_refspec *spec,
git_vector *refs,
- const git_signature *signature,
const char *log_message)
{
int error = 0, autotag;
@@ -1332,7 +1333,7 @@ static int update_tips_for_spec(
/* In autotag mode, don't overwrite any locally-existing tags */
error = git_reference_create(&ref, remote->repo, refname.ptr, &head->oid, !autotag,
- signature, log_message);
+ log_message);
if (error < 0 && error != GIT_EEXISTS)
goto on_error;
@@ -1418,7 +1419,7 @@ static int next_head(const git_remote *remote, git_vector *refs,
return GIT_ITEROVER;
}
-static int opportunistic_updates(const git_remote *remote, git_vector *refs, const git_signature *sig, const char *msg)
+static int opportunistic_updates(const git_remote *remote, git_vector *refs, const char *msg)
{
size_t i, j, k;
git_refspec *spec;
@@ -1441,7 +1442,7 @@ static int opportunistic_updates(const git_remote *remote, git_vector *refs, con
if ((error = git_refspec_transform(&refname, spec, head->name)) < 0)
return error;
- error = git_reference_create(&ref, remote->repo, refname.ptr, &head->oid, true, sig, msg);
+ error = git_reference_create(&ref, remote->repo, refname.ptr, &head->oid, true, msg);
git_buf_free(&refname);
git_reference_free(ref);
@@ -1454,7 +1455,6 @@ static int opportunistic_updates(const git_remote *remote, git_vector *refs, con
int git_remote_update_tips(
git_remote *remote,
- const git_signature *signature,
const char *reflog_message)
{
git_refspec *spec, tagspec;
@@ -1464,7 +1464,7 @@ int git_remote_update_tips(
/* push has its own logic hidden away in the push object */
if (remote->push) {
- return git_push_update_tips(remote->push, signature, reflog_message);
+ return git_push_update_tips(remote->push);
}
if (git_refspec__parse(&tagspec, GIT_REFSPEC_TAGS, true) < 0)
@@ -1475,7 +1475,7 @@ int git_remote_update_tips(
goto out;
if (remote->download_tags == GIT_REMOTE_DOWNLOAD_TAGS_ALL) {
- if ((error = update_tips_for_spec(remote, &tagspec, &refs, signature, reflog_message)) < 0)
+ if ((error = update_tips_for_spec(remote, &tagspec, &refs, reflog_message)) < 0)
goto out;
}
@@ -1483,13 +1483,13 @@ int git_remote_update_tips(
if (spec->push)
continue;
- if ((error = update_tips_for_spec(remote, spec, &refs, signature, reflog_message)) < 0)
+ if ((error = update_tips_for_spec(remote, spec, &refs, reflog_message)) < 0)
goto out;
}
/* only try to do opportunisitic updates if the refpec lists differ */
if (remote->passed_refspecs)
- error = opportunistic_updates(remote, &refs, signature, reflog_message);
+ error = opportunistic_updates(remote, &refs, reflog_message);
out:
git_vector_free(&refs);
@@ -1755,7 +1755,7 @@ static int rename_one_remote_reference(
goto cleanup;
if ((error = git_reference_rename(&ref, reference_in, git_buf_cstr(&new_name), 1,
- NULL, git_buf_cstr(&log_message))) < 0)
+ git_buf_cstr(&log_message))) < 0)
goto cleanup;
if (git_reference_type(ref) != GIT_REF_SYMBOLIC)
@@ -1775,7 +1775,7 @@ static int rename_one_remote_reference(
goto cleanup;
error = git_reference_symbolic_set_target(&dummy, ref, git_buf_cstr(&new_name),
- NULL, git_buf_cstr(&log_message));
+ git_buf_cstr(&log_message));
git_reference_free(dummy);
@@ -2373,8 +2373,7 @@ cleanup:
return error;
}
-int git_remote_push(git_remote *remote, const git_strarray *refspecs, const git_push_options *opts,
- const git_signature *signature, const char *reflog_message)
+int git_remote_push(git_remote *remote, const git_strarray *refspecs, const git_push_options *opts)
{
int error;
@@ -2386,7 +2385,7 @@ int git_remote_push(git_remote *remote, const git_strarray *refspecs, const git_
if ((error = git_remote_upload(remote, refspecs, opts)) < 0)
return error;
- error = git_remote_update_tips(remote, signature, reflog_message);
+ error = git_remote_update_tips(remote, NULL);
git_remote_disconnect(remote);
return error;
diff --git a/src/repository.c b/src/repository.c
index 23c99b0f0..0cbdf086a 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -124,6 +124,8 @@ void git_repository_free(git_repository *repo)
git__free(repo->workdir);
git__free(repo->namespace);
git__free(repo->name_8dot3);
+ git__free(repo->ident_name);
+ git__free(repo->ident_email);
git__memzero(repo, sizeof(*repo));
git__free(repo);
@@ -169,7 +171,13 @@ static git_repository *repository_alloc(void)
int git_repository_new(git_repository **out)
{
- *out = repository_alloc();
+ git_repository *repo;
+
+ *out = repo = repository_alloc();
+ GITERR_CHECK_ALLOC(repo);
+
+ repo->is_bare = 1;
+
return 0;
}
@@ -189,7 +197,7 @@ static int load_config_data(git_repository *repo, const git_config *config)
static int load_workdir(git_repository *repo, git_config *config, git_buf *parent_path)
{
int error;
- const git_config_entry *ce;
+ git_config_entry *ce;
git_buf worktree = GIT_BUF_INIT;
if (repo->is_bare)
@@ -202,7 +210,7 @@ static int load_workdir(git_repository *repo, git_config *config, git_buf *paren
if (ce && ce->value) {
if ((error = git_path_prettify_dir(
&worktree, ce->value, repo->path_repository)) < 0)
- return error;
+ goto cleanup;
repo->workdir = git_buf_detach(&worktree);
}
@@ -210,14 +218,18 @@ static int load_workdir(git_repository *repo, git_config *config, git_buf *paren
repo->workdir = git_buf_detach(parent_path);
else {
if (git_path_dirname_r(&worktree, repo->path_repository) < 0 ||
- git_path_to_dir(&worktree) < 0)
- return -1;
+ git_path_to_dir(&worktree) < 0) {
+ error = -1;
+ goto cleanup;
+ }
repo->workdir = git_buf_detach(&worktree);
}
GITERR_CHECK_ALLOC(repo->workdir);
- return 0;
+cleanup:
+ git_config_entry_free(ce);
+ return error;
}
/*
@@ -1887,40 +1899,63 @@ cleanup:
return error;
}
-static bool looks_like_a_branch(const char *refname)
+static int checkout_message(git_buf *out, git_reference *old, const char *new)
{
- return git__prefixcmp(refname, GIT_REFS_HEADS_DIR) == 0;
+ git_buf_puts(out, "checkout: moving from ");
+
+ if (git_reference_type(old) == GIT_REF_SYMBOLIC)
+ git_buf_puts(out, git_reference__shorthand(git_reference_symbolic_target(old)));
+ else
+ git_buf_puts(out, git_oid_tostr_s(git_reference_target(old)));
+
+ git_buf_puts(out, " to ");
+
+ if (git_reference__is_branch(new))
+ git_buf_puts(out, git_reference__shorthand(new));
+ else
+ git_buf_puts(out, new);
+
+ if (git_buf_oom(out))
+ return -1;
+
+ return 0;
}
int git_repository_set_head(
git_repository* repo,
- const char* refname,
- const git_signature *signature,
- const char *log_message)
+ const char* refname)
{
- git_reference *ref,
- *new_head = NULL;
+ git_reference *ref = NULL, *current = NULL, *new_head = NULL;
+ git_buf log_message = GIT_BUF_INIT;
int error;
assert(repo && refname);
+ if ((error = git_reference_lookup(&current, repo, GIT_HEAD_FILE)) < 0)
+ return error;
+
+ if ((error = checkout_message(&log_message, current, refname)) < 0)
+ goto cleanup;
+
error = git_reference_lookup(&ref, repo, refname);
if (error < 0 && error != GIT_ENOTFOUND)
- return error;
+ goto cleanup;
if (!error) {
if (git_reference_is_branch(ref)) {
error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE,
- git_reference_name(ref), true, signature, log_message);
+ git_reference_name(ref), true, git_buf_cstr(&log_message));
} else {
- error = git_repository_set_head_detached(repo, git_reference_target(ref),
- signature, log_message);
+ error = git_repository_set_head_detached(repo, git_reference_target(ref));
}
- } else if (looks_like_a_branch(refname)) {
+ } else if (git_reference__is_branch(refname)) {
error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE, refname,
- true, signature, log_message);
+ true, git_buf_cstr(&log_message));
}
+cleanup:
+ git_buf_free(&log_message);
+ git_reference_free(current);
git_reference_free(ref);
git_reference_free(new_head);
return error;
@@ -1928,57 +1963,68 @@ int git_repository_set_head(
int git_repository_set_head_detached(
git_repository* repo,
- const git_oid* commitish,
- const git_signature *signature,
- const char *log_message)
+ const git_oid* commitish)
{
int error;
- git_object *object,
- *peeled = NULL;
- git_reference *new_head = NULL;
+ git_buf log_message = GIT_BUF_INIT;
+ git_object *object = NULL, *peeled = NULL;
+ git_reference *new_head = NULL, *current = NULL;
assert(repo && commitish);
- if ((error = git_object_lookup(&object, repo, commitish, GIT_OBJ_ANY)) < 0)
+ if ((error = git_reference_lookup(&current, repo, GIT_HEAD_FILE)) < 0)
return error;
+ if ((error = git_object_lookup(&object, repo, commitish, GIT_OBJ_ANY)) < 0)
+ goto cleanup;
+
if ((error = git_object_peel(&peeled, object, GIT_OBJ_COMMIT)) < 0)
goto cleanup;
- error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_object_id(peeled), true, signature, log_message);
+ if ((error = checkout_message(&log_message, current, git_oid_tostr_s(git_object_id(peeled)))) < 0)
+ goto cleanup;
+
+ error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_object_id(peeled), true, git_buf_cstr(&log_message));
cleanup:
+ git_buf_free(&log_message);
git_object_free(object);
git_object_free(peeled);
+ git_reference_free(current);
git_reference_free(new_head);
return error;
}
-int git_repository_detach_head(
- git_repository* repo,
- const git_signature *signature,
- const char *reflog_message)
+int git_repository_detach_head(git_repository* repo)
{
- git_reference *old_head = NULL,
- *new_head = NULL;
+ git_reference *old_head = NULL, *new_head = NULL, *current = NULL;
git_object *object = NULL;
+ git_buf log_message = GIT_BUF_INIT;
int error;
assert(repo);
- if ((error = git_repository_head(&old_head, repo)) < 0)
+ if ((error = git_reference_lookup(&current, repo, GIT_HEAD_FILE)) < 0)
return error;
+ if ((error = git_repository_head(&old_head, repo)) < 0)
+ goto cleanup;
+
if ((error = git_object_lookup(&object, repo, git_reference_target(old_head), GIT_OBJ_COMMIT)) < 0)
goto cleanup;
+ if ((error = checkout_message(&log_message, current, git_oid_tostr_s(git_object_id(object)))) < 0)
+ goto cleanup;
+
error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_reference_target(old_head),
- 1, signature, reflog_message);
+ 1, git_buf_cstr(&log_message));
cleanup:
+ git_buf_free(&log_message);
git_object_free(object);
git_reference_free(old_head);
git_reference_free(new_head);
+ git_reference_free(current);
return error;
}
@@ -2096,3 +2142,34 @@ int git_repository_init_init_options(
GIT_REPOSITORY_INIT_OPTIONS_INIT);
return 0;
}
+
+int git_repository_ident(const char **name, const char **email, const git_repository *repo)
+{
+ *name = repo->ident_name;
+ *email = repo->ident_email;
+
+ return 0;
+}
+
+int git_repository_set_ident(git_repository *repo, const char *name, const char *email)
+{
+ char *tmp_name = NULL, *tmp_email = NULL;
+
+ if (name) {
+ tmp_name = git__strdup(name);
+ GITERR_CHECK_ALLOC(tmp_name);
+ }
+
+ if (email) {
+ tmp_email = git__strdup(email);
+ GITERR_CHECK_ALLOC(tmp_email);
+ }
+
+ tmp_name = git__swap(repo->ident_name, tmp_name);
+ tmp_email = git__swap(repo->ident_email, tmp_email);
+
+ git__free(tmp_name);
+ git__free(tmp_email);
+
+ return 0;
+}
diff --git a/src/repository.h b/src/repository.h
index dffa9a8ae..56d443d3c 100644
--- a/src/repository.h
+++ b/src/repository.h
@@ -128,6 +128,9 @@ struct git_repository {
char *namespace;
char *name_8dot3;
+ char *ident_name;
+ char *ident_email;
+
unsigned is_bare:1,
has_8dot3:1,
has_8dot3_default:1;
diff --git a/src/reset.c b/src/reset.c
index dc3aa4a66..351ecaa2a 100644
--- a/src/reset.c
+++ b/src/reset.c
@@ -100,16 +100,14 @@ int git_reset(
git_repository *repo,
git_object *target,
git_reset_t reset_type,
- git_checkout_options *checkout_opts,
- const git_signature *signature,
- const char *log_message)
+ git_checkout_options *checkout_opts)
{
git_object *commit = NULL;
git_index *index = NULL;
git_tree *tree = NULL;
int error = 0;
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
- git_buf log_message_buf = GIT_BUF_INIT;
+ git_buf log_message = GIT_BUF_INIT;
assert(repo && target);
@@ -141,19 +139,17 @@ int git_reset(
goto cleanup;
}
- if (log_message)
- git_buf_sets(&log_message_buf, log_message);
- else
- git_buf_sets(&log_message_buf, "reset: moving");
+ if ((error = git_buf_printf(&log_message, "reset: moving to %s", git_oid_tostr_s(git_object_id(commit)))) < 0)
+ return error;
/* move HEAD to the new target */
if ((error = git_reference__update_terminal(repo, GIT_HEAD_FILE,
- git_object_id(commit), signature, git_buf_cstr(&log_message_buf))) < 0)
+ git_object_id(commit), NULL, git_buf_cstr(&log_message))) < 0)
goto cleanup;
if (reset_type == GIT_RESET_HARD) {
/* overwrite working directory with HEAD */
- opts.checkout_strategy = GIT_CHECKOUT_FORCE | GIT_CHECKOUT_SKIP_UNMERGED;
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
if ((error = git_checkout_tree(repo, (git_object *)tree, &opts)) < 0)
goto cleanup;
@@ -176,7 +172,7 @@ cleanup:
git_object_free(commit);
git_index_free(index);
git_tree_free(tree);
- git_buf_free(&log_message_buf);
+ git_buf_free(&log_message);
return error;
}
diff --git a/src/revert.c b/src/revert.c
index f8a7f4333..c481e7dea 100644
--- a/src/revert.c
+++ b/src/revert.c
@@ -73,7 +73,7 @@ static int revert_normalize_opts(
const char *their_label)
{
int error = 0;
- unsigned int default_checkout_strategy = GIT_CHECKOUT_SAFE_CREATE |
+ unsigned int default_checkout_strategy = GIT_CHECKOUT_SAFE |
GIT_CHECKOUT_ALLOW_CONFLICTS;
GIT_UNUSED(repo);
diff --git a/src/stash.c b/src/stash.c
index cad87d120..8aa48cafe 100644
--- a/src/stash.c
+++ b/src/stash.c
@@ -313,8 +313,7 @@ static int build_workdir_tree(
if ((error = git_commit_tree(&b_tree, b_commit)) < 0)
goto cleanup;
- if ((error = git_diff_tree_to_workdir_with_index(
- &diff, repo, b_tree, &opts)) < 0)
+ if ((error = git_diff_tree_to_workdir(&diff, repo, b_tree, &opts)) < 0)
goto cleanup;
data.include_changed = true;
@@ -411,7 +410,6 @@ cleanup:
static int update_reflog(
git_oid *w_commit_oid,
git_repository *repo,
- const git_signature *stasher,
const char *message)
{
git_reference *stash;
@@ -420,7 +418,7 @@ static int update_reflog(
if ((error = git_reference_ensure_log(repo, GIT_REFS_STASH_FILE)) < 0)
return error;
- error = git_reference_create(&stash, repo, GIT_REFS_STASH_FILE, w_commit_oid, 1, stasher, message);
+ error = git_reference_create(&stash, repo, GIT_REFS_STASH_FILE, w_commit_oid, 1, message);
git_reference_free(stash);
@@ -534,7 +532,7 @@ int git_stash_save(
git_buf_rtrim(&msg);
- if ((error = update_reflog(out, repo, stasher, git_buf_cstr(&msg))) < 0)
+ if ((error = update_reflog(out, repo, git_buf_cstr(&msg))) < 0)
goto cleanup;
if ((error = reset_index_and_workdir(
diff --git a/src/submodule.c b/src/submodule.c
index 80f1b3789..567ab748e 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -927,7 +927,6 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio
/* Copy over the remote callbacks */
clone_options.remote_callbacks = update_options.remote_callbacks;
- clone_options.signature = update_options.signature;
/* Get the status of the submodule to determine if it is already initialized */
if ((error = git_submodule_status(&submodule_status, sm)) < 0)
@@ -985,7 +984,7 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio
update_options.checkout_opts.checkout_strategy = update_options.clone_checkout_strategy;
if ((error = git_clone(&sub_repo, submodule_url, sm->path, &clone_options)) < 0 ||
- (error = git_repository_set_head_detached(sub_repo, git_submodule_index_id(sm), update_options.signature, NULL)) < 0 ||
+ (error = git_repository_set_head_detached(sub_repo, git_submodule_index_id(sm))) < 0 ||
(error = git_checkout_head(sub_repo, &update_options.checkout_opts)) != 0)
goto done;
} else {
@@ -997,7 +996,7 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio
if ((error = git_submodule_open(&sub_repo, sm)) < 0 ||
(error = git_object_lookup(&target_commit, sub_repo, git_submodule_index_id(sm), GIT_OBJ_COMMIT)) < 0 ||
(error = git_checkout_tree(sub_repo, target_commit, &update_options.checkout_opts)) != 0 ||
- (error = git_repository_set_head_detached(sub_repo, git_submodule_index_id(sm), update_options.signature, NULL)) < 0)
+ (error = git_repository_set_head_detached(sub_repo, git_submodule_index_id(sm))) < 0)
goto done;
/* Invalidate the wd flags as the workdir has been updated. */
diff --git a/src/tag.c b/src/tag.c
index 3b8d684ed..6e69d760d 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -273,7 +273,7 @@ static int git_tag_create__internal(
} else
git_oid_cpy(oid, git_object_id(target));
- error = git_reference_create(&new_ref, repo, ref_name.ptr, oid, allow_ref_overwrite, NULL, NULL);
+ error = git_reference_create(&new_ref, repo, ref_name.ptr, oid, allow_ref_overwrite, NULL);
cleanup:
git_reference_free(new_ref);
@@ -380,7 +380,7 @@ int git_tag_create_frombuffer(git_oid *oid, git_repository *repo, const char *bu
}
error = git_reference_create(
- &new_ref, repo, ref_name.ptr, oid, allow_ref_overwrite, NULL, NULL);
+ &new_ref, repo, ref_name.ptr, oid, allow_ref_overwrite, NULL);
git_reference_free(new_ref);
git_buf_free(&ref_name);
diff --git a/src/transports/http.c b/src/transports/http.c
index 807e08044..0907afa6d 100644
--- a/src/transports/http.c
+++ b/src/transports/http.c
@@ -350,6 +350,11 @@ static int on_headers_complete(http_parser *parser)
} else {
assert(t->cred);
+ if (!(t->cred->credtype & allowed_auth_types)) {
+ giterr_set(GITERR_NET, "credentials callback returned an invalid cred type");
+ return t->parse_error = PARSE_ERROR_GENERIC;
+ }
+
/* Successfully acquired a credential. */
t->parse_error = PARSE_ERROR_REPLAY;
return 0;
diff --git a/src/transports/local.c b/src/transports/local.c
index 89f2651cd..bedd2390b 100644
--- a/src/transports/local.c
+++ b/src/transports/local.c
@@ -348,7 +348,7 @@ static int local_push_update_remote_ref(
if (lref[0] != '\0') {
/* Create or update a ref */
error = git_reference_create(NULL, remote_repo, rref, loid,
- !git_oid_iszero(roid), NULL, NULL);
+ !git_oid_iszero(roid), NULL);
} else {
/* Delete a ref */
if ((error = git_reference_lookup(&remote_ref, remote_repo, rref)) < 0) {
diff --git a/src/win32/git2.rc b/src/win32/git2.rc
index 22c63f695..b2e59807b 100644
--- a/src/win32/git2.rc
+++ b/src/win32/git2.rc
@@ -6,8 +6,8 @@
#endif
VS_VERSION_INFO VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
- FILEVERSION LIBGIT2_VER_MAJOR,LIBGIT2_VER_MINOR,LIBGIT2_VER_REVISION,0
- PRODUCTVERSION LIBGIT2_VER_MAJOR,LIBGIT2_VER_MINOR,LIBGIT2_VER_REVISION,0
+ FILEVERSION LIBGIT2_VER_MAJOR,LIBGIT2_VER_MINOR,LIBGIT2_VER_REVISION,LIBGIT2_VER_PATCH
+ PRODUCTVERSION LIBGIT2_VER_MAJOR,LIBGIT2_VER_MINOR,LIBGIT2_VER_REVISION,LIBGIT2_VER_PATCH
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
#ifdef _DEBUG
FILEFLAGS VS_FF_DEBUG
diff --git a/src/win32/mingw-compat.h b/src/win32/mingw-compat.h
index feedfecf4..a4a5a31c7 100644
--- a/src/win32/mingw-compat.h
+++ b/src/win32/mingw-compat.h
@@ -17,6 +17,13 @@
#define stat _stati64
#endif
+#if _WIN32_WINNT < 0x0600 && !defined(__MINGW64_VERSION_MAJOR)
+#undef MemoryBarrier
+void __mingworg_MemoryBarrier(void);
+#define MemoryBarrier __mingworg_MemoryBarrier
+#define VOLUME_NAME_DOS 0x0
+#endif
+
#endif
#endif /* INCLUDE_mingw_compat__ */
diff --git a/src/win32/msvc-compat.h b/src/win32/msvc-compat.h
index 4789d63df..8004bc1f8 100644
--- a/src/win32/msvc-compat.h
+++ b/src/win32/msvc-compat.h
@@ -15,6 +15,9 @@
typedef unsigned short mode_t;
typedef SSIZE_T ssize_t;
+#define strcasecmp(s1, s2) _stricmp(s1, s2)
+#define strncasecmp(s1, s2, c) _strnicmp(s1, s2, c)
+
#endif
#define GIT_STDLIB_CALL __cdecl
diff --git a/src/win32/posix.h b/src/win32/posix.h
index 104966edc..4bc6bfe2e 100644
--- a/src/win32/posix.h
+++ b/src/win32/posix.h
@@ -32,8 +32,6 @@ extern int p_recv(GIT_SOCKET socket, void *buffer, size_t length, int flags);
extern int p_send(GIT_SOCKET socket, const void *buffer, size_t length, int flags);
extern int p_inet_pton(int af, const char* src, void* dst);
-#define strcasecmp(s1, s2) _stricmp(s1, s2)
-#define strncasecmp(s1, s2, c) _strnicmp(s1, s2, c)
extern int p_vsnprintf(char *buffer, size_t count, const char *format, va_list argptr);
extern int p_snprintf(char *buffer, size_t count, const char *format, ...) GIT_FORMAT_PRINTF(3, 4);
extern int p_mkstemp(char *tmp_path);
@@ -41,7 +39,7 @@ extern int p_chdir(const char* path);
extern int p_chmod(const char* path, mode_t mode);
extern int p_rmdir(const char* path);
extern int p_access(const char* path, mode_t mode);
-extern int p_ftruncate(int fd, long size);
+extern int p_ftruncate(int fd, git_off_t size);
/* p_lstat is almost but not quite POSIX correct. Specifically, the use of
* ENOTDIR is wrong, in that it does not mean precisely that a non-directory
diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c
index 6e005c1cd..544b1ebd5 100644
--- a/src/win32/posix_w32.c
+++ b/src/win32/posix_w32.c
@@ -42,12 +42,28 @@
/* GetFinalPathNameByHandleW signature */
typedef DWORD(WINAPI *PFGetFinalPathNameByHandleW)(HANDLE, LPWSTR, DWORD, DWORD);
-int p_ftruncate(int fd, long size)
+/**
+ * Truncate or extend file.
+ *
+ * We now take a "git_off_t" rather than "long" because
+ * files may be longer than 2Gb.
+ */
+int p_ftruncate(int fd, git_off_t size)
{
-#if defined(_MSC_VER) && _MSC_VER >= 1500
- return _chsize_s(fd, size);
+ if (size < 0) {
+ errno = EINVAL;
+ return -1;
+ }
+
+#if !defined(__MINGW32__) || defined(MINGW_HAS_SECURE_API)
+ return ((_chsize_s(fd, size) == 0) ? 0 : -1);
#else
- return _chsize(fd, size);
+ /* TODO MINGW32 Find a replacement for _chsize() that handles big files. */
+ if (size > INT32_MAX) {
+ errno = EFBIG;
+ return -1;
+ }
+ return _chsize(fd, (long)size);
#endif
}
diff --git a/tests/checkout/crlf.c b/tests/checkout/crlf.c
index b6d4e949a..a7a579eaa 100644
--- a/tests/checkout/crlf.c
+++ b/tests/checkout/crlf.c
@@ -21,7 +21,7 @@ void test_checkout_crlf__cleanup(void)
void test_checkout_crlf__detect_crlf_autocrlf_false(void)
{
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
cl_repo_set_bool(g_repo, "core.autocrlf", false);
@@ -36,7 +36,7 @@ void test_checkout_crlf__autocrlf_false_index_size_is_unfiltered_size(void)
git_index *index;
const git_index_entry *entry;
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
cl_repo_set_bool(g_repo, "core.autocrlf", false);
@@ -56,7 +56,7 @@ void test_checkout_crlf__autocrlf_false_index_size_is_unfiltered_size(void)
void test_checkout_crlf__detect_crlf_autocrlf_true(void)
{
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
cl_repo_set_bool(g_repo, "core.autocrlf", true);
@@ -73,7 +73,7 @@ void test_checkout_crlf__detect_crlf_autocrlf_true(void)
void test_checkout_crlf__more_lf_autocrlf_true(void)
{
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
cl_repo_set_bool(g_repo, "core.autocrlf", true);
@@ -85,7 +85,7 @@ void test_checkout_crlf__more_lf_autocrlf_true(void)
void test_checkout_crlf__more_crlf_autocrlf_true(void)
{
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
cl_repo_set_bool(g_repo, "core.autocrlf", true);
@@ -97,7 +97,7 @@ void test_checkout_crlf__more_crlf_autocrlf_true(void)
void test_checkout_crlf__all_crlf_autocrlf_true(void)
{
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
cl_repo_set_bool(g_repo, "core.autocrlf", true);
@@ -109,11 +109,11 @@ void test_checkout_crlf__all_crlf_autocrlf_true(void)
void test_checkout_crlf__detect_crlf_autocrlf_true_utf8(void)
{
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
cl_repo_set_bool(g_repo, "core.autocrlf", true);
- git_repository_set_head(g_repo, "refs/heads/utf8", NULL, NULL);
+ git_repository_set_head(g_repo, "refs/heads/utf8");
git_checkout_head(g_repo, &opts);
if (GIT_EOL_NATIVE == GIT_EOL_LF)
@@ -136,7 +136,7 @@ void test_checkout_crlf__autocrlf_true_index_size_is_filtered_size(void)
git_index *index;
const git_index_entry *entry;
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
cl_repo_set_bool(g_repo, "core.autocrlf", true);
@@ -162,7 +162,7 @@ void test_checkout_crlf__with_ident(void)
git_index *index;
git_blob *blob;
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
cl_git_mkfile("crlf/.gitattributes",
"*.txt text\n*.bin binary\n"
@@ -252,7 +252,7 @@ void test_checkout_crlf__with_ident(void)
void test_checkout_crlf__autocrlf_false_no_attrs(void)
{
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
cl_repo_set_bool(g_repo, "core.autocrlf", false);
@@ -265,7 +265,7 @@ void test_checkout_crlf__autocrlf_false_no_attrs(void)
void test_checkout_crlf__autocrlf_true_no_attrs(void)
{
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
cl_repo_set_bool(g_repo, "core.autocrlf", true);
@@ -283,7 +283,7 @@ void test_checkout_crlf__autocrlf_true_no_attrs(void)
void test_checkout_crlf__autocrlf_input_no_attrs(void)
{
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
cl_repo_set_string(g_repo, "core.autocrlf", "input");
@@ -296,7 +296,7 @@ void test_checkout_crlf__autocrlf_input_no_attrs(void)
void test_checkout_crlf__autocrlf_false_text_auto_attr(void)
{
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
cl_git_mkfile("./crlf/.gitattributes", "* text=auto\n");
@@ -316,7 +316,7 @@ void test_checkout_crlf__autocrlf_false_text_auto_attr(void)
void test_checkout_crlf__autocrlf_true_text_auto_attr(void)
{
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
cl_git_mkfile("./crlf/.gitattributes", "* text=auto\n");
@@ -336,7 +336,7 @@ void test_checkout_crlf__autocrlf_true_text_auto_attr(void)
void test_checkout_crlf__autocrlf_input_text_auto_attr(void)
{
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
cl_git_mkfile("./crlf/.gitattributes", "* text=auto\n");
diff --git a/tests/checkout/index.c b/tests/checkout/index.c
index 112324a04..63ed4b177 100644
--- a/tests/checkout/index.c
+++ b/tests/checkout/index.c
@@ -49,7 +49,7 @@ void test_checkout_index__can_create_missing_files(void)
cl_assert_equal_i(false, git_path_isfile("./testrepo/branch_file.txt"));
cl_assert_equal_i(false, git_path_isfile("./testrepo/new.txt"));
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_RECREATE_MISSING;
cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
@@ -69,7 +69,9 @@ void test_checkout_index__can_remove_untracked_files(void)
cl_assert_equal_i(true, git_path_isdir("./testrepo/dir/subdir/subsubdir"));
opts.checkout_strategy =
- GIT_CHECKOUT_SAFE_CREATE | GIT_CHECKOUT_REMOVE_UNTRACKED;
+ GIT_CHECKOUT_SAFE |
+ GIT_CHECKOUT_RECREATE_MISSING |
+ GIT_CHECKOUT_REMOVE_UNTRACKED;
cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
@@ -88,7 +90,7 @@ void test_checkout_index__honor_the_specified_pathspecs(void)
cl_assert_equal_i(false, git_path_isfile("./testrepo/branch_file.txt"));
cl_assert_equal_i(false, git_path_isfile("./testrepo/new.txt"));
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_RECREATE_MISSING;
cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
@@ -107,7 +109,7 @@ void test_checkout_index__honor_the_gitattributes_directives(void)
cl_git_mkfile("./testrepo/.gitattributes", attributes);
cl_repo_set_bool(g_repo, "core.autocrlf", false);
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_RECREATE_MISSING;
cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
@@ -125,7 +127,7 @@ void test_checkout_index__honor_coreautocrlf_setting_set_to_true(void)
cl_git_pass(p_unlink("./testrepo/.gitattributes"));
cl_repo_set_bool(g_repo, "core.autocrlf", true);
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_RECREATE_MISSING;
cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
@@ -139,7 +141,7 @@ void test_checkout_index__honor_coresymlinks_setting_set_to_true(void)
cl_repo_set_bool(g_repo, "core.symlinks", true);
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_RECREATE_MISSING;
cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
@@ -165,7 +167,7 @@ void test_checkout_index__honor_coresymlinks_setting_set_to_false(void)
cl_repo_set_bool(g_repo, "core.symlinks", false);
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_RECREATE_MISSING;
cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
@@ -207,7 +209,7 @@ void test_checkout_index__options_disable_filters(void)
cl_git_mkfile("./testrepo/.gitattributes", "*.txt text eol=crlf\n");
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_RECREATE_MISSING;
opts.disable_filters = false;
cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
@@ -238,7 +240,7 @@ void test_checkout_index__options_dir_modes(void)
reset_index_to_treeish((git_object *)commit);
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_RECREATE_MISSING;
opts.dir_mode = 0701;
cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
@@ -264,7 +266,7 @@ void test_checkout_index__options_override_file_modes(void)
if (!cl_is_chmod_supported())
return;
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_RECREATE_MISSING;
opts.file_mode = 0700;
cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
@@ -329,8 +331,9 @@ void test_checkout_index__can_notify_of_skipped_files(void)
data.file = "new.txt";
data.sha = "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd";
- opts.checkout_strategy =
- GIT_CHECKOUT_SAFE_CREATE | GIT_CHECKOUT_ALLOW_CONFLICTS;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE |
+ GIT_CHECKOUT_RECREATE_MISSING |
+ GIT_CHECKOUT_ALLOW_CONFLICTS;
opts.notify_flags = GIT_CHECKOUT_NOTIFY_CONFLICT;
opts.notify_cb = test_checkout_notify_cb;
opts.notify_payload = &data;
@@ -368,7 +371,9 @@ void test_checkout_index__wont_notify_of_expected_line_ending_changes(void)
cl_git_mkfile("./testrepo/new.txt", "my new file\r\n");
opts.checkout_strategy =
- GIT_CHECKOUT_SAFE_CREATE | GIT_CHECKOUT_ALLOW_CONFLICTS;
+ GIT_CHECKOUT_SAFE |
+ GIT_CHECKOUT_RECREATE_MISSING |
+ GIT_CHECKOUT_ALLOW_CONFLICTS;
opts.notify_flags = GIT_CHECKOUT_NOTIFY_CONFLICT;
opts.notify_cb = dont_notify_cb;
opts.notify_payload = NULL;
@@ -388,7 +393,7 @@ void test_checkout_index__calls_progress_callback(void)
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
int calls = 0;
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_RECREATE_MISSING;
opts.progress_cb = checkout_progress_counter;
opts.progress_payload = &calls;
@@ -423,7 +428,9 @@ void test_checkout_index__can_overcome_name_clashes(void)
cl_assert(git_path_isfile("./testrepo/path0/file0"));
opts.checkout_strategy =
- GIT_CHECKOUT_SAFE_CREATE | GIT_CHECKOUT_ALLOW_CONFLICTS;
+ GIT_CHECKOUT_SAFE |
+ GIT_CHECKOUT_RECREATE_MISSING |
+ GIT_CHECKOUT_ALLOW_CONFLICTS;
cl_git_pass(git_checkout_index(g_repo, index, &opts));
cl_assert(git_path_isfile("./testrepo/path1"));
@@ -473,7 +480,9 @@ void test_checkout_index__can_update_prefixed_files(void)
cl_git_pass(p_mkdir("./testrepo/branch_file.txt.after", 0777));
opts.checkout_strategy =
- GIT_CHECKOUT_SAFE_CREATE | GIT_CHECKOUT_REMOVE_UNTRACKED;
+ GIT_CHECKOUT_SAFE |
+ GIT_CHECKOUT_RECREATE_MISSING |
+ GIT_CHECKOUT_REMOVE_UNTRACKED;
cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
@@ -523,7 +532,8 @@ void test_checkout_index__target_directory(void)
checkout_counts cts;
memset(&cts, 0, sizeof(cts));
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE |
+ GIT_CHECKOUT_RECREATE_MISSING;
opts.target_directory = "alternative";
cl_assert(!git_path_isdir("alternative"));
@@ -568,7 +578,8 @@ void test_checkout_index__target_directory_from_bare(void)
cl_git_pass(git_index_write(index));
git_index_free(index);
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE |
+ GIT_CHECKOUT_RECREATE_MISSING;
opts.notify_flags = GIT_CHECKOUT_NOTIFY_ALL;
opts.notify_cb = checkout_count_callback;
@@ -606,7 +617,7 @@ void test_checkout_index__can_get_repo_from_index(void)
cl_assert_equal_i(false, git_path_isfile("./testrepo/branch_file.txt"));
cl_assert_equal_i(false, git_path_isfile("./testrepo/new.txt"));
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_RECREATE_MISSING;
cl_git_pass(git_repository_index(&index, g_repo));
diff --git a/tests/checkout/tree.c b/tests/checkout/tree.c
index 0fabadc8d..7d4c784a1 100644
--- a/tests/checkout/tree.c
+++ b/tests/checkout/tree.c
@@ -15,7 +15,7 @@ void test_checkout_tree__initialize(void)
g_repo = cl_git_sandbox_init("testrepo");
GIT_INIT_STRUCTURE(&g_opts, GIT_CHECKOUT_OPTIONS_VERSION);
- g_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ g_opts.checkout_strategy = GIT_CHECKOUT_FORCE;
}
void test_checkout_tree__cleanup(void)
@@ -63,7 +63,7 @@ void test_checkout_tree__can_checkout_and_remove_directory(void)
cl_git_pass(git_revparse_single(&g_object, g_repo, "subtrees"));
cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
- cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees", NULL, NULL));
+ cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees"));
cl_assert_equal_i(true, git_path_isdir("./testrepo/ab/"));
cl_assert_equal_i(true, git_path_isfile("./testrepo/ab/de/2.txt"));
@@ -78,7 +78,7 @@ void test_checkout_tree__can_checkout_and_remove_directory(void)
cl_git_pass(git_revparse_single(&g_object, g_repo, "master"));
cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
- cl_git_pass(git_repository_set_head(g_repo, "refs/heads/master", NULL, NULL));
+ cl_git_pass(git_repository_set_head(g_repo, "refs/heads/master"));
/* This directory should no longer exist */
cl_assert_equal_i(false, git_path_isdir("./testrepo/ab/"));
@@ -163,7 +163,7 @@ void test_checkout_tree__can_switch_branches(void)
cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY));
cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
- cl_git_pass(git_repository_set_head(g_repo, "refs/heads/dir", NULL, NULL));
+ cl_git_pass(git_repository_set_head(g_repo, "refs/heads/dir"));
cl_assert(git_path_isfile("testrepo/README"));
cl_assert(git_path_isfile("testrepo/branch_file.txt"));
@@ -183,7 +183,7 @@ void test_checkout_tree__can_switch_branches(void)
cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY));
cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
- cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees", NULL, NULL));
+ cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees"));
cl_assert(git_path_isfile("testrepo/README"));
cl_assert(git_path_isfile("testrepo/branch_file.txt"));
@@ -253,7 +253,7 @@ static int checkout_tree_with_blob_ignored_in_workdir(int strategy, bool isdir)
cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY));
cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
- cl_git_pass(git_repository_set_head(g_repo, "refs/heads/dir", NULL, NULL));
+ cl_git_pass(git_repository_set_head(g_repo, "refs/heads/dir"));
cl_assert(git_path_isfile("testrepo/README"));
cl_assert(git_path_isfile("testrepo/branch_file.txt"));
@@ -313,7 +313,7 @@ void test_checkout_tree__can_overwrite_ignored_by_default(void)
{
cl_git_pass(checkout_tree_with_blob_ignored_in_workdir(GIT_CHECKOUT_SAFE, false));
- cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees", NULL, NULL));
+ cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees"));
cl_assert(git_path_isfile("testrepo/ab/4.txt"));
@@ -334,7 +334,7 @@ void test_checkout_tree__can_overwrite_ignored_folder_by_default(void)
{
cl_git_pass(checkout_tree_with_blob_ignored_in_workdir(GIT_CHECKOUT_SAFE, true));
- cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees", NULL, NULL));
+ cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees"));
cl_assert(git_path_isfile("testrepo/ab/4.txt"));
@@ -367,7 +367,7 @@ void test_checkout_tree__can_update_only(void)
cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY));
cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
- cl_git_pass(git_repository_set_head(g_repo, "refs/heads/dir", NULL, NULL));
+ cl_git_pass(git_repository_set_head(g_repo, "refs/heads/dir"));
assert_on_branch(g_repo, "dir");
@@ -396,7 +396,7 @@ void test_checkout_tree__can_checkout_with_pattern(void)
cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
cl_git_pass(
- git_repository_set_head_detached(g_repo, git_object_id(g_object), NULL, NULL));
+ git_repository_set_head_detached(g_repo, git_object_id(g_object)));
git_object_free(g_object);
g_object = NULL;
@@ -408,7 +408,7 @@ void test_checkout_tree__can_checkout_with_pattern(void)
/* now to a narrow patterned checkout */
- g_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ g_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
g_opts.paths.strings = entries;
g_opts.paths.count = 1;
@@ -435,7 +435,7 @@ void test_checkout_tree__can_disable_pattern_match(void)
cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
cl_git_pass(
- git_repository_set_head_detached(g_repo, git_object_id(g_object), NULL, NULL));
+ git_repository_set_head_detached(g_repo, git_object_id(g_object)));
git_object_free(g_object);
g_object = NULL;
@@ -445,7 +445,8 @@ void test_checkout_tree__can_disable_pattern_match(void)
/* now to a narrow patterned checkout, but disable pattern */
g_opts.checkout_strategy =
- GIT_CHECKOUT_SAFE_CREATE | GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH;
+ GIT_CHECKOUT_SAFE |
+ GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH;
g_opts.paths.strings = entries;
g_opts.paths.count = 1;
@@ -457,7 +458,7 @@ void test_checkout_tree__can_disable_pattern_match(void)
/* let's try that again, but allow the pattern match */
- g_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ g_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
@@ -480,11 +481,11 @@ void assert_conflict(
/* Create a branch pointing at the parent */
cl_git_pass(git_revparse_single(&g_object, g_repo, parent_sha));
cl_git_pass(git_branch_create(&branch, g_repo,
- "potential_conflict", (git_commit *)g_object, 0, NULL, NULL));
+ "potential_conflict", (git_commit *)g_object, 0));
/* Make HEAD point to this branch */
cl_git_pass(git_reference_symbolic_create(
- &head, g_repo, "HEAD", git_reference_name(branch), 1, NULL, NULL));
+ &head, g_repo, "HEAD", git_reference_name(branch), 1, NULL));
git_reference_free(head);
git_reference_free(branch);
@@ -571,7 +572,7 @@ void test_checkout_tree__donot_update_deleted_file_by_default(void)
cl_git_pass(git_oid_fromstr(&old_id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"));
cl_git_pass(git_commit_lookup(&old_commit, g_repo, &old_id));
- cl_git_pass(git_reset(g_repo, (git_object *)old_commit, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(g_repo, (git_object *)old_commit, GIT_RESET_HARD, NULL));
cl_git_pass(p_unlink("testrepo/branch_file.txt"));
cl_git_pass(git_index_remove_bypath(index ,"branch_file.txt"));
@@ -676,7 +677,7 @@ void test_checkout_tree__can_checkout_with_last_workdir_item_missing(void)
cl_git_pass(git_commit_lookup(&commit, g_repo, &commit_id));
cl_git_pass(git_checkout_tree(g_repo, (git_object *)commit, &opts));
- cl_git_pass(git_repository_set_head(g_repo, "refs/heads/master", NULL, NULL));
+ cl_git_pass(git_repository_set_head(g_repo, "refs/heads/master"));
cl_git_pass(p_mkdir("./testrepo/this-is-dir", 0777));
cl_git_mkfile("./testrepo/this-is-dir/contained_file", "content\n");
@@ -824,7 +825,8 @@ void test_checkout_tree__target_directory_from_bare(void)
g_repo = cl_git_sandbox_init("testrepo.git");
cl_assert(git_repository_is_bare(g_repo));
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE |
+ GIT_CHECKOUT_RECREATE_MISSING;
opts.notify_flags = GIT_CHECKOUT_NOTIFY_ALL;
opts.notify_cb = checkout_count_callback;
@@ -1047,7 +1049,7 @@ void test_checkout_tree__case_changing_rename(void)
cl_git_pass(git_commit_lookup(&dir_commit, g_repo, &dir_commit_id));
cl_git_pass(git_checkout_tree(g_repo, (git_object *)dir_commit, &opts));
- cl_git_pass(git_repository_set_head(g_repo, "refs/heads/dir", NULL, NULL));
+ cl_git_pass(git_repository_set_head(g_repo, "refs/heads/dir"));
cl_assert(git_path_isfile("testrepo/README"));
case_sensitive = !git_path_isfile("testrepo/readme");
@@ -1084,7 +1086,7 @@ void test_checkout_tree__case_changing_rename(void)
cl_git_pass(git_commit_lookup(&master_commit, g_repo, &master_id));
cl_git_pass(git_checkout_tree(g_repo, (git_object *)master_commit, &opts));
- cl_git_pass(git_repository_set_head(g_repo, "refs/heads/master", NULL, NULL));
+ cl_git_pass(git_repository_set_head(g_repo, "refs/heads/master"));
assert_on_branch(g_repo, "master");
@@ -1199,7 +1201,7 @@ void test_checkout_tree__can_not_update_index(void)
cl_git_pass(git_reference_name_to_id(&oid, g_repo, "HEAD"));
cl_git_pass(git_object_lookup(&head, g_repo, &oid, GIT_OBJ_ANY));
- cl_git_pass(git_reset(g_repo, head, GIT_RESET_HARD, &g_opts, NULL, NULL));
+ cl_git_pass(git_reset(g_repo, head, GIT_RESET_HARD, &g_opts));
cl_assert_equal_i(false, git_path_isdir("./testrepo/ab/"));
@@ -1236,7 +1238,7 @@ void test_checkout_tree__can_update_but_not_write_index(void)
cl_git_pass(git_reference_name_to_id(&oid, g_repo, "HEAD"));
cl_git_pass(git_object_lookup(&head, g_repo, &oid, GIT_OBJ_ANY));
- cl_git_pass(git_reset(g_repo, head, GIT_RESET_HARD, &g_opts, NULL, NULL));
+ cl_git_pass(git_reset(g_repo, head, GIT_RESET_HARD, &g_opts));
cl_assert_equal_i(false, git_path_isdir("./testrepo/ab/"));
@@ -1264,3 +1266,39 @@ void test_checkout_tree__can_update_but_not_write_index(void)
git_object_free(head);
git_index_free(index);
}
+
+/* Emulate checking out in a repo created by clone --no-checkout,
+ * which would not have written an index. */
+void test_checkout_tree__safe_proceeds_if_no_index(void)
+{
+ git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
+ git_oid oid;
+ git_object *obj = NULL;
+
+ assert_on_branch(g_repo, "master");
+ cl_must_pass(p_unlink("testrepo/.git/index"));
+
+ /* do second checkout safe because we should be clean after first */
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE;
+
+ cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/subtrees"));
+ cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY));
+
+ cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
+ cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees"));
+
+ cl_assert(git_path_isfile("testrepo/README"));
+ cl_assert(git_path_isfile("testrepo/branch_file.txt"));
+ cl_assert(git_path_isfile("testrepo/new.txt"));
+ cl_assert(git_path_isfile("testrepo/ab/4.txt"));
+ cl_assert(git_path_isfile("testrepo/ab/c/3.txt"));
+ cl_assert(git_path_isfile("testrepo/ab/de/2.txt"));
+ cl_assert(git_path_isfile("testrepo/ab/de/fgh/1.txt"));
+
+ cl_assert(!git_path_isdir("testrepo/a"));
+
+ assert_on_branch(g_repo, "subtrees");
+
+ git_object_free(obj);
+}
+
diff --git a/tests/checkout/typechange.c b/tests/checkout/typechange.c
index 7aa14b36d..b4959a351 100644
--- a/tests/checkout/typechange.c
+++ b/tests/checkout/typechange.c
@@ -122,7 +122,7 @@ void test_checkout_typechange__checkout_typechanges_safe(void)
cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
cl_git_pass(
- git_repository_set_head_detached(g_repo, git_object_id(obj), NULL, NULL));
+ git_repository_set_head_detached(g_repo, git_object_id(obj)));
assert_workdir_matches_tree(g_repo, git_object_id(obj), NULL, true);
@@ -212,7 +212,7 @@ void test_checkout_typechange__checkout_with_conflicts(void)
p_mkdir("typechanges/d", 0777); /* intentionally empty dir */
force_create_file("typechanges/untracked");
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE;
memset(&cts, 0, sizeof(cts));
cl_git_fail(git_checkout_tree(g_repo, obj, &opts));
@@ -231,7 +231,7 @@ void test_checkout_typechange__checkout_with_conflicts(void)
cl_assert(!git_path_exists("typechanges/untracked"));
cl_git_pass(
- git_repository_set_head_detached(g_repo, git_object_id(obj), NULL, NULL));
+ git_repository_set_head_detached(g_repo, git_object_id(obj)));
assert_workdir_matches_tree(g_repo, git_object_id(obj), NULL, true);
diff --git a/tests/cherrypick/workdir.c b/tests/cherrypick/workdir.c
index 86a385d16..f8b4ca2e9 100644
--- a/tests/cherrypick/workdir.c
+++ b/tests/cherrypick/workdir.c
@@ -66,7 +66,7 @@ void test_cherrypick_workdir__automerge(void)
git_tree *cherrypicked_tree = NULL;
cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
- cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
git_oid_fromstr(&cherry_oid, cherrypick_oids[i]);
cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
@@ -118,7 +118,7 @@ void test_cherrypick_workdir__empty_result(void)
cl_assert(git_path_exists(TEST_REPO_PATH "/file4.txt"));
cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
- cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
git_oid_fromstr(&cherry_oid, cherrypick_oid);
cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
@@ -155,7 +155,7 @@ void test_cherrypick_workdir__conflicts(void)
git_oid_fromstr(&head_oid, "bafbf6912c09505ac60575cd43d3f2aba3bd84d8");
cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
- cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
git_oid_fromstr(&cherry_oid, "e9b63f3655b2ad80c0ff587389b5a9589a3a7110");
cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
@@ -263,7 +263,7 @@ void test_cherrypick_workdir__conflict_use_ours(void)
git_oid_fromstr(&head_oid, "bafbf6912c09505ac60575cd43d3f2aba3bd84d8");
cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
- cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
git_oid_fromstr(&cherry_oid, "e9b63f3655b2ad80c0ff587389b5a9589a3a7110");
cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
@@ -275,7 +275,7 @@ void test_cherrypick_workdir__conflict_use_ours(void)
/* resolve conflicts in the index by taking "ours" */
opts.merge_opts.file_favor = GIT_MERGE_FILE_FAVOR_OURS;
- cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
cl_git_pass(git_cherrypick(repo, commit, &opts));
cl_assert(merge_test_index(repo_index, merge_filesystem_entries, 3));
@@ -305,7 +305,7 @@ void test_cherrypick_workdir__rename(void)
git_oid_fromstr(&head_oid, "cfc4f0999a8367568e049af4f72e452d40828a15");
cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
- cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
git_oid_fromstr(&cherry_oid, "2a26c7e88b285613b302ba76712bc998863f3cbc");
cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
@@ -340,7 +340,7 @@ void test_cherrypick_workdir__both_renamed(void)
git_oid_fromstr(&head_oid, "44cd2ed2052c9c68f9a439d208e9614dc2a55c70");
cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
- cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
git_oid_fromstr(&cherry_oid, "2a26c7e88b285613b302ba76712bc998863f3cbc");
cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
@@ -391,7 +391,7 @@ void test_cherrypick_workdir__merge_fails_without_mainline_specified(void)
git_oid_fromstr(&head_oid, "cfc4f0999a8367568e049af4f72e452d40828a15");
cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
- cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
git_oid_fromstr(&cherry_oid, "abe4603bc7cd5b8167a267e0e2418fd2348f8cff");
cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
@@ -423,7 +423,7 @@ void test_cherrypick_workdir__merge_first_parent(void)
git_oid_fromstr(&head_oid, "cfc4f0999a8367568e049af4f72e452d40828a15");
cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
- cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
git_oid_fromstr(&cherry_oid, "abe4603bc7cd5b8167a267e0e2418fd2348f8cff");
cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
@@ -455,7 +455,7 @@ void test_cherrypick_workdir__merge_second_parent(void)
git_oid_fromstr(&head_oid, "cfc4f0999a8367568e049af4f72e452d40828a15");
cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
- cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
git_oid_fromstr(&cherry_oid, "abe4603bc7cd5b8167a267e0e2418fd2348f8cff");
cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
diff --git a/tests/clar.c b/tests/clar.c
index 17f767a02..1182ed1c3 100644
--- a/tests/clar.c
+++ b/tests/clar.c
@@ -132,6 +132,10 @@ static struct {
jmp_buf trampoline;
int trampoline_enabled;
+
+ cl_trace_cb *pfn_trace_cb;
+ void *trace_payload;
+
} _clar;
struct clar_func {
@@ -163,6 +167,23 @@ static int clar_sandbox(void);
/* Load the declarations for the test suite */
#include "clar.suite"
+
+#define CL_TRACE(ev) \
+ do { \
+ if (_clar.pfn_trace_cb) \
+ _clar.pfn_trace_cb(ev, \
+ _clar.active_suite, \
+ _clar.active_test, \
+ _clar.trace_payload); \
+ } while (0)
+
+void cl_trace_register(cl_trace_cb *cb, void *payload)
+{
+ _clar.pfn_trace_cb = cb;
+ _clar.trace_payload = payload;
+}
+
+
/* Core test functions */
static void
clar_report_errors(void)
@@ -191,11 +212,15 @@ clar_run_test(
_clar.test_status = CL_TEST_OK;
_clar.trampoline_enabled = 1;
+ CL_TRACE(CL_TRACE__TEST__BEGIN);
+
if (setjmp(_clar.trampoline) == 0) {
if (initialize->ptr != NULL)
initialize->ptr();
+ CL_TRACE(CL_TRACE__TEST__RUN_BEGIN);
test->ptr();
+ CL_TRACE(CL_TRACE__TEST__RUN_END);
}
_clar.trampoline_enabled = 0;
@@ -206,6 +231,8 @@ clar_run_test(
if (cleanup->ptr != NULL)
cleanup->ptr();
+ CL_TRACE(CL_TRACE__TEST__END);
+
_clar.tests_ran++;
/* remove any local-set cleanup methods */
@@ -235,6 +262,8 @@ clar_run_suite(const struct clar_suite *suite, const char *filter)
clar_print_onsuite(suite->name, ++_clar.suites_ran);
_clar.active_suite = suite->name;
+ _clar.active_test = NULL;
+ CL_TRACE(CL_TRACE__SUITE_BEGIN);
if (filter) {
size_t suitelen = strlen(suite->name);
@@ -259,6 +288,9 @@ clar_run_suite(const struct clar_suite *suite, const char *filter)
if (_clar.exit_on_error && _clar.total_errors)
return;
}
+
+ _clar.active_test = NULL;
+ CL_TRACE(CL_TRACE__SUITE_END);
}
static void
@@ -424,6 +456,7 @@ static void abort_test(void)
exit(-1);
}
+ CL_TRACE(CL_TRACE__TEST__LONGJMP);
longjmp(_clar.trampoline, -1);
}
diff --git a/tests/clar.h b/tests/clar.h
index 514203f89..5c674d70f 100644
--- a/tests/clar.h
+++ b/tests/clar.h
@@ -26,6 +26,48 @@ const char *clar_sandbox_path(void);
void cl_set_cleanup(void (*cleanup)(void *), void *opaque);
void cl_fs_cleanup(void);
+/**
+ * cl_trace_* is a hook to provide a simple global tracing
+ * mechanism.
+ *
+ * The goal here is to let main() provide clar-proper
+ * with a callback to optionally write log info for
+ * test operations into the same stream used by their
+ * actual tests. This would let them print test names
+ * and maybe performance data as they choose.
+ *
+ * The goal is NOT to alter the flow of control or to
+ * override test selection/skipping. (So the callback
+ * does not return a value.)
+ *
+ * The goal is NOT to duplicate the existing
+ * pass/fail/skip reporting. (So the callback
+ * does not accept a status/errorcode argument.)
+ *
+ */
+typedef enum cl_trace_event {
+ CL_TRACE__SUITE_BEGIN,
+ CL_TRACE__SUITE_END,
+ CL_TRACE__TEST__BEGIN,
+ CL_TRACE__TEST__END,
+ CL_TRACE__TEST__RUN_BEGIN,
+ CL_TRACE__TEST__RUN_END,
+ CL_TRACE__TEST__LONGJMP,
+} cl_trace_event;
+
+typedef void (cl_trace_cb)(
+ cl_trace_event ev,
+ const char *suite_name,
+ const char *test_name,
+ void *payload);
+
+/**
+ * Register a callback into CLAR to send global trace events.
+ * Pass NULL to disable.
+ */
+void cl_trace_register(cl_trace_cb *cb, void *payload);
+
+
#ifdef CLAR_FIXTURE_PATH
const char *cl_fixture(const char *fixture_name);
void cl_fixture_sandbox(const char *fixture_name);
diff --git a/tests/clar_libgit2_timer.c b/tests/clar_libgit2_timer.c
new file mode 100644
index 000000000..737506da2
--- /dev/null
+++ b/tests/clar_libgit2_timer.c
@@ -0,0 +1,31 @@
+#include "clar_libgit2.h"
+#include "clar_libgit2_timer.h"
+#include "buffer.h"
+
+void cl_perf_timer__init(cl_perf_timer *t)
+{
+ memset(t, 0, sizeof(cl_perf_timer));
+}
+
+void cl_perf_timer__start(cl_perf_timer *t)
+{
+ t->time_started = git__timer();
+}
+
+void cl_perf_timer__stop(cl_perf_timer *t)
+{
+ double time_now = git__timer();
+
+ t->last = time_now - t->time_started;
+ t->sum += t->last;
+}
+
+double cl_perf_timer__last(const cl_perf_timer *t)
+{
+ return t->last;
+}
+
+double cl_perf_timer__sum(const cl_perf_timer *t)
+{
+ return t->sum;
+}
diff --git a/tests/clar_libgit2_timer.h b/tests/clar_libgit2_timer.h
new file mode 100644
index 000000000..0d150e018
--- /dev/null
+++ b/tests/clar_libgit2_timer.h
@@ -0,0 +1,35 @@
+#ifndef __CLAR_LIBGIT2_TIMER__
+#define __CLAR_LIBGIT2_TIMER__
+
+struct cl_perf_timer
+{
+ /* cummulative running time across all start..stop intervals */
+ double sum;
+
+ /* value of last start..stop interval */
+ double last;
+
+ /* clock value at start */
+ double time_started;
+};
+
+#define CL_PERF_TIMER_INIT {0}
+
+typedef struct cl_perf_timer cl_perf_timer;
+
+void cl_perf_timer__init(cl_perf_timer *t);
+void cl_perf_timer__start(cl_perf_timer *t);
+void cl_perf_timer__stop(cl_perf_timer *t);
+
+/**
+ * return value of last start..stop interval in seconds.
+ */
+double cl_perf_timer__last(const cl_perf_timer *t);
+
+/**
+ * return cummulative running time across all start..stop
+ * intervals in seconds.
+ */
+double cl_perf_timer__sum(const cl_perf_timer *t);
+
+#endif /* __CLAR_LIBGIT2_TIMER__ */
diff --git a/tests/clar_libgit2_trace.c b/tests/clar_libgit2_trace.c
new file mode 100644
index 000000000..ae582d1cb
--- /dev/null
+++ b/tests/clar_libgit2_trace.c
@@ -0,0 +1,229 @@
+#include "clar_libgit2.h"
+#include "clar_libgit2_trace.h"
+#include "clar_libgit2_timer.h"
+#include "trace.h"
+
+
+struct method {
+ const char *name;
+ void (*git_trace_cb)(git_trace_level_t level, const char *msg);
+ void (*close)(void);
+};
+
+
+#if defined(GIT_TRACE)
+static void _git_trace_cb__printf(git_trace_level_t level, const char *msg)
+{
+ /* TODO Use level to print a per-message prefix. */
+ GIT_UNUSED(level);
+
+ printf("%s\n", msg);
+}
+
+#if defined(GIT_WIN32)
+static void _git_trace_cb__debug(git_trace_level_t level, const char *msg)
+{
+ /* TODO Use level to print a per-message prefix. */
+ GIT_UNUSED(level);
+
+ OutputDebugString(msg);
+ OutputDebugString("\n");
+
+ printf("%s\n", msg);
+}
+#else
+#define _git_trace_cb__debug _git_trace_cb__printf
+#endif
+
+
+static void _trace_printf_close(void)
+{
+ fflush(stdout);
+}
+
+#define _trace_debug_close _trace_printf_close
+
+
+static struct method s_methods[] = {
+ { "printf", _git_trace_cb__printf, _trace_printf_close },
+ { "debug", _git_trace_cb__debug, _trace_debug_close },
+ /* TODO add file method */
+ {0},
+};
+
+
+static int s_trace_loaded = 0;
+static int s_trace_level = GIT_TRACE_NONE;
+static struct method *s_trace_method = NULL;
+
+
+static int set_method(const char *name)
+{
+ int k;
+
+ if (!name || !*name)
+ name = "printf";
+
+ for (k=0; (s_methods[k].name); k++) {
+ if (strcmp(name, s_methods[k].name) == 0) {
+ s_trace_method = &s_methods[k];
+ return 0;
+ }
+ }
+ fprintf(stderr, "Unknown CLAR_TRACE_METHOD: '%s'\n", name);
+ return -1;
+}
+
+
+/**
+ * Lookup CLAR_TRACE_LEVEL and CLAR_TRACE_METHOD from
+ * the environment and set the above s_trace_* fields.
+ *
+ * If CLAR_TRACE_LEVEL is not set, we disable tracing.
+ *
+ * TODO If set, we assume GIT_TRACE_TRACE level, which
+ * logs everything. Later, we may want to parse the
+ * value of the environment variable and set a specific
+ * level.
+ *
+ * We assume the "printf" method. This can be changed
+ * with the CLAR_TRACE_METHOD environment variable.
+ * Currently, this is only needed on Windows for a "debug"
+ * version which also writes to the debug output window
+ * in Visual Studio.
+ *
+ * TODO add a "file" method that would open and write
+ * to a well-known file. This would help keep trace
+ * output and clar output separate.
+ *
+ */
+static void _load_trace_params(void)
+{
+ char *sz_level;
+ char *sz_method;
+
+ s_trace_loaded = 1;
+
+ sz_level = cl_getenv("CLAR_TRACE_LEVEL");
+ if (!sz_level || !*sz_level) {
+ s_trace_level = GIT_TRACE_NONE;
+ s_trace_method = NULL;
+ return;
+ }
+
+ /* TODO Parse sz_level and set s_trace_level. */
+ s_trace_level = GIT_TRACE_TRACE;
+
+ sz_method = cl_getenv("CLAR_TRACE_METHOD");
+ if (set_method(sz_method) < 0)
+ set_method(NULL);
+}
+
+#define HR "================================================================"
+
+/**
+ * Timer to report the take spend in a test's run() method.
+ */
+static cl_perf_timer s_timer_run = CL_PERF_TIMER_INIT;
+
+/**
+ * Timer to report total time in a test (init, run, cleanup).
+ */
+static cl_perf_timer s_timer_test = CL_PERF_TIMER_INIT;
+
+void _cl_trace_cb__event_handler(
+ cl_trace_event ev,
+ const char *suite_name,
+ const char *test_name,
+ void *payload)
+{
+ GIT_UNUSED(payload);
+
+ switch (ev) {
+ case CL_TRACE__SUITE_BEGIN:
+ git_trace(GIT_TRACE_TRACE, "\n\n%s\n%s: Begin Suite", HR, suite_name);
+ break;
+
+ case CL_TRACE__SUITE_END:
+ git_trace(GIT_TRACE_TRACE, "\n\n%s: End Suite\n%s", suite_name, HR);
+ break;
+
+ case CL_TRACE__TEST__BEGIN:
+ git_trace(GIT_TRACE_TRACE, "\n%s::%s: Begin Test", suite_name, test_name);
+ cl_perf_timer__init(&s_timer_test);
+ cl_perf_timer__start(&s_timer_test);
+ break;
+
+ case CL_TRACE__TEST__END:
+ cl_perf_timer__stop(&s_timer_test);
+ git_trace(GIT_TRACE_TRACE, "%s::%s: End Test (%.3f %.3f)", suite_name, test_name,
+ cl_perf_timer__last(&s_timer_run),
+ cl_perf_timer__last(&s_timer_test));
+ break;
+
+ case CL_TRACE__TEST__RUN_BEGIN:
+ git_trace(GIT_TRACE_TRACE, "%s::%s: Begin Run", suite_name, test_name);
+ cl_perf_timer__init(&s_timer_run);
+ cl_perf_timer__start(&s_timer_run);
+ break;
+
+ case CL_TRACE__TEST__RUN_END:
+ cl_perf_timer__stop(&s_timer_run);
+ git_trace(GIT_TRACE_TRACE, "%s::%s: End Run", suite_name, test_name);
+ break;
+
+ case CL_TRACE__TEST__LONGJMP:
+ cl_perf_timer__stop(&s_timer_run);
+ git_trace(GIT_TRACE_TRACE, "%s::%s: Aborted", suite_name, test_name);
+ break;
+
+ default:
+ break;
+ }
+}
+
+#endif /*GIT_TRACE*/
+
+/**
+ * Setup/Enable git_trace() based upon settings user's environment.
+ *
+ */
+void cl_global_trace_register(void)
+{
+#if defined(GIT_TRACE)
+ if (!s_trace_loaded)
+ _load_trace_params();
+
+ if (s_trace_level == GIT_TRACE_NONE)
+ return;
+ if (s_trace_method == NULL)
+ return;
+ if (s_trace_method->git_trace_cb == NULL)
+ return;
+
+ git_trace_set(s_trace_level, s_trace_method->git_trace_cb);
+ cl_trace_register(_cl_trace_cb__event_handler, NULL);
+#endif
+}
+
+/**
+ * If we turned on git_trace() earlier, turn it off.
+ *
+ * This is intended to let us close/flush any buffered
+ * IO if necessary.
+ *
+ */
+void cl_global_trace_disable(void)
+{
+#if defined(GIT_TRACE)
+ cl_trace_register(NULL, NULL);
+ git_trace_set(GIT_TRACE_NONE, NULL);
+ if (s_trace_method && s_trace_method->close)
+ s_trace_method->close();
+
+ /* Leave s_trace_ vars set so they can restart tracing
+ * since we only want to hit the environment variables
+ * once.
+ */
+#endif
+}
diff --git a/tests/clar_libgit2_trace.h b/tests/clar_libgit2_trace.h
new file mode 100644
index 000000000..09d1e050f
--- /dev/null
+++ b/tests/clar_libgit2_trace.h
@@ -0,0 +1,7 @@
+#ifndef __CLAR_LIBGIT2_TRACE__
+#define __CLAR_LIBGIT2_TRACE__
+
+void cl_global_trace_register(void);
+void cl_global_trace_disable(void);
+
+#endif
diff --git a/tests/clone/nonetwork.c b/tests/clone/nonetwork.c
index a0264b0d0..2a3157739 100644
--- a/tests/clone/nonetwork.c
+++ b/tests/clone/nonetwork.c
@@ -22,9 +22,8 @@ void test_clone_nonetwork__initialize(void)
memset(&g_options, 0, sizeof(git_clone_options));
g_options.version = GIT_CLONE_OPTIONS_VERSION;
g_options.checkout_opts = dummy_opts;
- g_options.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ g_options.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
g_options.remote_callbacks = dummy_callbacks;
- cl_git_pass(git_signature_now(&g_options.signature, "Me", "foo@example.com"));
}
void test_clone_nonetwork__cleanup(void)
@@ -44,7 +43,6 @@ void test_clone_nonetwork__cleanup(void)
g_remote = NULL;
}
- git_signature_free(g_options.signature);
cl_fixture_cleanup("./foo");
}
@@ -228,13 +226,11 @@ void test_clone_nonetwork__can_detached_head(void)
git_object *obj;
git_repository *cloned;
git_reference *cloned_head;
- git_reflog *log;
- const git_reflog_entry *entry;
cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
cl_git_pass(git_revparse_single(&obj, g_repo, "master~1"));
- cl_git_pass(git_repository_set_head_detached(g_repo, git_object_id(obj), NULL, NULL));
+ cl_git_pass(git_repository_set_head_detached(g_repo, git_object_id(obj)));
cl_git_pass(git_clone(&cloned, "./foo", "./foo1", &g_options));
@@ -243,13 +239,8 @@ void test_clone_nonetwork__can_detached_head(void)
cl_git_pass(git_repository_head(&cloned_head, cloned));
cl_assert_equal_oid(git_object_id(obj), git_reference_target(cloned_head));
- cl_git_pass(git_reflog_read(&log, cloned, "HEAD"));
- entry = git_reflog_entry_byindex(log, 0);
- cl_assert_equal_s("foo@example.com", git_reflog_entry_committer(entry)->email);
-
git_object_free(obj);
git_reference_free(cloned_head);
- git_reflog_free(log);
git_repository_free(cloned);
cl_fixture_cleanup("./foo1");
@@ -267,7 +258,6 @@ static void assert_correct_reflog(const char *name)
cl_assert_equal_i(1, git_reflog_entrycount(log));
entry = git_reflog_entry_byindex(log, 0);
cl_assert_equal_s(expected_log_message, git_reflog_entry_message(entry));
- cl_assert_equal_s("foo@example.com", git_reflog_entry_committer(entry)->email);
git_reflog_free(log);
}
@@ -301,7 +291,7 @@ void test_clone_nonetwork__clone_from_empty_sets_upstream(void)
cl_set_cleanup(&cleanup_repository, "./repowithunborn");
cl_git_pass(git_clone(&repo, "./test1", "./repowithunborn", NULL));
- cl_git_pass(git_repository_config(&config, repo));
+ cl_git_pass(git_repository_config_snapshot(&config, repo));
cl_git_pass(git_config_get_string(&str, config, "branch.master.remote"));
cl_assert_equal_s("origin", str);
diff --git a/tests/commit/write.c b/tests/commit/write.c
index 6212ef641..ee9eb8237 100644
--- a/tests/commit/write.c
+++ b/tests/commit/write.c
@@ -120,7 +120,7 @@ void test_commit_write__root(void)
cl_assert(head_old != NULL);
git_reference_free(head);
- cl_git_pass(git_reference_symbolic_create(&head, g_repo, "HEAD", branch_name, 1, NULL, NULL));
+ cl_git_pass(git_reference_symbolic_create(&head, g_repo, "HEAD", branch_name, 1, NULL));
cl_git_pass(git_commit_create_v(
&commit_id, /* out id */
diff --git a/tests/config/config_helpers.c b/tests/config/config_helpers.c
index 35da720e0..025838ad7 100644
--- a/tests/config/config_helpers.c
+++ b/tests/config/config_helpers.c
@@ -1,6 +1,7 @@
#include "clar_libgit2.h"
#include "config_helpers.h"
#include "repository.h"
+#include "buffer.h"
void assert_config_entry_existence(
git_repository *repo,
@@ -8,12 +9,13 @@ void assert_config_entry_existence(
bool is_supposed_to_exist)
{
git_config *config;
- const char *out;
+ git_config_entry *entry = NULL;
int result;
cl_git_pass(git_repository_config__weakptr(&config, repo));
- result = git_config_get_string(&out, config, name);
+ result = git_config_get_entry(&entry, config, name);
+ git_config_entry_free(entry);
if (is_supposed_to_exist)
cl_git_pass(result);
@@ -27,13 +29,14 @@ void assert_config_entry_value(
const char *expected_value)
{
git_config *config;
- const char *out;
+ git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_repository_config__weakptr(&config, repo));
- cl_git_pass(git_config_get_string(&out, config, name));
+ cl_git_pass(git_config_get_string_buf(&buf, config, name));
- cl_assert_equal_s(expected_value, out);
+ cl_assert_equal_s(expected_value, git_buf_cstr(&buf));
+ git_buf_free(&buf);
}
static int count_config_entries_cb(
diff --git a/tests/config/configlevel.c b/tests/config/configlevel.c
index 1c22e8d9f..ca478b1a5 100644
--- a/tests/config/configlevel.c
+++ b/tests/config/configlevel.c
@@ -22,7 +22,7 @@ void test_config_configlevel__adding_the_same_level_twice_returns_EEXISTS(void)
void test_config_configlevel__can_replace_a_config_file_at_an_existing_level(void)
{
git_config *cfg;
- const char *s;
+ git_buf buf = {0};
cl_git_pass(git_config_new(&cfg));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config18"),
@@ -30,9 +30,10 @@ void test_config_configlevel__can_replace_a_config_file_at_an_existing_level(voi
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config19"),
GIT_CONFIG_LEVEL_LOCAL, 1));
- cl_git_pass(git_config_get_string(&s, cfg, "core.stringglobal"));
- cl_assert_equal_s("don't find me!", s);
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.stringglobal"));
+ cl_assert_equal_s("don't find me!", buf.ptr);
+ git_buf_free(&buf);
git_config_free(cfg);
}
@@ -40,7 +41,7 @@ void test_config_configlevel__can_read_from_a_single_level_focused_file_after_pa
{
git_config *cfg;
git_config *single_level_cfg;
- const char *s;
+ git_buf buf = {0};
cl_git_pass(git_config_new(&cfg));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config18"),
@@ -52,9 +53,10 @@ void test_config_configlevel__can_read_from_a_single_level_focused_file_after_pa
git_config_free(cfg);
- cl_git_pass(git_config_get_string(&s, single_level_cfg, "core.stringglobal"));
- cl_assert_equal_s("don't find me!", s);
+ cl_git_pass(git_config_get_string_buf(&buf, single_level_cfg, "core.stringglobal"));
+ cl_assert_equal_s("don't find me!", buf.ptr);
+ git_buf_free(&buf);
git_config_free(single_level_cfg);
}
diff --git a/tests/config/global.c b/tests/config/global.c
index fc471f90d..4481308d6 100644
--- a/tests/config/global.c
+++ b/tests/config/global.c
@@ -46,8 +46,9 @@ void test_config_global__open_global(void)
void test_config_global__open_xdg(void)
{
git_config *cfg, *xdg, *selected;
- const char *val, *str = "teststring";
+ const char *str = "teststring";
const char *key = "this.variable";
+ git_buf buf = {0};
cl_git_mkfile("xdg/git/config", "# XDG config\n[core]\n test = 1\n");
@@ -56,9 +57,10 @@ void test_config_global__open_xdg(void)
cl_git_pass(git_config_open_global(&selected, cfg));
cl_git_pass(git_config_set_string(xdg, key, str));
- cl_git_pass(git_config_get_string(&val, selected, key));
- cl_assert_equal_s(str, val);
+ cl_git_pass(git_config_get_string_buf(&buf, selected, key));
+ cl_assert_equal_s(str, buf.ptr);
+ git_buf_free(&buf);
git_config_free(selected);
git_config_free(xdg);
git_config_free(cfg);
diff --git a/tests/config/include.c b/tests/config/include.c
index 8232af489..882b89b16 100644
--- a/tests/config/include.c
+++ b/tests/config/include.c
@@ -5,20 +5,20 @@
void test_config_include__relative(void)
{
git_config *cfg;
- const char *str;
+ git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config-include")));
- cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.baz"));
- cl_assert_equal_s(str, "huzzah");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
+ cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
+ git_buf_free(&buf);
git_config_free(cfg);
}
void test_config_include__absolute(void)
{
git_config *cfg;
- const char *str;
git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_buf_printf(&buf, "[include]\npath = %s/config-included", cl_fixture("config")));
@@ -27,25 +27,27 @@ void test_config_include__absolute(void)
git_buf_free(&buf);
cl_git_pass(git_config_open_ondisk(&cfg, "config-include-absolute"));
- cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.baz"));
- cl_assert_equal_s(str, "huzzah");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
+ cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
+ git_buf_free(&buf);
git_config_free(cfg);
}
void test_config_include__homedir(void)
{
git_config *cfg;
- const char *str;
+ git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, cl_fixture("config")));
cl_git_mkfile("config-include-homedir", "[include]\npath = ~/config-included");
cl_git_pass(git_config_open_ondisk(&cfg, "config-include-homedir"));
- cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.baz"));
- cl_assert_equal_s(str, "huzzah");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
+ cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
+ git_buf_free(&buf);
git_config_free(cfg);
cl_sandbox_set_search_path_defaults();
@@ -55,7 +57,7 @@ void test_config_include__homedir(void)
void test_config_include__ordering(void)
{
git_config *cfg;
- const char *str;
+ git_buf buf = GIT_BUF_INIT;
cl_git_mkfile("included", "[foo \"bar\"]\nbaz = hurrah\nfrotz = hiya");
cl_git_mkfile("including",
@@ -65,11 +67,13 @@ void test_config_include__ordering(void)
cl_git_pass(git_config_open_ondisk(&cfg, "including"));
- cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.frotz"));
- cl_assert_equal_s(str, "hiya");
- cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.baz"));
- cl_assert_equal_s(str, "huzzah");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.frotz"));
+ cl_assert_equal_s("hiya", git_buf_cstr(&buf));
+ git_buf_clear(&buf);
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
+ cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
+ git_buf_free(&buf);
git_config_free(cfg);
}
@@ -90,16 +94,17 @@ void test_config_include__depth(void)
void test_config_include__missing(void)
{
git_config *cfg;
- const char *str;
+ git_buf buf = GIT_BUF_INIT;
cl_git_mkfile("including", "[include]\npath = nonexistentfile\n[foo]\nbar = baz");
giterr_clear();
cl_git_pass(git_config_open_ondisk(&cfg, "including"));
cl_assert(giterr_last() == NULL);
- cl_git_pass(git_config_get_string(&str, cfg, "foo.bar"));
- cl_assert_equal_s(str, "baz");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar"));
+ cl_assert_equal_s("baz", git_buf_cstr(&buf));
+ git_buf_free(&buf);
git_config_free(cfg);
}
@@ -107,7 +112,7 @@ void test_config_include__missing(void)
void test_config_include__depth2(void)
{
git_config *cfg;
- const char *str;
+ git_buf buf = GIT_BUF_INIT;
const char *content = "[include]\n" replicate10(replicate10("path=bottom\n"));
cl_git_mkfile("top-level", "[include]\npath = middle\n[foo]\nbar = baz");
@@ -116,11 +121,13 @@ void test_config_include__depth2(void)
cl_git_pass(git_config_open_ondisk(&cfg, "top-level"));
- cl_git_pass(git_config_get_string(&str, cfg, "foo.bar"));
- cl_assert_equal_s(str, "baz");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar"));
+ cl_assert_equal_s("baz", git_buf_cstr(&buf));
- cl_git_pass(git_config_get_string(&str, cfg, "foo.bar2"));
- cl_assert_equal_s(str, "baz2");
+ git_buf_clear(&buf);
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar2"));
+ cl_assert_equal_s("baz2", git_buf_cstr(&buf));
+ git_buf_free(&buf);
git_config_free(cfg);
}
diff --git a/tests/config/new.c b/tests/config/new.c
index dd6dbca9e..b39baa0a5 100644
--- a/tests/config/new.c
+++ b/tests/config/new.c
@@ -8,8 +8,8 @@
void test_config_new__write_new_config(void)
{
- const char *out;
git_config *config;
+ git_buf buf = GIT_BUF_INIT;
cl_git_mkfile(TEST_CONFIG, "");
cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
@@ -21,11 +21,13 @@ void test_config_new__write_new_config(void)
cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
- cl_git_pass(git_config_get_string(&out, config, "color.ui"));
- cl_assert_equal_s(out, "auto");
- cl_git_pass(git_config_get_string(&out, config, "core.editor"));
- cl_assert_equal_s(out, "ed");
+ cl_git_pass(git_config_get_string_buf(&buf, config, "color.ui"));
+ cl_assert_equal_s("auto", git_buf_cstr(&buf));
+ git_buf_clear(&buf);
+ cl_git_pass(git_config_get_string_buf(&buf, config, "core.editor"));
+ cl_assert_equal_s("ed", git_buf_cstr(&buf));
+ git_buf_free(&buf);
git_config_free(config);
p_unlink(TEST_CONFIG);
diff --git a/tests/config/read.c b/tests/config/read.c
index 1799970fb..a7b77159e 100644
--- a/tests/config/read.c
+++ b/tests/config/read.c
@@ -2,6 +2,13 @@
#include "buffer.h"
#include "path.h"
+static git_buf buf = GIT_BUF_INIT;
+
+void test_config_read__cleanup(void)
+{
+ git_buf_free(&buf);
+}
+
void test_config_read__simple_read(void)
{
git_config *cfg;
@@ -25,14 +32,15 @@ void test_config_read__case_sensitive(void)
{
git_config *cfg;
int i;
- const char *str;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config1")));
- cl_git_pass(git_config_get_string(&str, cfg, "this.that.other"));
- cl_assert_equal_s(str, "true");
- cl_git_pass(git_config_get_string(&str, cfg, "this.That.other"));
- cl_assert_equal_s(str, "yes");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "this.that.other"));
+ cl_assert_equal_s("true", git_buf_cstr(&buf));
+ git_buf_clear(&buf);
+
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "this.That.other"));
+ cl_assert_equal_s("yes", git_buf_cstr(&buf));
cl_git_pass(git_config_get_bool(&i, cfg, "this.that.other"));
cl_assert(i == 1);
@@ -52,12 +60,11 @@ void test_config_read__case_sensitive(void)
void test_config_read__multiline_value(void)
{
git_config *cfg;
- const char *str;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config2")));
- cl_git_pass(git_config_get_string(&str, cfg, "this.That.and"));
- cl_assert_equal_s(str, "one one one two two three three");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "this.That.and"));
+ cl_assert_equal_s("one one one two two three three", git_buf_cstr(&buf));
git_config_free(cfg);
}
@@ -68,15 +75,14 @@ void test_config_read__multiline_value(void)
void test_config_read__subsection_header(void)
{
git_config *cfg;
- const char *str;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config3")));
- cl_git_pass(git_config_get_string(&str, cfg, "section.subsection.var"));
- cl_assert_equal_s(str, "hello");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "section.subsection.var"));
+ cl_assert_equal_s("hello", git_buf_cstr(&buf));
/* The subsection is transformed to lower-case */
- cl_must_fail(git_config_get_string(&str, cfg, "section.subSectIon.var"));
+ cl_must_fail(git_config_get_string_buf(&buf, cfg, "section.subSectIon.var"));
git_config_free(cfg);
}
@@ -84,21 +90,21 @@ void test_config_read__subsection_header(void)
void test_config_read__lone_variable(void)
{
git_config *cfg;
- const char *str;
int i;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config4")));
cl_git_fail(git_config_get_int32(&i, cfg, "some.section.variable"));
- cl_git_pass(git_config_get_string(&str, cfg, "some.section.variable"));
- cl_assert_equal_s(str, "");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.section.variable"));
+ cl_assert_equal_s("", git_buf_cstr(&buf));
+ git_buf_clear(&buf);
cl_git_pass(git_config_get_bool(&i, cfg, "some.section.variable"));
cl_assert(i == 1);
- cl_git_pass(git_config_get_string(&str, cfg, "some.section.variableeq"));
- cl_assert_equal_s(str, "");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.section.variableeq"));
+ cl_assert_equal_s("", git_buf_cstr(&buf));
cl_git_pass(git_config_get_bool(&i, cfg, "some.section.variableeq"));
cl_assert(i == 0);
@@ -184,14 +190,14 @@ void test_config_read__header_in_last_line(void)
void test_config_read__prefixes(void)
{
git_config *cfg;
- const char *str;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config9")));
- cl_git_pass(git_config_get_string(&str, cfg, "remote.ab.url"));
- cl_assert_equal_s(str, "http://example.com/git/ab");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "remote.ab.url"));
+ cl_assert_equal_s("http://example.com/git/ab", git_buf_cstr(&buf));
+ git_buf_clear(&buf);
- cl_git_pass(git_config_get_string(&str, cfg, "remote.abba.url"));
- cl_assert_equal_s(str, "http://example.com/git/abba");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "remote.abba.url"));
+ cl_assert_equal_s("http://example.com/git/abba", git_buf_cstr(&buf));
git_config_free(cfg);
}
@@ -199,11 +205,10 @@ void test_config_read__prefixes(void)
void test_config_read__escaping_quotes(void)
{
git_config *cfg;
- const char *str;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config13")));
- cl_git_pass(git_config_get_string(&str, cfg, "core.editor"));
- cl_assert_equal_s("\"C:/Program Files/Nonsense/bah.exe\" \"--some option\"", str);
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.editor"));
+ cl_assert_equal_s("\"C:/Program Files/Nonsense/bah.exe\" \"--some option\"", git_buf_cstr(&buf));
git_config_free(cfg);
}
@@ -363,15 +368,15 @@ void test_config_read__iterator_glob(void)
void test_config_read__whitespace_not_required_around_assignment(void)
{
git_config *cfg;
- const char *str;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config14")));
- cl_git_pass(git_config_get_string(&str, cfg, "a.b"));
- cl_assert_equal_s(str, "c");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "a.b"));
+ cl_assert_equal_s("c", git_buf_cstr(&buf));
+ git_buf_clear(&buf);
- cl_git_pass(git_config_get_string(&str, cfg, "d.e"));
- cl_assert_equal_s(str, "f");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "d.e"));
+ cl_assert_equal_s("f", git_buf_cstr(&buf));
git_config_free(cfg);
}
@@ -379,7 +384,7 @@ void test_config_read__whitespace_not_required_around_assignment(void)
void test_config_read__read_git_config_entry(void)
{
git_config *cfg;
- const git_config_entry *entry;
+ git_config_entry *entry;
cl_git_pass(git_config_new(&cfg));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"),
@@ -390,6 +395,7 @@ void test_config_read__read_git_config_entry(void)
cl_assert_equal_s("42", entry->value);
cl_assert_equal_i(GIT_CONFIG_LEVEL_SYSTEM, entry->level);
+ git_config_entry_free(entry);
git_config_free(cfg);
}
@@ -480,7 +486,6 @@ void test_config_read__simple_read_from_specific_level(void)
git_config *cfg, *cfg_specific;
int i;
int64_t l, expected = +9223372036854775803;
- const char *s;
cl_git_pass(git_config_new(&cfg));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config18"),
@@ -496,8 +501,8 @@ void test_config_read__simple_read_from_specific_level(void)
cl_assert(l == expected);
cl_git_pass(git_config_get_bool(&i, cfg_specific, "core.boolglobal"));
cl_assert_equal_b(true, i);
- cl_git_pass(git_config_get_string(&s, cfg_specific, "core.stringglobal"));
- cl_assert_equal_s("I'm a global config value!", s);
+ cl_git_pass(git_config_get_string_buf(&buf, cfg_specific, "core.stringglobal"));
+ cl_assert_equal_s("I'm a global config value!", git_buf_cstr(&buf));
git_config_free(cfg_specific);
git_config_free(cfg);
@@ -558,14 +563,13 @@ void test_config_read__corrupt_header3(void)
void test_config_read__override_variable(void)
{
git_config *cfg;
- const char *str;
cl_set_cleanup(&clean_test_config, NULL);
cl_git_mkfile("./testconfig", "[some] var = one\nvar = two");
cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
- cl_git_pass(git_config_get_string(&str, cfg, "some.var"));
- cl_assert_equal_s(str, "two");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.var"));
+ cl_assert_equal_s("two", git_buf_cstr(&buf));
git_config_free(cfg);
}
diff --git a/tests/config/rename.c b/tests/config/rename.c
index db07c798f..a4614158a 100644
--- a/tests/config/rename.c
+++ b/tests/config/rename.c
@@ -21,11 +21,12 @@ void test_config_rename__cleanup(void)
void test_config_rename__can_rename(void)
{
- const git_config_entry *ce;
+ git_config_entry *ce;
cl_git_pass(git_config_get_entry(
&ce, g_config, "branch.track-local.remote"));
cl_assert_equal_s(".", ce->value);
+ git_config_entry_free(ce);
cl_git_fail(git_config_get_entry(
&ce, g_config, "branch.local-track.remote"));
@@ -36,6 +37,7 @@ void test_config_rename__can_rename(void)
cl_git_pass(git_config_get_entry(
&ce, g_config, "branch.local-track.remote"));
cl_assert_equal_s(".", ce->value);
+ git_config_entry_free(ce);
cl_git_fail(git_config_get_entry(
&ce, g_config, "branch.track-local.remote"));
@@ -43,7 +45,7 @@ void test_config_rename__can_rename(void)
void test_config_rename__prevent_overwrite(void)
{
- const git_config_entry *ce;
+ git_config_entry *ce;
cl_git_pass(git_config_set_string(
g_config, "branch.local-track.remote", "yellow"));
@@ -51,6 +53,7 @@ void test_config_rename__prevent_overwrite(void)
cl_git_pass(git_config_get_entry(
&ce, g_config, "branch.local-track.remote"));
cl_assert_equal_s("yellow", ce->value);
+ git_config_entry_free(ce);
cl_git_pass(git_config_rename_section(
g_repo, "branch.track-local", "branch.local-track"));
@@ -58,6 +61,7 @@ void test_config_rename__prevent_overwrite(void)
cl_git_pass(git_config_get_entry(
&ce, g_config, "branch.local-track.remote"));
cl_assert_equal_s(".", ce->value);
+ git_config_entry_free(ce);
/* so, we don't currently prevent overwrite... */
/* {
diff --git a/tests/config/stress.c b/tests/config/stress.c
index e8e9d2b61..503f44f03 100644
--- a/tests/config/stress.c
+++ b/tests/config/stress.c
@@ -6,6 +6,8 @@
#define TEST_CONFIG "git-test-config"
+static git_buf buf = GIT_BUF_INIT;
+
void test_config_stress__initialize(void)
{
git_filebuf file = GIT_FILEBUF_INIT;
@@ -20,50 +22,43 @@ void test_config_stress__initialize(void)
void test_config_stress__cleanup(void)
{
+ git_buf_free(&buf);
p_unlink(TEST_CONFIG);
}
void test_config_stress__dont_break_on_invalid_input(void)
{
- const char *editor, *color;
git_config *config;
cl_assert(git_path_exists(TEST_CONFIG));
cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
- cl_git_pass(git_config_get_string(&color, config, "color.ui"));
- cl_git_pass(git_config_get_string(&editor, config, "core.editor"));
+ cl_git_pass(git_config_get_string_buf(&buf, config, "color.ui"));
+ cl_git_pass(git_config_get_string_buf(&buf, config, "core.editor"));
git_config_free(config);
}
+void assert_config_value(git_config *config, const char *key, const char *value)
+{
+ git_buf_clear(&buf);
+ cl_git_pass(git_config_get_string_buf(&buf, config, key));
+ cl_assert_equal_s(value, git_buf_cstr(&buf));
+}
+
void test_config_stress__comments(void)
{
git_config *config;
- const char *str;
cl_git_pass(git_config_open_ondisk(&config, cl_fixture("config/config12")));
- cl_git_pass(git_config_get_string(&str, config, "some.section.test2"));
- cl_assert_equal_s("hello", str);
-
- cl_git_pass(git_config_get_string(&str, config, "some.section.test3"));
- cl_assert_equal_s("welcome", str);
-
- cl_git_pass(git_config_get_string(&str, config, "some.section.other"));
- cl_assert_equal_s("hello! \" ; ; ; ", str);
-
- cl_git_pass(git_config_get_string(&str, config, "some.section.other2"));
- cl_assert_equal_s("cool! \" # # # ", str);
-
- cl_git_pass(git_config_get_string(&str, config, "some.section.multi"));
- cl_assert_equal_s("hi, this is a ; multiline comment # with ;\n special chars and other stuff !@#", str);
-
- cl_git_pass(git_config_get_string(&str, config, "some.section.multi2"));
- cl_assert_equal_s("good, this is a ; multiline comment # with ;\n special chars and other stuff !@#", str);
-
- cl_git_pass(git_config_get_string(&str, config, "some.section.back"));
- cl_assert_equal_s("this is \ba phrase", str);
+ assert_config_value(config, "some.section.test2", "hello");
+ assert_config_value(config, "some.section.test3", "welcome");
+ assert_config_value(config, "some.section.other", "hello! \" ; ; ; ");
+ assert_config_value(config, "some.section.other2", "cool! \" # # # ");
+ assert_config_value(config, "some.section.multi", "hi, this is a ; multiline comment # with ;\n special chars and other stuff !@#");
+ assert_config_value(config, "some.section.multi2", "good, this is a ; multiline comment # with ;\n special chars and other stuff !@#");
+ assert_config_value(config, "some.section.back", "this is \ba phrase");
git_config_free(config);
}
@@ -71,7 +66,6 @@ void test_config_stress__comments(void)
void test_config_stress__escape_subsection_names(void)
{
git_config *config;
- const char *str;
cl_assert(git_path_exists("git-test-config"));
cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
@@ -81,15 +75,14 @@ void test_config_stress__escape_subsection_names(void)
cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
- cl_git_pass(git_config_get_string(&str, config, "some.sec\\tion.other"));
- cl_assert_equal_s("foo", str);
+ assert_config_value(config, "some.sec\\tion.other", "foo");
+
git_config_free(config);
}
void test_config_stress__trailing_backslash(void)
{
git_config *config;
- const char *str;
const char *path = "C:\\iam\\some\\windows\\path\\";
cl_assert(git_path_exists("git-test-config"));
@@ -98,20 +91,19 @@ void test_config_stress__trailing_backslash(void)
git_config_free(config);
cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
- cl_git_pass(git_config_get_string(&str, config, "windows.path"));
- cl_assert_equal_s(path, str);
+ assert_config_value(config, "windows.path", path);
+
git_config_free(config);
}
void test_config_stress__complex(void)
{
git_config *config;
- const char *str;
const char *path = "./config-immediate-multiline";
cl_git_mkfile(path, "[imm]\n multi = \"\\\nfoo\"");
cl_git_pass(git_config_open_ondisk(&config, path));
- cl_git_pass(git_config_get_string(&str, config, "imm.multi"));
- cl_assert_equal_s(str, "foo");
+ assert_config_value(config, "imm.multi", "foo");
+
git_config_free(config);
}
diff --git a/tests/config/validkeyname.c b/tests/config/validkeyname.c
index 0ef4a9ae3..4b36509af 100644
--- a/tests/config/validkeyname.c
+++ b/tests/config/validkeyname.c
@@ -3,7 +3,6 @@
#include "config.h"
static git_config *cfg;
-static const char *value;
void test_config_validkeyname__initialize(void)
{
@@ -22,7 +21,9 @@ void test_config_validkeyname__cleanup(void)
static void assert_invalid_config_key_name(const char *name)
{
- cl_git_fail_with(git_config_get_string(&value, cfg, name),
+ git_buf buf = GIT_BUF_INIT;
+
+ cl_git_fail_with(git_config_get_string_buf(&buf, cfg, name),
GIT_EINVALIDSPEC);
cl_git_fail_with(git_config_set_string(cfg, name, "42"),
GIT_EINVALIDSPEC);
diff --git a/tests/config/write.c b/tests/config/write.c
index 067b7445b..32e6f27b4 100644
--- a/tests/config/write.c
+++ b/tests/config/write.c
@@ -1,4 +1,5 @@
#include "clar_libgit2.h"
+#include "buffer.h"
void test_config_write__initialize(void)
{
@@ -108,15 +109,17 @@ void test_config_write__delete_value_at_specific_level(void)
void test_config_write__write_subsection(void)
{
git_config *cfg;
- const char *str;
+ git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_set_string(cfg, "my.own.var", "works"));
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
- cl_git_pass(git_config_get_string(&str, cfg, "my.own.var"));
- cl_assert_equal_s("works", str);
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "my.own.var"));
+ cl_assert_equal_s("works", git_buf_cstr(&buf));
+
+ git_buf_free(&buf);
git_config_free(cfg);
}
@@ -132,46 +135,52 @@ void test_config_write__delete_inexistent(void)
void test_config_write__value_containing_quotes(void)
{
git_config *cfg;
- const char* str;
+ git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_set_string(cfg, "core.somevar", "this \"has\" quotes"));
- cl_git_pass(git_config_get_string(&str, cfg, "core.somevar"));
- cl_assert_equal_s(str, "this \"has\" quotes");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar"));
+ cl_assert_equal_s("this \"has\" quotes", git_buf_cstr(&buf));
+ git_buf_clear(&buf);
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
- cl_git_pass(git_config_get_string(&str, cfg, "core.somevar"));
- cl_assert_equal_s(str, "this \"has\" quotes");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar"));
+ cl_assert_equal_s("this \"has\" quotes", git_buf_cstr(&buf));
+ git_buf_clear(&buf);
git_config_free(cfg);
/* The code path for values that already exist is different, check that one as well */
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_set_string(cfg, "core.somevar", "this also \"has\" quotes"));
- cl_git_pass(git_config_get_string(&str, cfg, "core.somevar"));
- cl_assert_equal_s(str, "this also \"has\" quotes");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar"));
+ cl_assert_equal_s("this also \"has\" quotes", git_buf_cstr(&buf));
+ git_buf_clear(&buf);
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
- cl_git_pass(git_config_get_string(&str, cfg, "core.somevar"));
- cl_assert_equal_s(str, "this also \"has\" quotes");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar"));
+ cl_assert_equal_s("this also \"has\" quotes", git_buf_cstr(&buf));
+ git_buf_free(&buf);
git_config_free(cfg);
}
void test_config_write__escape_value(void)
{
git_config *cfg;
- const char* str;
+ git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_set_string(cfg, "core.somevar", "this \"has\" quotes and \t"));
- cl_git_pass(git_config_get_string(&str, cfg, "core.somevar"));
- cl_assert_equal_s(str, "this \"has\" quotes and \t");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar"));
+ cl_assert_equal_s("this \"has\" quotes and \t", git_buf_cstr(&buf));
+ git_buf_clear(&buf);
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
- cl_git_pass(git_config_get_string(&str, cfg, "core.somevar"));
- cl_assert_equal_s(str, "this \"has\" quotes and \t");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar"));
+ cl_assert_equal_s("this \"has\" quotes and \t", git_buf_cstr(&buf));
+ git_buf_free(&buf);
git_config_free(cfg);
}
@@ -180,7 +189,7 @@ void test_config_write__add_value_at_specific_level(void)
git_config *cfg, *cfg_specific;
int i;
int64_t l, expected = +9223372036854775803;
- const char *s;
+ git_buf buf = GIT_BUF_INIT;
// open config15 as global level config file
cl_git_pass(git_config_new(&cfg));
@@ -207,9 +216,10 @@ void test_config_write__add_value_at_specific_level(void)
cl_assert(l == expected);
cl_git_pass(git_config_get_bool(&i, cfg, "core.boolglobal"));
cl_assert_equal_b(true, i);
- cl_git_pass(git_config_get_string(&s, cfg, "core.stringglobal"));
- cl_assert_equal_s("I'm a global config value!", s);
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.stringglobal"));
+ cl_assert_equal_s("I'm a global config value!", git_buf_cstr(&buf));
+ git_buf_free(&buf);
git_config_free(cfg);
}
@@ -247,7 +257,7 @@ void test_config_write__add_section_at_file_with_no_clrf_at_the_end(void)
void test_config_write__add_value_which_needs_quotes(void)
{
- git_config *cfg;
+ git_config *cfg, *base;
const char* str1;
const char* str2;
const char* str3;
@@ -262,7 +272,8 @@ void test_config_write__add_value_which_needs_quotes(void)
cl_git_pass(git_config_set_string(cfg, "core.startwhithsapceandcontainsdoublequote", " some\"thing"));
git_config_free(cfg);
- cl_git_pass(git_config_open_ondisk(&cfg, "config17"));
+ cl_git_pass(git_config_open_ondisk(&base, "config17"));
+ cl_git_pass(git_config_snapshot(&cfg, base));
cl_git_pass(git_config_get_string(&str1, cfg, "core.startwithspace"));
cl_assert_equal_s(" Something", str1);
cl_git_pass(git_config_get_string(&str2, cfg, "core.endwithspace"));
@@ -274,6 +285,7 @@ void test_config_write__add_value_which_needs_quotes(void)
cl_git_pass(git_config_get_string(&str5, cfg, "core.startwhithsapceandcontainsdoublequote"));
cl_assert_equal_s(" some\"thing", str5);
git_config_free(cfg);
+ git_config_free(base);
}
void test_config_write__can_set_a_value_to_NULL(void)
@@ -294,15 +306,16 @@ void test_config_write__can_set_an_empty_value(void)
{
git_repository *repository;
git_config *config;
- const char * str;
+ git_buf buf = {0};
repository = cl_git_sandbox_init("testrepo.git");
cl_git_pass(git_repository_config(&config, repository));
cl_git_pass(git_config_set_string(config, "core.somevar", ""));
- cl_git_pass(git_config_get_string(&str, config, "core.somevar"));
- cl_assert_equal_s(str, "");
+ cl_git_pass(git_config_get_string_buf(&buf, config, "core.somevar"));
+ cl_assert_equal_s("", buf.ptr);
+ git_buf_free(&buf);
git_config_free(config);
cl_git_sandbox_cleanup();
}
diff --git a/tests/core/ftruncate.c b/tests/core/ftruncate.c
new file mode 100644
index 000000000..21981d677
--- /dev/null
+++ b/tests/core/ftruncate.c
@@ -0,0 +1,48 @@
+/**
+ * Some tests for p_ftruncate() to ensure that
+ * properly handles large (2Gb+) files.
+ */
+
+#include "clar_libgit2.h"
+
+static const char *filename = "core_ftruncate.txt";
+static int fd = -1;
+
+void test_core_ftruncate__initialize(void)
+{
+ if (!cl_getenv("GITTEST_INVASIVE_FS_SIZE"))
+ cl_skip();
+
+ cl_must_pass((fd = p_open(filename, O_CREAT | O_RDWR, 0644)));
+}
+
+void test_core_ftruncate__cleanup(void)
+{
+ if (fd < 0)
+ return;
+
+ p_close(fd);
+ fd = 0;
+
+ p_unlink(filename);
+}
+
+static void _extend(git_off_t i64len)
+{
+ struct stat st;
+ int error;
+
+ cl_assert((error = p_ftruncate(fd, i64len)) == 0);
+ cl_assert((error = p_fstat(fd, &st)) == 0);
+ cl_assert(st.st_size == i64len);
+}
+
+void test_core_ftruncate__2gb(void)
+{
+ _extend(0x80000001);
+}
+
+void test_core_ftruncate__4gb(void)
+{
+ _extend(0x100000001);
+}
diff --git a/tests/describe/t6120.c b/tests/describe/t6120.c
index 2377335a5..6df397ec6 100644
--- a/tests/describe/t6120.c
+++ b/tests/describe/t6120.c
@@ -113,7 +113,7 @@ static void commit_and_tag(
if (tag_name == NULL)
return;
- cl_git_pass(git_reference_create(&ref, repo, tag_name, &commit_id, 0, NULL, NULL));
+ cl_git_pass(git_reference_create(&ref, repo, tag_name, &commit_id, 0, NULL));
git_reference_free(ref);
}
diff --git a/tests/diff/rename.c b/tests/diff/rename.c
index 28e0bf149..8a327f035 100644
--- a/tests/diff/rename.c
+++ b/tests/diff/rename.c
@@ -961,7 +961,7 @@ void test_diff_rename__rejected_match_can_match_others(void)
cl_git_pass(git_reference_lookup(&head, g_repo, "HEAD"));
cl_git_pass(git_reference_symbolic_set_target(
- &selfsimilar, head, "refs/heads/renames_similar", NULL, NULL));
+ &selfsimilar, head, "refs/heads/renames_similar", NULL));
cl_git_pass(git_checkout_head(g_repo, &opts));
cl_git_pass(git_repository_index(&index, g_repo));
@@ -1046,7 +1046,7 @@ void test_diff_rename__rejected_match_can_match_others_two(void)
cl_git_pass(git_reference_lookup(&head, g_repo, "HEAD"));
cl_git_pass(git_reference_symbolic_set_target(
- &selfsimilar, head, "refs/heads/renames_similar_two", NULL, NULL));
+ &selfsimilar, head, "refs/heads/renames_similar_two", NULL));
cl_git_pass(git_checkout_head(g_repo, &opts));
cl_git_pass(git_repository_index(&index, g_repo));
@@ -1104,7 +1104,7 @@ void test_diff_rename__rejected_match_can_match_others_three(void)
cl_git_pass(git_reference_lookup(&head, g_repo, "HEAD"));
cl_git_pass(git_reference_symbolic_set_target(
- &selfsimilar, head, "refs/heads/renames_similar_two", NULL, NULL));
+ &selfsimilar, head, "refs/heads/renames_similar_two", NULL));
cl_git_pass(git_checkout_head(g_repo, &opts));
cl_git_pass(git_repository_index(&index, g_repo));
@@ -1602,3 +1602,103 @@ void test_diff_rename__by_config_doesnt_mess_with_whitespace_settings(void)
git_tree_free(tree1);
git_tree_free(tree2);
}
+
+static void expect_files_renamed(const char *one, const char *two, uint32_t whitespace_flags)
+{
+ git_index *index;
+ git_diff *diff = NULL;
+ diff_expects exp;
+ git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
+ git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT;
+
+ diffopts.flags = GIT_DIFF_INCLUDE_UNTRACKED;
+ findopts.flags = GIT_DIFF_FIND_FOR_UNTRACKED |
+ GIT_DIFF_FIND_AND_BREAK_REWRITES |
+ GIT_DIFF_FIND_RENAMES_FROM_REWRITES |
+ whitespace_flags;
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+
+ cl_git_rewritefile("renames/ikeepsix.txt", one);
+ cl_git_pass(git_index_add_bypath(index, "ikeepsix.txt"));
+
+ cl_git_rmfile("renames/ikeepsix.txt");
+ cl_git_rewritefile("renames/ikeepsix2.txt", two);
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, index, &diffopts));
+ cl_git_pass(git_diff_find_similar(diff, &findopts));
+
+ memset(&exp, 0, sizeof(exp));
+
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+ cl_assert_equal_i(1, exp.files);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_RENAMED]);
+
+ git_diff_free(diff);
+ git_index_free(index);
+}
+
+/* test some variations on empty and blank files */
+void test_diff_rename__empty_files_renamed(void)
+{
+ /* empty files are identical when ignoring whitespace or not */
+ expect_files_renamed("", "", GIT_DIFF_FIND_DONT_IGNORE_WHITESPACE);
+ expect_files_renamed("", "", GIT_DIFF_FIND_IGNORE_WHITESPACE);
+}
+
+/* test that blank files are similar when ignoring whitespace */
+void test_diff_rename__blank_files_renamed_when_ignoring_whitespace(void)
+{
+ expect_files_renamed("", "\n\n", GIT_DIFF_FIND_IGNORE_WHITESPACE);
+ expect_files_renamed("", "\r\n\r\n", GIT_DIFF_FIND_IGNORE_WHITESPACE);
+ expect_files_renamed("\r\n\r\n", "\n\n\n", GIT_DIFF_FIND_IGNORE_WHITESPACE);
+
+ expect_files_renamed(" ", "\n\n", GIT_DIFF_FIND_IGNORE_WHITESPACE);
+ expect_files_renamed(" \n \n", "\n\n", GIT_DIFF_FIND_IGNORE_WHITESPACE);
+}
+
+/* blank files are not similar when whitespace is not ignored */
+static void expect_files_not_renamed(const char *one, const char *two, uint32_t whitespace_flags)
+{
+ git_index *index;
+ git_diff *diff = NULL;
+ diff_expects exp;
+ git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
+ git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT;
+
+ diffopts.flags = GIT_DIFF_INCLUDE_UNTRACKED;
+
+ findopts.flags = GIT_DIFF_FIND_FOR_UNTRACKED |
+ whitespace_flags;
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+
+ cl_git_rewritefile("renames/ikeepsix.txt", one);
+ cl_git_pass(git_index_add_bypath(index, "ikeepsix.txt"));
+
+ cl_git_rmfile("renames/ikeepsix.txt");
+ cl_git_rewritefile("renames/ikeepsix2.txt", two);
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, index, &diffopts));
+ cl_git_pass(git_diff_find_similar(diff, &findopts));
+
+ memset(&exp, 0, sizeof(exp));
+
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+ cl_assert_equal_i(2, exp.files);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
+
+ git_diff_free(diff);
+ git_index_free(index);
+}
+
+/* test that blank files are similar when ignoring renames */
+void test_diff_rename__blank_files_not_renamed_when_not_ignoring_whitespace(void)
+{
+ expect_files_not_renamed("", "\r\n\r\n\r\n", GIT_DIFF_FIND_DONT_IGNORE_WHITESPACE);
+ expect_files_not_renamed("", "\n\n\n\n", GIT_DIFF_FIND_DONT_IGNORE_WHITESPACE);
+ expect_files_not_renamed("\n\n\n\n", "\r\n\r\n\r\n", GIT_DIFF_FIND_DONT_IGNORE_WHITESPACE);
+}
diff --git a/tests/fetchhead/nonetwork.c b/tests/fetchhead/nonetwork.c
index 489481826..2d6d53eb6 100644
--- a/tests/fetchhead/nonetwork.c
+++ b/tests/fetchhead/nonetwork.c
@@ -335,7 +335,7 @@ void test_fetchhead_nonetwork__unborn_with_upstream(void)
cl_git_pass(git_remote_set_url(remote, cl_fixture("testrepo.git")));
cl_git_pass(git_remote_save(remote));
- cl_git_pass(git_remote_fetch(remote, NULL, NULL, NULL));
+ cl_git_pass(git_remote_fetch(remote, NULL, NULL));
git_remote_free(remote);
cl_git_pass(git_repository_fetchhead_foreach(repo, assert_master_for_merge, NULL));
diff --git a/tests/filter/file.c b/tests/filter/file.c
new file mode 100644
index 000000000..865c416c5
--- /dev/null
+++ b/tests/filter/file.c
@@ -0,0 +1,97 @@
+#include "clar_libgit2.h"
+#include "git2/sys/filter.h"
+#include "crlf.h"
+#include "buffer.h"
+
+static git_repository *g_repo = NULL;
+
+void test_filter_file__initialize(void)
+{
+ git_reference *head_ref;
+ git_commit *head;
+
+ g_repo = cl_git_sandbox_init("crlf");
+
+ cl_git_mkfile("crlf/.gitattributes",
+ "*.txt text\n*.bin binary\n*.crlf text eol=crlf\n*.lf text eol=lf\n");
+
+ cl_repo_set_bool(g_repo, "core.autocrlf", true);
+
+ cl_git_pass(git_repository_head(&head_ref, g_repo));
+ cl_git_pass(git_reference_peel((git_object **)&head, head_ref, GIT_OBJ_COMMIT));
+ cl_git_pass(git_reset(g_repo, (git_object *)head, GIT_RESET_HARD, NULL));
+
+ git_commit_free(head);
+ git_reference_free(head_ref);
+}
+
+void test_filter_file__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+void test_filter_file__apply(void)
+{
+ git_filter_list *fl;
+ git_filter *crlf;
+ git_buf buf = GIT_BUF_INIT;
+
+ cl_git_pass(git_filter_list_new(
+ &fl, g_repo, GIT_FILTER_TO_ODB, 0));
+
+ crlf = git_filter_lookup(GIT_FILTER_CRLF);
+ cl_assert(crlf != NULL);
+
+ cl_git_pass(git_filter_list_push(fl, crlf, NULL));
+
+ cl_git_pass(git_filter_list_apply_to_file(&buf, fl, g_repo, "all-crlf"));
+ cl_assert_equal_s("crlf\ncrlf\ncrlf\ncrlf\n", buf.ptr);
+
+ git_buf_free(&buf);
+ git_filter_list_free(fl);
+}
+
+struct buf_writestream {
+ git_writestream base;
+ git_buf buf;
+};
+
+int buf_writestream_write(git_writestream *s, const char *buf, size_t len)
+{
+ struct buf_writestream *stream = (struct buf_writestream *)s;
+ return git_buf_put(&stream->buf, buf, len);
+}
+
+int buf_writestream_close(git_writestream *s)
+{
+ return 0;
+}
+
+void buf_writestream_free(git_writestream *s)
+{
+ struct buf_writestream *stream = (struct buf_writestream *)s;
+ git_buf_free(&stream->buf);
+}
+
+void test_filter_file__apply_stream(void)
+{
+ git_filter_list *fl;
+ git_filter *crlf;
+ struct buf_writestream write_target = { {
+ buf_writestream_write,
+ buf_writestream_close,
+ buf_writestream_free } };
+
+ cl_git_pass(git_filter_list_new(
+ &fl, g_repo, GIT_FILTER_TO_ODB, 0));
+
+ crlf = git_filter_lookup(GIT_FILTER_CRLF);
+ cl_assert(crlf != NULL);
+
+ cl_git_pass(git_filter_list_push(fl, crlf, NULL));
+
+ cl_git_pass(git_filter_list_stream_file(fl, g_repo, "all-crlf", (git_writestream *)&write_target));
+ cl_assert_equal_s("crlf\ncrlf\ncrlf\ncrlf\n", write_target.buf.ptr);
+
+ git_filter_list_free(fl);
+}
diff --git a/tests/index/names.c b/tests/index/names.c
index c7619ed13..d462088b2 100644
--- a/tests/index/names.c
+++ b/tests/index/names.c
@@ -89,7 +89,7 @@ void test_index_names__cleaned_on_reset_hard(void)
cl_git_pass(git_revparse_single(&target, repo, "3a34580"));
test_index_names__add();
- cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
cl_assert(git_index_name_entrycount(repo_index) == 0);
git_object_free(target);
@@ -102,7 +102,7 @@ void test_index_names__cleaned_on_reset_mixed(void)
cl_git_pass(git_revparse_single(&target, repo, "3a34580"));
test_index_names__add();
- cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL));
cl_assert(git_index_name_entrycount(repo_index) == 0);
git_object_free(target);
diff --git a/tests/index/reuc.c b/tests/index/reuc.c
index 0b948a29e..e57facc0c 100644
--- a/tests/index/reuc.c
+++ b/tests/index/reuc.c
@@ -298,7 +298,7 @@ void test_index_reuc__cleaned_on_reset_hard(void)
cl_git_pass(git_revparse_single(&target, repo, "3a34580"));
test_index_reuc__add();
- cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
cl_assert(reuc_entry_exists() == false);
git_object_free(target);
@@ -311,7 +311,7 @@ void test_index_reuc__cleaned_on_reset_mixed(void)
cl_git_pass(git_revparse_single(&target, repo, "3a34580"));
test_index_reuc__add();
- cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL));
cl_assert(reuc_entry_exists() == false);
git_object_free(target);
@@ -323,10 +323,10 @@ void test_index_reuc__retained_on_reset_soft(void)
cl_git_pass(git_revparse_single(&target, repo, "3a34580"));
- git_reset(repo, target, GIT_RESET_HARD, NULL, NULL, NULL);
+ cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
test_index_reuc__add();
- cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT, NULL));
cl_assert(reuc_entry_exists() == true);
git_object_free(target);
diff --git a/tests/main.c b/tests/main.c
index a092b8ba4..f67c8ffbc 100644
--- a/tests/main.c
+++ b/tests/main.c
@@ -1,4 +1,5 @@
#include "clar_libgit2.h"
+#include "clar_libgit2_trace.h"
#ifdef _WIN32
int __cdecl main(int argc, char *argv[])
@@ -11,6 +12,7 @@ int main(int argc, char *argv[])
clar_test_init(argc, argv);
git_libgit2_init();
+ cl_global_trace_register();
cl_sandbox_set_search_path_defaults();
/* Run the test suite */
@@ -18,7 +20,7 @@ int main(int argc, char *argv[])
clar_test_shutdown();
- giterr_clear();
+ cl_global_trace_disable();
git_libgit2_shutdown();
return res;
diff --git a/tests/merge/merge_helpers.c b/tests/merge/merge_helpers.c
index 9a6ead984..33710f403 100644
--- a/tests/merge/merge_helpers.c
+++ b/tests/merge/merge_helpers.c
@@ -90,7 +90,7 @@ int merge_branches(git_repository *repo,
head_checkout_opts.checkout_strategy = GIT_CHECKOUT_FORCE;
- cl_git_pass(git_reference_symbolic_create(&head_ref, repo, "HEAD", ours_branch, 1, NULL, NULL));
+ cl_git_pass(git_reference_symbolic_create(&head_ref, repo, "HEAD", ours_branch, 1, NULL));
cl_git_pass(git_checkout_head(repo, &head_checkout_opts));
cl_git_pass(git_reference_lookup(&theirs_ref, repo, theirs_branch));
diff --git a/tests/merge/workdir/dirty.c b/tests/merge/workdir/dirty.c
index 4b68b213b..b66225d1f 100644
--- a/tests/merge/workdir/dirty.c
+++ b/tests/merge/workdir/dirty.c
@@ -182,7 +182,7 @@ static void stage_content(char *content[])
cl_git_pass(git_repository_head(&head, repo));
cl_git_pass(git_reference_peel(&head_object, head, GIT_OBJ_COMMIT));
- cl_git_pass(git_reset(repo, head_object, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, head_object, GIT_RESET_HARD, NULL));
for (i = 0, filename = content[i], text = content[++i];
filename && text;
@@ -209,7 +209,7 @@ static int merge_dirty_files(char *dirty_files[])
cl_git_pass(git_repository_head(&head, repo));
cl_git_pass(git_reference_peel(&head_object, head, GIT_OBJ_COMMIT));
- cl_git_pass(git_reset(repo, head_object, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, head_object, GIT_RESET_HARD, NULL));
write_files(dirty_files);
@@ -229,7 +229,7 @@ static int merge_differently_filtered_files(char *files[])
cl_git_pass(git_repository_head(&head, repo));
cl_git_pass(git_reference_peel(&head_object, head, GIT_OBJ_COMMIT));
- cl_git_pass(git_reset(repo, head_object, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, head_object, GIT_RESET_HARD, NULL));
write_files(files);
hack_index(files);
@@ -266,7 +266,7 @@ void test_merge_workdir_dirty__unstaged_deletes_maintained(void)
cl_git_pass(git_repository_head(&head, repo));
cl_git_pass(git_reference_peel(&head_object, head, GIT_OBJ_COMMIT));
- cl_git_pass(git_reset(repo, head_object, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, head_object, GIT_RESET_HARD, NULL));
cl_git_pass(p_unlink("merge-resolve/unchanged.txt"));
diff --git a/tests/merge/workdir/simple.c b/tests/merge/workdir/simple.c
index 4019e0077..abc0777f7 100644
--- a/tests/merge/workdir/simple.c
+++ b/tests/merge/workdir/simple.c
@@ -521,10 +521,10 @@ void test_merge_workdir_simple__directory_file(void)
{ 0100644, "f5504f36e6f4eb797a56fc5bac6c6c7f32969bf2", 3, "file-5/new" },
};
- cl_git_pass(git_reference_symbolic_create(&head, repo, GIT_HEAD_FILE, GIT_REFS_HEADS_DIR OURS_DIRECTORY_FILE, 1, NULL, NULL));
+ cl_git_pass(git_reference_symbolic_create(&head, repo, GIT_HEAD_FILE, GIT_REFS_HEADS_DIR OURS_DIRECTORY_FILE, 1, NULL));
cl_git_pass(git_reference_name_to_id(&head_commit_id, repo, GIT_HEAD_FILE));
cl_git_pass(git_commit_lookup(&head_commit, repo, &head_commit_id));
- cl_git_pass(git_reset(repo, (git_object *)head_commit, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, (git_object *)head_commit, GIT_RESET_HARD, NULL));
cl_git_pass(git_oid_fromstr(&their_oids[0], THEIRS_DIRECTORY_FILE));
cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &their_oids[0]));
@@ -616,7 +616,7 @@ void test_merge_workdir_simple__binary(void)
cl_git_pass(git_oid_fromstr(&their_oid, "ad01aebfdf2ac13145efafe3f9fcf798882f1730"));
cl_git_pass(git_commit_lookup(&our_commit, repo, &our_oid));
- cl_git_pass(git_reset(repo, (git_object *)our_commit, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, (git_object *)our_commit, GIT_RESET_HARD, NULL));
cl_git_pass(git_annotated_commit_lookup(&their_head, repo, &their_oid));
diff --git a/tests/merge/workdir/submodules.c b/tests/merge/workdir/submodules.c
index 31ded4662..7c18c2ffb 100644
--- a/tests/merge/workdir/submodules.c
+++ b/tests/merge/workdir/submodules.c
@@ -44,7 +44,7 @@ void test_merge_workdir_submodules__automerge(void)
cl_git_pass(git_reference_lookup(&our_ref, repo, "refs/heads/" SUBMODULE_MAIN_BRANCH));
cl_git_pass(git_commit_lookup(&our_commit, repo, git_reference_target(our_ref)));
- cl_git_pass(git_reset(repo, (git_object *)our_commit, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, (git_object *)our_commit, GIT_RESET_HARD, NULL));
cl_git_pass(git_reference_lookup(&their_ref, repo, "refs/heads/" SUBMODULE_OTHER_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_head, repo, their_ref));
@@ -77,7 +77,7 @@ void test_merge_workdir_submodules__take_changed(void)
cl_git_pass(git_reference_lookup(&our_ref, repo, "refs/heads/" SUBMODULE_MAIN_BRANCH));
cl_git_pass(git_commit_lookup(&our_commit, repo, git_reference_target(our_ref)));
- cl_git_pass(git_reset(repo, (git_object *)our_commit, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, (git_object *)our_commit, GIT_RESET_HARD, NULL));
cl_git_pass(git_reference_lookup(&their_ref, repo, "refs/heads/" SUBMODULE_OTHER2_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_head, repo, their_ref));
diff --git a/tests/merge/workdir/trivial.c b/tests/merge/workdir/trivial.c
index fa261c3a1..5cc20f746 100644
--- a/tests/merge/workdir/trivial.c
+++ b/tests/merge/workdir/trivial.c
@@ -38,7 +38,7 @@ static int merge_trivial(const char *ours, const char *theirs)
checkout_opts.checkout_strategy = GIT_CHECKOUT_FORCE;
git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, ours);
- cl_git_pass(git_reference_symbolic_create(&our_ref, repo, "HEAD", branch_buf.ptr, 1, NULL, NULL));
+ cl_git_pass(git_reference_symbolic_create(&our_ref, repo, "HEAD", branch_buf.ptr, 1, NULL));
cl_git_pass(git_checkout_head(repo, &checkout_opts));
diff --git a/tests/network/fetchlocal.c b/tests/network/fetchlocal.c
index af1922672..13b3cf07c 100644
--- a/tests/network/fetchlocal.c
+++ b/tests/network/fetchlocal.c
@@ -46,7 +46,7 @@ void test_network_fetchlocal__complete(void)
git_remote_set_callbacks(origin, &callbacks);
cl_git_pass(git_remote_connect(origin, GIT_DIRECTION_FETCH));
cl_git_pass(git_remote_download(origin, NULL));
- cl_git_pass(git_remote_update_tips(origin, NULL, NULL));
+ cl_git_pass(git_remote_update_tips(origin, NULL));
cl_git_pass(git_reference_list(&refnames, repo));
cl_assert_equal_i(19, (int)refnames.count);
@@ -76,7 +76,7 @@ void test_network_fetchlocal__prune(void)
cl_git_pass(git_remote_create(&origin, repo, GIT_REMOTE_ORIGIN, url));
git_remote_set_callbacks(origin, &callbacks);
- cl_git_pass(git_remote_fetch(origin, NULL, NULL, NULL));
+ cl_git_pass(git_remote_fetch(origin, NULL, NULL));
cl_git_pass(git_reference_list(&refnames, repo));
cl_assert_equal_i(19, (int)refnames.count);
@@ -93,7 +93,7 @@ void test_network_fetchlocal__prune(void)
cl_git_pass(git_remote_connect(origin, GIT_DIRECTION_FETCH));
cl_git_pass(git_remote_download(origin, NULL));
cl_git_pass(git_remote_prune(origin));
- cl_git_pass(git_remote_update_tips(origin, NULL, NULL));
+ cl_git_pass(git_remote_update_tips(origin, NULL));
cl_git_pass(git_reference_list(&refnames, repo));
cl_assert_equal_i(18, (int)refnames.count);
@@ -109,7 +109,7 @@ void test_network_fetchlocal__prune(void)
cl_git_pass(git_remote_connect(origin, GIT_DIRECTION_FETCH));
cl_git_pass(git_remote_download(origin, NULL));
cl_git_pass(git_remote_prune(origin));
- cl_git_pass(git_remote_update_tips(origin, NULL, NULL));
+ cl_git_pass(git_remote_update_tips(origin, NULL));
cl_git_pass(git_reference_list(&refnames, repo));
cl_assert_equal_i(17, (int)refnames.count);
@@ -158,7 +158,7 @@ void test_network_fetchlocal__prune_overlapping(void)
cl_git_pass(git_reference_lookup(&ref, remote_repo, "refs/heads/master"));
git_oid_cpy(&target, git_reference_target(ref));
git_reference_free(ref);
- cl_git_pass(git_reference_create(&ref, remote_repo, "refs/pull/42/head", &target, 1, NULL, NULL));
+ cl_git_pass(git_reference_create(&ref, remote_repo, "refs/pull/42/head", &target, 1, NULL));
git_reference_free(ref);
cl_set_cleanup(&cleanup_local_repo, "foo");
@@ -174,7 +174,7 @@ void test_network_fetchlocal__prune_overlapping(void)
git_remote_free(origin);
cl_git_pass(git_remote_lookup(&origin, repo, GIT_REMOTE_ORIGIN));
git_remote_set_callbacks(origin, &callbacks);
- cl_git_pass(git_remote_fetch(origin, NULL, NULL, NULL));
+ cl_git_pass(git_remote_fetch(origin, NULL, NULL));
assert_ref_exists(repo, "refs/remotes/origin/master");
assert_ref_exists(repo, "refs/remotes/origin/pr/42");
@@ -190,7 +190,7 @@ void test_network_fetchlocal__prune_overlapping(void)
cl_git_pass(git_remote_lookup(&origin, repo, GIT_REMOTE_ORIGIN));
callbacks.update_tips = update_tips_fail_on_call;
git_remote_set_callbacks(origin, &callbacks);
- cl_git_pass(git_remote_fetch(origin, NULL, NULL, NULL));
+ cl_git_pass(git_remote_fetch(origin, NULL, NULL));
assert_ref_exists(repo, "refs/remotes/origin/master");
assert_ref_exists(repo, "refs/remotes/origin/pr/42");
@@ -206,7 +206,7 @@ void test_network_fetchlocal__prune_overlapping(void)
cl_git_pass(git_remote_lookup(&origin, repo, GIT_REMOTE_ORIGIN));
callbacks.update_tips = update_tips_fail_on_call;
git_remote_set_callbacks(origin, &callbacks);
- cl_git_pass(git_remote_fetch(origin, NULL, NULL, NULL));
+ cl_git_pass(git_remote_fetch(origin, NULL, NULL));
git_config_free(config);
git_strarray_free(&refnames);
@@ -234,7 +234,7 @@ void test_network_fetchlocal__fetchprune(void)
cl_git_pass(git_remote_create(&origin, repo, GIT_REMOTE_ORIGIN, url));
git_remote_set_callbacks(origin, &callbacks);
- cl_git_pass(git_remote_fetch(origin, NULL, NULL, NULL));
+ cl_git_pass(git_remote_fetch(origin, NULL, NULL));
cl_git_pass(git_reference_list(&refnames, repo));
cl_assert_equal_i(19, (int)refnames.count);
@@ -248,7 +248,7 @@ void test_network_fetchlocal__fetchprune(void)
cl_git_pass(git_remote_lookup(&origin, repo, GIT_REMOTE_ORIGIN));
git_remote_set_callbacks(origin, &callbacks);
- cl_git_pass(git_remote_fetch(origin, NULL, NULL, NULL));
+ cl_git_pass(git_remote_fetch(origin, NULL, NULL));
cl_git_pass(git_remote_prune(origin));
cl_git_pass(git_reference_list(&refnames, repo));
@@ -266,7 +266,7 @@ void test_network_fetchlocal__fetchprune(void)
cl_git_pass(git_remote_lookup(&origin, repo, GIT_REMOTE_ORIGIN));
cl_assert_equal_i(1, git_remote_prune_refs(origin));
git_remote_set_callbacks(origin, &callbacks);
- cl_git_pass(git_remote_fetch(origin, NULL, NULL, NULL));
+ cl_git_pass(git_remote_fetch(origin, NULL, NULL));
cl_git_pass(git_reference_list(&refnames, repo));
cl_assert_equal_i(17, (int)refnames.count);
@@ -299,12 +299,12 @@ void test_network_fetchlocal__prune_tag(void)
cl_git_pass(git_remote_create(&origin, repo, GIT_REMOTE_ORIGIN, url));
git_remote_set_callbacks(origin, &callbacks);
- cl_git_pass(git_remote_fetch(origin, NULL, NULL, NULL));
+ cl_git_pass(git_remote_fetch(origin, NULL, NULL));
git_remote_free(origin);
cl_git_pass(git_revparse_single(&obj, repo, "origin/master"));
- cl_git_pass(git_reference_create(&ref, repo, "refs/remotes/origin/fake-remote", git_object_id(obj), 1, NULL, NULL));
+ cl_git_pass(git_reference_create(&ref, repo, "refs/remotes/origin/fake-remote", git_object_id(obj), 1, NULL));
git_reference_free(ref);
/* create signature */
@@ -322,7 +322,7 @@ void test_network_fetchlocal__prune_tag(void)
cl_git_pass(git_remote_lookup(&origin, repo, GIT_REMOTE_ORIGIN));
cl_assert_equal_i(1, git_remote_prune_refs(origin));
git_remote_set_callbacks(origin, &callbacks);
- cl_git_pass(git_remote_fetch(origin, NULL, NULL, NULL));
+ cl_git_pass(git_remote_fetch(origin, NULL, NULL));
assert_ref_exists(repo, "refs/tags/some-tag");
cl_git_fail_with(GIT_ENOTFOUND, git_reference_lookup(&ref, repo, "refs/remotes/origin/fake-remote"));
@@ -360,7 +360,7 @@ void test_network_fetchlocal__partial(void)
git_remote_set_callbacks(origin, &callbacks);
cl_git_pass(git_remote_connect(origin, GIT_DIRECTION_FETCH));
cl_git_pass(git_remote_download(origin, NULL));
- cl_git_pass(git_remote_update_tips(origin, NULL, NULL));
+ cl_git_pass(git_remote_update_tips(origin, NULL));
git_strarray_free(&refnames);
@@ -427,7 +427,7 @@ void test_network_fetchlocal__multi_remotes(void)
git_remote_set_callbacks(test, &callbacks);
cl_git_pass(git_remote_connect(test, GIT_DIRECTION_FETCH));
cl_git_pass(git_remote_download(test, NULL));
- cl_git_pass(git_remote_update_tips(test, NULL, NULL));
+ cl_git_pass(git_remote_update_tips(test, NULL));
cl_git_pass(git_reference_list(&refnames, repo));
cl_assert_equal_i(32, (int)refnames.count);
@@ -438,7 +438,7 @@ void test_network_fetchlocal__multi_remotes(void)
git_remote_set_callbacks(test2, &callbacks);
cl_git_pass(git_remote_connect(test2, GIT_DIRECTION_FETCH));
cl_git_pass(git_remote_download(test2, NULL));
- cl_git_pass(git_remote_update_tips(test2, NULL, NULL));
+ cl_git_pass(git_remote_update_tips(test2, NULL));
cl_git_pass(git_reference_list(&refnames, repo));
cl_assert_equal_i(44, (int)refnames.count);
@@ -475,7 +475,7 @@ void test_network_fetchlocal__call_progress(void)
callbacks.payload = &callcount;
cl_git_pass(git_remote_set_callbacks(remote, &callbacks));
- cl_git_pass(git_remote_fetch(remote, NULL, NULL, NULL));
+ cl_git_pass(git_remote_fetch(remote, NULL, NULL));
cl_assert(callcount != 0);
git_remote_free(remote);
diff --git a/tests/network/remote/defaultbranch.c b/tests/network/remote/defaultbranch.c
index 243369fa2..c83d5c8b0 100644
--- a/tests/network/remote/defaultbranch.c
+++ b/tests/network/remote/defaultbranch.c
@@ -39,13 +39,13 @@ void test_network_remote_defaultbranch__master(void)
void test_network_remote_defaultbranch__master_does_not_win(void)
{
- cl_git_pass(git_repository_set_head(g_repo_a, "refs/heads/not-good", NULL, NULL));
+ cl_git_pass(git_repository_set_head(g_repo_a, "refs/heads/not-good"));
assert_default_branch("refs/heads/not-good");
}
void test_network_remote_defaultbranch__master_on_detached(void)
{
- cl_git_pass(git_repository_detach_head(g_repo_a, NULL, NULL));
+ cl_git_pass(git_repository_detach_head(g_repo_a));
assert_default_branch("refs/heads/master");
}
@@ -74,10 +74,10 @@ void test_network_remote_defaultbranch__detached_sharing_nonbranch_id(void)
git_repository *cloned_repo;
cl_git_pass(git_reference_name_to_id(&id, g_repo_a, "HEAD"));
- cl_git_pass(git_repository_detach_head(g_repo_a, NULL, NULL));
+ cl_git_pass(git_repository_detach_head(g_repo_a));
cl_git_pass(git_reference_remove(g_repo_a, "refs/heads/master"));
cl_git_pass(git_reference_remove(g_repo_a, "refs/heads/not-good"));
- cl_git_pass(git_reference_create(&ref, g_repo_a, "refs/foo/bar", &id, 1, NULL, NULL));
+ cl_git_pass(git_reference_create(&ref, g_repo_a, "refs/foo/bar", &id, 1, NULL));
git_reference_free(ref);
cl_git_pass(git_remote_connect(g_remote, GIT_DIRECTION_FETCH));
@@ -97,7 +97,7 @@ void test_network_remote_defaultbranch__unborn_HEAD_with_branches(void)
git_reference *ref;
git_repository *cloned_repo;
- cl_git_pass(git_reference_symbolic_create(&ref, g_repo_a, "HEAD", "refs/heads/i-dont-exist", 1, NULL, NULL));
+ cl_git_pass(git_reference_symbolic_create(&ref, g_repo_a, "HEAD", "refs/heads/i-dont-exist", 1, NULL));
git_reference_free(ref);
cl_git_pass(git_clone(&cloned_repo, git_repository_path(g_repo_a), "./semi-empty", NULL));
diff --git a/tests/network/remote/local.c b/tests/network/remote/local.c
index 55453061b..ba54de6af 100644
--- a/tests/network/remote/local.c
+++ b/tests/network/remote/local.c
@@ -18,6 +18,7 @@ static git_strarray push_array = {
void test_network_remote_local__initialize(void)
{
cl_git_pass(git_repository_init(&repo, "remotelocal/", 0));
+ cl_git_pass(git_repository_set_ident(repo, "Foo Bar", "foo@example.com"));
cl_assert(repo != NULL);
}
@@ -138,7 +139,7 @@ void test_network_remote_local__shorthand_fetch_refspec0(void)
connect_to_local_repository(cl_fixture("testrepo.git"));
cl_git_pass(git_remote_download(remote, &array));
- cl_git_pass(git_remote_update_tips(remote, NULL, NULL));
+ cl_git_pass(git_remote_update_tips(remote, NULL));
cl_git_pass(git_reference_lookup(&ref, repo, "refs/remotes/sloppy/master"));
git_reference_free(ref);
@@ -164,7 +165,7 @@ void test_network_remote_local__shorthand_fetch_refspec1(void)
git_remote_clear_refspecs(remote);
cl_git_pass(git_remote_download(remote, &array));
- cl_git_pass(git_remote_update_tips(remote, NULL, NULL));
+ cl_git_pass(git_remote_update_tips(remote, NULL));
cl_git_fail(git_reference_lookup(&ref, repo, "refs/remotes/master"));
@@ -177,7 +178,7 @@ void test_network_remote_local__tagopt(void)
cl_git_pass(git_remote_create(&remote, repo, "tagopt", cl_git_path_url(cl_fixture("testrepo.git"))));
git_remote_set_autotag(remote, GIT_REMOTE_DOWNLOAD_TAGS_ALL);
- cl_git_pass(git_remote_fetch(remote, NULL, NULL, NULL));
+ cl_git_pass(git_remote_fetch(remote, NULL, NULL));
cl_git_pass(git_reference_lookup(&ref, repo, "refs/remotes/tagopt/master"));
git_reference_free(ref);
@@ -185,7 +186,7 @@ void test_network_remote_local__tagopt(void)
git_reference_free(ref);
git_remote_set_autotag(remote, GIT_REMOTE_DOWNLOAD_TAGS_AUTO);
- cl_git_pass(git_remote_fetch(remote, NULL, NULL, NULL));
+ cl_git_pass(git_remote_fetch(remote, NULL, NULL));
cl_git_pass(git_reference_lookup(&ref, repo, "refs/remotes/tagopt/master"));
git_reference_free(ref);
}
@@ -206,7 +207,7 @@ void test_network_remote_local__push_to_bare_remote(void)
/* Get some commits */
connect_to_local_repository(cl_fixture("testrepo.git"));
cl_git_pass(git_remote_download(remote, &array));
- cl_git_pass(git_remote_update_tips(remote, NULL, NULL));
+ cl_git_pass(git_remote_update_tips(remote, NULL));
git_remote_disconnect(remote);
/* Set up an empty bare repo to push into */
@@ -244,7 +245,7 @@ void test_network_remote_local__push_to_bare_remote_with_file_url(void)
/* Get some commits */
connect_to_local_repository(cl_fixture("testrepo.git"));
cl_git_pass(git_remote_download(remote, &array));
- cl_git_pass(git_remote_update_tips(remote, NULL, NULL));
+ cl_git_pass(git_remote_update_tips(remote, NULL));
git_remote_disconnect(remote);
/* Set up an empty bare repo to push into */
@@ -285,7 +286,7 @@ void test_network_remote_local__push_to_non_bare_remote(void)
/* Get some commits */
connect_to_local_repository(cl_fixture("testrepo.git"));
cl_git_pass(git_remote_download(remote, &array));
- cl_git_pass(git_remote_update_tips(remote, NULL, NULL));
+ cl_git_pass(git_remote_update_tips(remote, NULL));
git_remote_disconnect(remote);
/* Set up an empty non-bare repo to push into */
@@ -319,14 +320,11 @@ void test_network_remote_local__fetch(void)
git_reflog *log;
const git_reflog_entry *entry;
- git_signature *sig;
git_reference *ref;
- cl_git_pass(git_signature_now(&sig, "Foo Bar", "foo@example.com"));
-
connect_to_local_repository(cl_fixture("testrepo.git"));
- cl_git_pass(git_remote_fetch(remote, &array, sig, "UPDAAAAAATE!!"));
+ cl_git_pass(git_remote_fetch(remote, &array, "UPDAAAAAATE!!"));
cl_git_pass(git_reference_lookup(&ref, repo, "refs/remotes/sloppy/master"));
git_reference_free(ref);
@@ -338,7 +336,6 @@ void test_network_remote_local__fetch(void)
cl_assert_equal_s("UPDAAAAAATE!!", git_reflog_entry_message(entry));
git_reflog_free(log);
- git_signature_free(sig);
}
void test_network_remote_local__reflog(void)
@@ -353,14 +350,11 @@ void test_network_remote_local__reflog(void)
git_reflog *log;
const git_reflog_entry *entry;
- git_signature *sig;
-
- cl_git_pass(git_signature_now(&sig, "Foo Bar", "foo@example.com"));
connect_to_local_repository(cl_fixture("testrepo.git"));
cl_git_pass(git_remote_download(remote, &array));
- cl_git_pass(git_remote_update_tips(remote, sig, "UPDAAAAAATE!!"));
+ cl_git_pass(git_remote_update_tips(remote, "UPDAAAAAATE!!"));
cl_git_pass(git_reflog_read(&log, repo, "refs/remotes/sloppy/master"));
cl_assert_equal_i(1, git_reflog_entrycount(log));
@@ -369,7 +363,6 @@ void test_network_remote_local__reflog(void)
cl_assert_equal_s("UPDAAAAAATE!!", git_reflog_entry_message(entry));
git_reflog_free(log);
- git_signature_free(sig);
}
void test_network_remote_local__fetch_default_reflog_message(void)
@@ -384,14 +377,11 @@ void test_network_remote_local__fetch_default_reflog_message(void)
git_reflog *log;
const git_reflog_entry *entry;
- git_signature *sig;
char expected_reflog_msg[1024];
- cl_git_pass(git_signature_now(&sig, "Foo Bar", "foo@example.com"));
-
connect_to_local_repository(cl_fixture("testrepo.git"));
- cl_git_pass(git_remote_fetch(remote, &array, sig, NULL));
+ cl_git_pass(git_remote_fetch(remote, &array, NULL));
cl_git_pass(git_reflog_read(&log, repo, "refs/remotes/sloppy/master"));
cl_assert_equal_i(1, git_reflog_entrycount(log));
@@ -402,7 +392,6 @@ void test_network_remote_local__fetch_default_reflog_message(void)
cl_assert_equal_s(expected_reflog_msg, git_reflog_entry_message(entry));
git_reflog_free(log);
- git_signature_free(sig);
}
void test_network_remote_local__opportunistic_update(void)
@@ -419,7 +408,7 @@ void test_network_remote_local__opportunistic_update(void)
/* this remote has a passive refspec of "refs/heads/<star>:refs/remotes/origin/<star>" */
cl_git_pass(git_remote_create(&remote, repo, "origin", cl_git_fixture_url("testrepo.git")));
/* and we pass the active refspec "master" */
- cl_git_pass(git_remote_fetch(remote, &array, NULL, NULL));
+ cl_git_pass(git_remote_fetch(remote, &array, NULL));
/* and we expect that to update our copy of origin's master */
cl_git_pass(git_reference_lookup(&ref, repo, "refs/remotes/origin/master"));
@@ -445,7 +434,7 @@ void test_network_remote_local__update_tips_for_new_remote(void) {
cl_git_pass(git_remote_upload(new_remote, &push_array, NULL));
/* Update tips and make sure remote branch has been created */
- cl_git_pass(git_remote_update_tips(new_remote, NULL, NULL));
+ cl_git_pass(git_remote_update_tips(new_remote, NULL));
cl_git_pass(git_branch_lookup(&branch, src_repo, "bare/master", GIT_BRANCH_REMOTE));
git_reference_free(branch);
@@ -475,12 +464,12 @@ void test_network_remote_local__push_delete(void)
cl_git_pass(git_remote_create(&remote, src_repo, "origin", "./target.git"));
/* Push the master branch and verify it's there */
- cl_git_pass(git_remote_push(remote, &specs, NULL, NULL, NULL));
+ cl_git_pass(git_remote_push(remote, &specs, NULL));
cl_git_pass(git_reference_lookup(&ref, dst_repo, "refs/heads/master"));
git_reference_free(ref);
specs.strings = spec_delete;
- cl_git_pass(git_remote_push(remote, &specs, NULL, NULL, NULL));
+ cl_git_pass(git_remote_push(remote, &specs, NULL));
cl_git_fail(git_reference_lookup(&ref, dst_repo, "refs/heads/master"));
git_remote_free(remote);
diff --git a/tests/network/remote/remotes.c b/tests/network/remote/remotes.c
index 995f1d541..e750f7b1e 100644
--- a/tests/network/remote/remotes.c
+++ b/tests/network/remote/remotes.c
@@ -1,4 +1,5 @@
#include "clar_libgit2.h"
+#include "config/config_helpers.h"
#include "buffer.h"
#include "refspec.h"
#include "remote.h"
@@ -272,7 +273,7 @@ void test_network_remote_remotes__nonmatch_upstream_refspec(void)
cl_git_pass(git_config_set_string(config, "branch.master.remote", "taggy"));
cl_git_pass(git_config_set_string(config, "branch.master.merge", "refs/heads/foo"));
- cl_git_pass(git_remote_fetch(remote, &specs, NULL, NULL));
+ cl_git_pass(git_remote_fetch(remote, &specs, NULL));
git_remote_free(remote);
}
@@ -385,26 +386,17 @@ void test_network_remote_remotes__cannot_add_a_remote_with_an_invalid_name(void)
void test_network_remote_remotes__tagopt(void)
{
- const char *opt;
- git_config *cfg;
-
- cl_git_pass(git_repository_config(&cfg, _repo));
-
git_remote_set_autotag(_remote, GIT_REMOTE_DOWNLOAD_TAGS_ALL);
cl_git_pass(git_remote_save(_remote));
- cl_git_pass(git_config_get_string(&opt, cfg, "remote.test.tagopt"));
- cl_assert_equal_s("--tags", opt);
+ assert_config_entry_value(_repo, "remote.test.tagopt", "--tags");
git_remote_set_autotag(_remote, GIT_REMOTE_DOWNLOAD_TAGS_NONE);
cl_git_pass(git_remote_save(_remote));
- cl_git_pass(git_config_get_string(&opt, cfg, "remote.test.tagopt"));
- cl_assert_equal_s("--no-tags", opt);
+ assert_config_entry_value(_repo, "remote.test.tagopt", "--no-tags");
git_remote_set_autotag(_remote, GIT_REMOTE_DOWNLOAD_TAGS_AUTO);
cl_git_pass(git_remote_save(_remote));
- cl_assert(git_config_get_string(&opt, cfg, "remote.test.tagopt") == GIT_ENOTFOUND);
-
- git_config_free(cfg);
+ assert_config_entry_existence(_repo, "remote.test.tagopt", false);
}
void test_network_remote_remotes__can_load_with_an_empty_url(void)
@@ -545,7 +537,7 @@ void test_network_remote_remotes__fetch_from_anonymous(void)
cl_git_pass(git_remote_create_anonymous(&remote, _repo, cl_fixture("testrepo.git"),
"refs/heads/*:refs/other/*"));
- cl_git_pass(git_remote_fetch(remote, NULL, NULL, NULL));
+ cl_git_pass(git_remote_fetch(remote, NULL, NULL));
git_remote_free(remote);
}
diff --git a/tests/network/remote/rename.c b/tests/network/remote/rename.c
index 1dabd07f5..b44a0ae71 100644
--- a/tests/network/remote/rename.c
+++ b/tests/network/remote/rename.c
@@ -181,7 +181,7 @@ void test_network_remote_rename__overwrite_ref_in_target(void)
git_strarray problems = {0};
cl_git_pass(git_oid_fromstr(&id, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"));
- cl_git_pass(git_reference_create(&ref, _repo, "refs/remotes/renamed/master", &id, 1, NULL, NULL));
+ cl_git_pass(git_reference_create(&ref, _repo, "refs/remotes/renamed/master", &id, 1, NULL));
git_reference_free(ref);
cl_git_pass(git_remote_rename(&problems, _repo, _remote_name, "renamed"));
@@ -219,7 +219,7 @@ void test_network_remote_rename__symref_head(void)
char idstr[GIT_OID_HEXSZ + 1] = {0};
git_vector refs;
- cl_git_pass(git_reference_symbolic_create(&ref, _repo, "refs/remotes/test/HEAD", "refs/remotes/test/master", 0, NULL, NULL));
+ cl_git_pass(git_reference_symbolic_create(&ref, _repo, "refs/remotes/test/HEAD", "refs/remotes/test/master", 0, NULL));
git_reference_free(ref);
cl_git_pass(git_remote_rename(&problems, _repo, _remote_name, "renamed"));
diff --git a/tests/online/clone.c b/tests/online/clone.c
index cae7b3338..3bb927955 100644
--- a/tests/online/clone.c
+++ b/tests/online/clone.c
@@ -104,7 +104,7 @@ void test_online_clone__can_checkout_a_cloned_repo(void)
bool checkout_progress_cb_was_called = false,
fetch_progress_cb_was_called = false;
- g_options.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ g_options.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
g_options.checkout_opts.progress_cb = &checkout_progress;
g_options.checkout_opts.progress_payload = &checkout_progress_cb_was_called;
g_options.remote_callbacks.transfer_progress = &fetch_progress;
diff --git a/tests/online/fetch.c b/tests/online/fetch.c
index 848b87410..fcbe24d5f 100644
--- a/tests/online/fetch.c
+++ b/tests/online/fetch.c
@@ -48,7 +48,7 @@ static void do_fetch(const char *url, git_remote_autotag_option_t flag, int n)
git_remote_set_autotag(remote, flag);
cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
cl_git_pass(git_remote_download(remote, NULL));
- cl_git_pass(git_remote_update_tips(remote, NULL, NULL));
+ cl_git_pass(git_remote_update_tips(remote, NULL));
git_remote_disconnect(remote);
cl_assert_equal_i(counter, n);
cl_assert(bytes_received > 0);
@@ -132,7 +132,7 @@ void test_online_fetch__doesnt_retrieve_a_pack_when_the_repository_is_up_to_date
cl_assert_equal_i(false, invoked);
- cl_git_pass(git_remote_update_tips(remote, NULL, NULL));
+ cl_git_pass(git_remote_update_tips(remote, NULL));
git_remote_disconnect(remote);
git_remote_free(remote);
@@ -208,8 +208,8 @@ void test_online_fetch__twice(void)
git_remote *remote;
cl_git_pass(git_remote_create(&remote, _repo, "test", "http://github.com/libgit2/TestGitRepository.git"));
- cl_git_pass(git_remote_fetch(remote, NULL, NULL, NULL));
- cl_git_pass(git_remote_fetch(remote, NULL, NULL, NULL));
+ cl_git_pass(git_remote_fetch(remote, NULL, NULL));
+ cl_git_pass(git_remote_fetch(remote, NULL, NULL));
git_remote_free(remote);
}
diff --git a/tests/online/fetchhead.c b/tests/online/fetchhead.c
index b0a80cd58..9a97abef3 100644
--- a/tests/online/fetchhead.c
+++ b/tests/online/fetchhead.c
@@ -53,7 +53,7 @@ static void fetchhead_test_fetch(const char *fetchspec, const char *expected_fet
cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
cl_git_pass(git_remote_download(remote, active_refs));
- cl_git_pass(git_remote_update_tips(remote, NULL, NULL));
+ cl_git_pass(git_remote_update_tips(remote, NULL));
git_remote_disconnect(remote);
git_remote_free(remote);
diff --git a/tests/online/push.c b/tests/online/push.c
index 1e30a1035..9b98bc77a 100644
--- a/tests/online/push.c
+++ b/tests/online/push.c
@@ -322,6 +322,7 @@ void test_online_push__initialize(void)
_repo = cl_git_sandbox_init("push_src");
+ cl_git_pass(git_repository_set_ident(_repo, "Random J. Hacker", "foo@example.com"));
cl_fixture_sandbox("testrepo.git");
cl_rename("push_src/submodule/.gitted", "push_src/submodule/.git");
@@ -395,7 +396,7 @@ void test_online_push__initialize(void)
/* Now that we've deleted everything, fetch from the remote */
cl_git_pass(git_remote_connect(_remote, GIT_DIRECTION_FETCH));
cl_git_pass(git_remote_download(_remote, NULL));
- cl_git_pass(git_remote_update_tips(_remote, NULL, NULL));
+ cl_git_pass(git_remote_update_tips(_remote, NULL));
git_remote_disconnect(_remote);
}
@@ -458,7 +459,6 @@ static void do_push(
size_t i;
int error;
git_strarray specs = {0};
- git_signature *pusher;
git_remote_callbacks callbacks;
record_callbacks_data *data;
@@ -466,8 +466,6 @@ static void do_push(
/* Auto-detect the number of threads to use */
opts.pb_parallelism = 0;
- cl_git_pass(git_signature_now(&pusher, "Foo Bar", "foo@example.com"));
-
memcpy(&callbacks, git_remote_get_callbacks(_remote), sizeof(callbacks));
data = callbacks.payload;
@@ -489,7 +487,7 @@ static void do_push(
if (check_progress_cb && expected_ret == GIT_EUSER)
data->transfer_progress_calls = GIT_EUSER;
- error = git_remote_push(_remote, &specs, &opts, pusher, "test push");
+ error = git_remote_push(_remote, &specs, &opts);
git__free(specs.strings);
if (expected_ret < 0) {
@@ -511,7 +509,6 @@ static void do_push(
if (check_update_tips_cb)
verify_update_tips_callback(_remote, expected_refs, expected_refs_len);
- git_signature_free(pusher);
}
}
@@ -611,7 +608,7 @@ void test_online_push__multi(void)
cl_git_pass(git_reflog_read(&log, _repo, "refs/remotes/test/b1"));
entry = git_reflog_entry_byindex(log, 0);
if (entry) {
- cl_assert_equal_s("test push", git_reflog_entry_message(entry));
+ cl_assert_equal_s("update by push", git_reflog_entry_message(entry));
cl_assert_equal_s("foo@example.com", git_reflog_entry_committer(entry)->email);
}
diff --git a/tests/perf/helper__perf__do_merge.c b/tests/perf/helper__perf__do_merge.c
index 00221851e..c77b46a1f 100644
--- a/tests/perf/helper__perf__do_merge.c
+++ b/tests/perf/helper__perf__do_merge.c
@@ -26,9 +26,8 @@ void perf__do_merge(const char *fixture,
perf__timer__start(&t_total);
- checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
clone_opts.checkout_opts = checkout_opts;
- cl_git_pass(git_signature_now(&clone_opts.signature, "Me", "foo@example.com"));
perf__timer__start(&t_clone);
cl_git_pass(git_clone(&g_repo, fixture, test_name, &clone_opts));
@@ -38,21 +37,19 @@ void perf__do_merge(const char *fixture,
cl_git_pass(git_commit_lookup(&commit_a, g_repo, &oid_a));
cl_git_pass(git_branch_create(&ref_branch_a, g_repo,
"A", commit_a,
- 0, NULL, NULL));
+ 0));
perf__timer__start(&t_checkout);
cl_git_pass(git_checkout_tree(g_repo, (git_object*)commit_a, &checkout_opts));
perf__timer__stop(&t_checkout);
- cl_git_pass(git_repository_set_head(g_repo,
- git_reference_name(ref_branch_a),
- NULL, NULL));
+ cl_git_pass(git_repository_set_head(g_repo, git_reference_name(ref_branch_a)));
git_oid_fromstr(&oid_b, id_b);
cl_git_pass(git_commit_lookup(&commit_b, g_repo, &oid_b));
cl_git_pass(git_branch_create(&ref_branch_b, g_repo,
"B", commit_b,
- 0, NULL, NULL));
+ 0));
cl_git_pass(git_annotated_commit_lookup(&annotated_commits[0], g_repo, &oid_b));
diff --git a/tests/rebase/abort.c b/tests/rebase/abort.c
index 71326433f..24af2d140 100644
--- a/tests/rebase/abort.c
+++ b/tests/rebase/abort.c
@@ -23,14 +23,12 @@ static void test_abort(git_annotated_commit *branch, git_annotated_commit *onto)
{
git_rebase *rebase;
git_reference *head_ref, *branch_ref = NULL;
- git_signature *signature;
git_status_list *statuslist;
git_reflog *reflog;
const git_reflog_entry *reflog_entry;
cl_git_pass(git_rebase_open(&rebase, repo));
- cl_git_pass(git_signature_new(&signature, "Rebaser", "rebaser@example.com", 1404157834, -400));
- cl_git_pass(git_rebase_abort(rebase, signature));
+ cl_git_pass(git_rebase_abort(rebase));
cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo));
@@ -60,7 +58,6 @@ static void test_abort(git_annotated_commit *branch, git_annotated_commit *onto)
git_reflog_free(reflog);
git_reference_free(head_ref);
git_reference_free(branch_ref);
- git_signature_free(signature);
git_rebase_free(rebase);
}
@@ -68,7 +65,6 @@ void test_rebase_abort__merge(void)
{
git_rebase *rebase;
git_reference *branch_ref, *onto_ref;
- git_signature *signature;
git_annotated_commit *branch_head, *onto_head;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef"));
@@ -77,15 +73,11 @@ void test_rebase_abort__merge(void)
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&onto_head, repo, onto_ref));
- cl_git_pass(git_signature_new(&signature, "Rebaser", "rebaser@example.com", 1404157834, -400));
-
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, signature, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
test_abort(branch_head, onto_head);
- git_signature_free(signature);
-
git_annotated_commit_free(branch_head);
git_annotated_commit_free(onto_head);
@@ -110,7 +102,7 @@ void test_rebase_abort__detached_head(void)
cl_git_pass(git_signature_new(&signature, "Rebaser", "rebaser@example.com", 1404157834, -400));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, signature, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
test_abort(branch_head, onto_head);
@@ -139,7 +131,7 @@ void test_rebase_abort__old_style_head_file(void)
cl_git_pass(git_signature_new(&signature, "Rebaser", "rebaser@example.com", 1404157834, -400));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, signature, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
p_rename("rebase-merge/.git/rebase-merge/orig-head",
diff --git a/tests/rebase/iterator.c b/tests/rebase/iterator.c
index 8117a094a..2cff82ced 100644
--- a/tests/rebase/iterator.c
+++ b/tests/rebase/iterator.c
@@ -64,7 +64,7 @@ void test_rebase_iterator__iterates(void)
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, signature, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
test_operations(rebase, 0);
git_rebase_free(rebase);
diff --git a/tests/rebase/merge.c b/tests/rebase/merge.c
index 1b2ec96bc..f820e96c6 100644
--- a/tests/rebase/merge.c
+++ b/tests/rebase/merge.c
@@ -53,7 +53,7 @@ void test_rebase_merge__next(void)
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, signature, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase, &checkout_opts));
@@ -120,7 +120,7 @@ void test_rebase_merge__next_with_conflicts(void)
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, signature, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase, &checkout_opts));
@@ -165,7 +165,7 @@ void test_rebase_merge__next_stops_with_iterover(void)
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, signature, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase, &checkout_opts));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
@@ -221,7 +221,7 @@ void test_rebase_merge__commit(void)
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, signature, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase, &checkout_opts));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
@@ -279,7 +279,7 @@ void test_rebase_merge__commit_updates_rewritten(void)
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, signature, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase, &checkout_opts));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
@@ -319,7 +319,7 @@ void test_rebase_merge__commit_drops_already_applied(void)
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, signature, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase, &checkout_opts));
cl_git_fail(error = git_rebase_commit(&commit_id, rebase, NULL, signature,
@@ -362,7 +362,7 @@ void test_rebase_merge__finish(void)
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, signature, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase, &checkout_opts));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
@@ -433,7 +433,7 @@ static void test_copy_note(
git_commit_id(branch_commit),
"This is a commit note.", 0));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, signature, opts));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, opts));
cl_git_pass(git_rebase_next(&rebase_operation, rebase, &checkout_opts));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
diff --git a/tests/rebase/setup.c b/tests/rebase/setup.c
index f1eb6a47d..627d3b9de 100644
--- a/tests/rebase/setup.c
+++ b/tests/rebase/setup.c
@@ -39,12 +39,12 @@ void test_rebase_setup__blocked_when_in_progress(void)
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, signature, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
git_rebase_free(rebase);
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
- cl_git_fail(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, signature, NULL));
+ cl_git_fail(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
@@ -70,7 +70,7 @@ void test_rebase_setup__merge(void)
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, signature, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
@@ -118,7 +118,7 @@ void test_rebase_setup__merge_root(void)
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&onto_head, repo, onto_ref));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, signature, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, NULL));
git_oid_fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00");
cl_git_pass(git_repository_head(&head, repo));
@@ -168,7 +168,7 @@ void test_rebase_setup__merge_onto_and_upstream(void)
cl_git_pass(git_annotated_commit_from_ref(&branch2_head, repo, branch2_ref));
cl_git_pass(git_annotated_commit_from_ref(&onto_head, repo, onto_ref));
- cl_git_pass(git_rebase_init(&rebase, repo, branch1_head, branch2_head, onto_head, signature, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch1_head, branch2_head, onto_head, NULL));
git_oid_fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00");
cl_git_pass(git_repository_head(&head, repo));
@@ -215,7 +215,7 @@ void test_rebase_setup__branch_with_merges(void)
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, signature, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
@@ -263,7 +263,7 @@ void test_rebase_setup__orphan_branch(void)
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, signature, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
@@ -308,13 +308,13 @@ void test_rebase_setup__merge_null_branch_uses_HEAD(void)
cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo));
- cl_git_pass(git_repository_set_head(repo, "refs/heads/beef", NULL, NULL));
+ cl_git_pass(git_repository_set_head(repo, "refs/heads/beef"));
cl_git_pass(git_checkout_head(repo, &checkout_opts));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
- cl_git_pass(git_rebase_init(&rebase, repo, NULL, upstream_head, NULL, signature, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, NULL, upstream_head, NULL, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
@@ -358,7 +358,7 @@ static int rebase_is_blocked(void)
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
- error = git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, signature, NULL);
+ error = git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
diff --git a/tests/refs/branches/create.c b/tests/refs/branches/create.c
index af9963bde..d4cf4c29f 100644
--- a/tests/refs/branches/create.c
+++ b/tests/refs/branches/create.c
@@ -45,7 +45,7 @@ void test_refs_branches_create__can_create_a_local_branch(void)
{
retrieve_known_commit(&target, repo);
- cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, 0, NULL, NULL));
+ cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, 0));
cl_git_pass(git_oid_cmp(git_reference_target(branch), git_commit_id(target)));
}
@@ -53,14 +53,14 @@ void test_refs_branches_create__can_not_create_a_branch_if_its_name_collide_with
{
retrieve_known_commit(&target, repo);
- cl_assert_equal_i(GIT_EEXISTS, git_branch_create(&branch, repo, "br2", target, 0, NULL, NULL));
+ cl_assert_equal_i(GIT_EEXISTS, git_branch_create(&branch, repo, "br2", target, 0));
}
void test_refs_branches_create__can_force_create_over_an_existing_branch(void)
{
retrieve_known_commit(&target, repo);
- cl_git_pass(git_branch_create(&branch, repo, "br2", target, 1, NULL, NULL));
+ cl_git_pass(git_branch_create(&branch, repo, "br2", target, 1));
cl_git_pass(git_oid_cmp(git_reference_target(branch), git_commit_id(target)));
cl_assert_equal_s("refs/heads/br2", git_reference_name(branch));
}
@@ -76,7 +76,7 @@ void test_refs_branches_create__cannot_force_create_over_current_branch(void)
cl_assert_equal_i(true, git_branch_is_head(branch2));
oid = git_reference_target(branch2);
- cl_git_fail_with(-1, git_branch_create(&branch, repo, "master", target, 1, NULL, NULL));
+ cl_git_fail_with(-1, git_branch_create(&branch, repo, "master", target, 1));
branch = NULL;
cl_git_pass(git_branch_lookup(&branch, repo, "master", GIT_BRANCH_LOCAL));
cl_assert_equal_s("refs/heads/master", git_reference_name(branch));
@@ -89,33 +89,13 @@ void test_refs_branches_create__creating_a_branch_with_an_invalid_name_returns_E
retrieve_known_commit(&target, repo);
cl_assert_equal_i(GIT_EINVALIDSPEC,
- git_branch_create(&branch, repo, "inv@{id", target, 0, NULL, NULL));
-}
-
-void test_refs_branches_create__creation_creates_new_reflog(void)
-{
- git_reflog *log;
- const git_reflog_entry *entry;
- git_signature *sig;
-
- cl_git_pass(git_signature_now(&sig, "me", "foo@example.com"));
-
- retrieve_known_commit(&target, repo);
- cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, false, sig, "create!"));
- cl_git_pass(git_reflog_read(&log, repo, "refs/heads/" NEW_BRANCH_NAME));
-
- cl_assert_equal_i(1, git_reflog_entrycount(log));
- entry = git_reflog_entry_byindex(log, 0);
- cl_assert_equal_s("create!", git_reflog_entry_message(entry));
- cl_assert_equal_s("foo@example.com", git_reflog_entry_committer(entry)->email);
-
- git_reflog_free(log);
- git_signature_free(sig);
+ git_branch_create(&branch, repo, "inv@{id", target, 0));
}
void test_refs_branches_create__default_reflog_message(void)
{
git_reflog *log;
+ git_buf buf = GIT_BUF_INIT;
const git_reflog_entry *entry;
git_signature *sig;
git_config *cfg;
@@ -128,13 +108,15 @@ void test_refs_branches_create__default_reflog_message(void)
cl_git_pass(git_signature_default(&sig, repo));
retrieve_known_commit(&target, repo);
- cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, false, NULL, NULL));
+ cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, false));
cl_git_pass(git_reflog_read(&log, repo, "refs/heads/" NEW_BRANCH_NAME));
entry = git_reflog_entry_byindex(log, 0);
- cl_assert_equal_s("Branch: created", git_reflog_entry_message(entry));
+ cl_git_pass(git_buf_printf(&buf, "branch: Created from %s", git_oid_tostr_s(git_commit_id(target))));
+ cl_assert_equal_s(git_buf_cstr(&buf), git_reflog_entry_message(entry));
cl_assert_equal_s(sig->email, git_reflog_entry_committer(entry)->email);
+ git_buf_free(&buf);
git_reflog_free(log);
git_signature_free(sig);
}
@@ -181,7 +163,7 @@ void test_refs_branches_create__can_create_branch_with_unicode(void)
for (i = 0; i < ARRAY_SIZE(names); ++i) {
const char *name;
cl_git_pass(git_branch_create(
- &branch, repo, names[i], target, 0, NULL, NULL));
+ &branch, repo, names[i], target, 0));
cl_git_pass(git_oid_cmp(
git_reference_target(branch), git_commit_id(target)));
@@ -239,7 +221,7 @@ void test_refs_branches_create__name_vs_namespace(void)
retrieve_known_commit(&target, repo);
for (p=item; p->first; p++) {
- cl_git_pass(git_branch_create(&branch, repo, p->first, target, 0, NULL, NULL));
+ cl_git_pass(git_branch_create(&branch, repo, p->first, target, 0));
cl_git_pass(git_oid_cmp(git_reference_target(branch), git_commit_id(target)));
cl_git_pass(git_branch_name(&name, branch));
cl_assert_equal_s(name, p->first);
@@ -248,7 +230,7 @@ void test_refs_branches_create__name_vs_namespace(void)
git_reference_free(branch);
branch = NULL;
- cl_git_pass(git_branch_create(&branch, repo, p->second, target, 0, NULL, NULL));
+ cl_git_pass(git_branch_create(&branch, repo, p->second, target, 0));
git_reference_free(branch);
branch = NULL;
}
@@ -277,7 +259,7 @@ void test_refs_branches_create__name_vs_namespace_fail(void)
retrieve_known_commit(&target, repo);
for (p=item; p->first; p++) {
- cl_git_pass(git_branch_create(&branch, repo, p->first, target, 0, NULL, NULL));
+ cl_git_pass(git_branch_create(&branch, repo, p->first, target, 0));
cl_git_pass(git_oid_cmp(git_reference_target(branch), git_commit_id(target)));
cl_git_pass(git_branch_name(&name, branch));
cl_assert_equal_s(name, p->first);
@@ -286,7 +268,7 @@ void test_refs_branches_create__name_vs_namespace_fail(void)
git_reference_free(branch);
branch = NULL;
- cl_git_pass(git_branch_create(&branch, repo, p->first_alternate, target, 0, NULL, NULL));
+ cl_git_pass(git_branch_create(&branch, repo, p->first_alternate, target, 0));
cl_git_pass(git_oid_cmp(git_reference_target(branch), git_commit_id(target)));
cl_git_pass(git_branch_name(&name, branch));
cl_assert_equal_s(name, p->first_alternate);
@@ -295,7 +277,7 @@ void test_refs_branches_create__name_vs_namespace_fail(void)
git_reference_free(branch);
branch = NULL;
- cl_git_fail(git_branch_create(&branch, repo, p->second, target, 0, NULL, NULL));
+ cl_git_fail(git_branch_create(&branch, repo, p->second, target, 0));
git_reference_free(branch);
branch = NULL;
}
diff --git a/tests/refs/branches/delete.c b/tests/refs/branches/delete.c
index e3199e230..343ff0f50 100644
--- a/tests/refs/branches/delete.c
+++ b/tests/refs/branches/delete.c
@@ -13,7 +13,7 @@ void test_refs_branches_delete__initialize(void)
repo = cl_git_sandbox_init("testrepo.git");
cl_git_pass(git_oid_fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"));
- cl_git_pass(git_reference_create(&fake_remote, repo, "refs/remotes/nulltoken/master", &id, 0, NULL, NULL));
+ cl_git_pass(git_reference_create(&fake_remote, repo, "refs/remotes/nulltoken/master", &id, 0, NULL));
}
void test_refs_branches_delete__cleanup(void)
@@ -75,7 +75,7 @@ void test_refs_branches_delete__can_delete_a_branch_pointed_at_by_detached_HEAD(
git_reference_free(head);
/* Detach HEAD and make it target the commit that "master" points to */
- git_repository_detach_head(repo, NULL, NULL);
+ git_repository_detach_head(repo);
cl_git_pass(git_branch_lookup(&branch, repo, "master", GIT_BRANCH_LOCAL));
cl_git_pass(git_branch_delete(branch));
diff --git a/tests/refs/branches/ishead.c b/tests/refs/branches/ishead.c
index d16a79652..1df70b789 100644
--- a/tests/refs/branches/ishead.c
+++ b/tests/refs/branches/ishead.c
@@ -82,9 +82,9 @@ void test_refs_branches_ishead__only_direct_references_are_considered(void)
{
git_reference *linked, *super, *head;
- cl_git_pass(git_reference_symbolic_create(&linked, repo, "refs/heads/linked", "refs/heads/master", 0, NULL, NULL));
- cl_git_pass(git_reference_symbolic_create(&super, repo, "refs/heads/super", "refs/heads/linked", 0, NULL, NULL));
- cl_git_pass(git_reference_symbolic_create(&head, repo, GIT_HEAD_FILE, "refs/heads/super", 1, NULL, NULL));
+ cl_git_pass(git_reference_symbolic_create(&linked, repo, "refs/heads/linked", "refs/heads/master", 0, NULL));
+ cl_git_pass(git_reference_symbolic_create(&super, repo, "refs/heads/super", "refs/heads/linked", 0, NULL));
+ cl_git_pass(git_reference_symbolic_create(&head, repo, GIT_HEAD_FILE, "refs/heads/super", 1, NULL));
cl_assert_equal_i(false, git_branch_is_head(linked));
cl_assert_equal_i(false, git_branch_is_head(super));
diff --git a/tests/refs/branches/iterator.c b/tests/refs/branches/iterator.c
index 76b35a7d6..ca366c9f3 100644
--- a/tests/refs/branches/iterator.c
+++ b/tests/refs/branches/iterator.c
@@ -12,7 +12,7 @@ void test_refs_branches_iterator__initialize(void)
cl_git_pass(git_repository_open(&repo, "testrepo.git"));
cl_git_pass(git_oid_fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"));
- cl_git_pass(git_reference_create(&fake_remote, repo, "refs/remotes/nulltoken/master", &id, 0, NULL, NULL));
+ cl_git_pass(git_reference_create(&fake_remote, repo, "refs/remotes/nulltoken/master", &id, 0, NULL));
}
void test_refs_branches_iterator__cleanup(void)
@@ -113,7 +113,7 @@ void test_refs_branches_iterator__retrieve_remote_symbolic_HEAD_when_present(voi
};
git_reference_free(fake_remote);
- cl_git_pass(git_reference_symbolic_create(&fake_remote, repo, "refs/remotes/nulltoken/HEAD", "refs/remotes/nulltoken/master", 0, NULL, NULL));
+ cl_git_pass(git_reference_symbolic_create(&fake_remote, repo, "refs/remotes/nulltoken/HEAD", "refs/remotes/nulltoken/master", 0, NULL));
assert_retrieval(GIT_BRANCH_REMOTE, 3);
diff --git a/tests/refs/branches/move.c b/tests/refs/branches/move.c
index f136b00d6..bec39e18b 100644
--- a/tests/refs/branches/move.c
+++ b/tests/refs/branches/move.c
@@ -22,7 +22,7 @@ void test_refs_branches_move__can_move_a_local_branch(void)
cl_git_pass(git_reference_lookup(&original_ref, repo, "refs/heads/br2"));
- cl_git_pass(git_branch_move(&new_ref, original_ref, NEW_BRANCH_NAME, 0, NULL, NULL));
+ cl_git_pass(git_branch_move(&new_ref, original_ref, NEW_BRANCH_NAME, 0));
cl_assert_equal_s(GIT_REFS_HEADS_DIR NEW_BRANCH_NAME, git_reference_name(new_ref));
git_reference_free(original_ref);
@@ -36,11 +36,11 @@ void test_refs_branches_move__can_move_a_local_branch_to_a_different_namespace(v
cl_git_pass(git_reference_lookup(&original_ref, repo, "refs/heads/br2"));
/* Downward */
- cl_git_pass(git_branch_move(&new_ref, original_ref, "somewhere/" NEW_BRANCH_NAME, 0, NULL, NULL));
+ cl_git_pass(git_branch_move(&new_ref, original_ref, "somewhere/" NEW_BRANCH_NAME, 0));
git_reference_free(original_ref);
/* Upward */
- cl_git_pass(git_branch_move(&newer_ref, new_ref, "br2", 0, NULL, NULL));
+ cl_git_pass(git_branch_move(&newer_ref, new_ref, "br2", 0));
git_reference_free(new_ref);
git_reference_free(newer_ref);
@@ -53,11 +53,11 @@ void test_refs_branches_move__can_move_a_local_branch_to_a_partially_colliding_n
cl_git_pass(git_reference_lookup(&original_ref, repo, "refs/heads/br2"));
/* Downward */
- cl_git_pass(git_branch_move(&new_ref, original_ref, "br2/" NEW_BRANCH_NAME, 0, NULL, NULL));
+ cl_git_pass(git_branch_move(&new_ref, original_ref, "br2/" NEW_BRANCH_NAME, 0));
git_reference_free(original_ref);
/* Upward */
- cl_git_pass(git_branch_move(&newer_ref, new_ref, "br2", 0, NULL, NULL));
+ cl_git_pass(git_branch_move(&newer_ref, new_ref, "br2", 0));
git_reference_free(new_ref);
git_reference_free(newer_ref);
@@ -67,51 +67,59 @@ void test_refs_branches_move__can_not_move_a_branch_if_its_destination_name_coll
{
git_reference *original_ref, *new_ref;
git_config *config;
- const git_config_entry *ce;
+ git_buf buf = GIT_BUF_INIT;
char *original_remote, *original_merge;
+ const char *str;
- cl_git_pass(git_repository_config(&config, repo));
-
- cl_git_pass(git_config_get_entry(&ce, config, "branch.master.remote"));
- original_remote = strdup(ce->value);
- cl_git_pass(git_config_get_entry(&ce, config, "branch.master.merge"));
- original_merge = strdup(ce->value);
+ cl_git_pass(git_repository_config_snapshot(&config, repo));
+ cl_git_pass(git_config_get_string_buf(&buf, config, "branch.master.remote"));
+ original_remote = git_buf_detach(&buf);
+ cl_git_pass(git_config_get_string_buf(&buf, config, "branch.master.merge"));
+ original_merge = git_buf_detach(&buf);
+ git_config_free(config);
cl_git_pass(git_reference_lookup(&original_ref, repo, "refs/heads/br2"));
cl_assert_equal_i(GIT_EEXISTS,
- git_branch_move(&new_ref, original_ref, "master", 0, NULL, NULL));
+ git_branch_move(&new_ref, original_ref, "master", 0));
cl_assert(giterr_last()->message != NULL);
- cl_git_pass(git_config_get_entry(&ce, config, "branch.master.remote"));
- cl_assert_equal_s(original_remote, ce->value);
- cl_git_pass(git_config_get_entry(&ce, config, "branch.master.merge"));
- cl_assert_equal_s(original_merge, ce->value);
+ cl_git_pass(git_repository_config_snapshot(&config, repo));
+ cl_git_pass(git_config_get_string(&str, config, "branch.master.remote"));
+ cl_assert_equal_s(original_remote, str);
+ cl_git_pass(git_config_get_string(&str, config, "branch.master.merge"));
+ cl_assert_equal_s(original_merge, str);
+ git_config_free(config);
cl_assert_equal_i(GIT_EEXISTS,
- git_branch_move(&new_ref, original_ref, "cannot-fetch", 0, NULL, NULL));
+ git_branch_move(&new_ref, original_ref, "cannot-fetch", 0));
cl_assert(giterr_last()->message != NULL);
- cl_git_pass(git_config_get_entry(&ce, config, "branch.master.remote"));
- cl_assert_equal_s(original_remote, ce->value);
- cl_git_pass(git_config_get_entry(&ce, config, "branch.master.merge"));
- cl_assert_equal_s(original_merge, ce->value);
+
+ cl_git_pass(git_repository_config_snapshot(&config, repo));
+ cl_git_pass(git_config_get_string(&str, config, "branch.master.remote"));
+ cl_assert_equal_s(original_remote, str);
+ cl_git_pass(git_config_get_string(&str, config, "branch.master.merge"));
+ cl_assert_equal_s(original_merge, str);
+ git_config_free(config);
git_reference_free(original_ref);
cl_git_pass(git_reference_lookup(&original_ref, repo, "refs/heads/track-local"));
cl_assert_equal_i(GIT_EEXISTS,
- git_branch_move(&new_ref, original_ref, "master", 0, NULL, NULL));
+ git_branch_move(&new_ref, original_ref, "master", 0));
cl_assert(giterr_last()->message != NULL);
- cl_git_pass(git_config_get_entry(&ce, config, "branch.master.remote"));
- cl_assert_equal_s(original_remote, ce->value);
- cl_git_pass(git_config_get_entry(&ce, config, "branch.master.merge"));
- cl_assert_equal_s(original_merge, ce->value);
- free(original_remote); free(original_merge);
+ cl_git_pass(git_repository_config_snapshot(&config, repo));
+ cl_git_pass(git_config_get_string(&str, config, "branch.master.remote"));
+ cl_assert_equal_s(original_remote, str);
+ cl_git_pass(git_config_get_string(&str, config, "branch.master.merge"));
+ cl_assert_equal_s(original_merge, str);
+
+ git__free(original_remote); git__free(original_merge);
git_reference_free(original_ref);
git_config_free(config);
}
@@ -122,7 +130,7 @@ void test_refs_branches_move__moving_a_branch_with_an_invalid_name_returns_EINVA
cl_git_pass(git_reference_lookup(&original_ref, repo, "refs/heads/br2"));
- cl_assert_equal_i(GIT_EINVALIDSPEC, git_branch_move(&new_ref, original_ref, "Inv@{id", 0, NULL, NULL));
+ cl_assert_equal_i(GIT_EINVALIDSPEC, git_branch_move(&new_ref, original_ref, "Inv@{id", 0));
git_reference_free(original_ref);
}
@@ -132,7 +140,7 @@ void test_refs_branches_move__can_not_move_a_non_branch(void)
git_reference *tag, *new_ref;
cl_git_pass(git_reference_lookup(&tag, repo, "refs/tags/e90810b"));
- cl_git_fail(git_branch_move(&new_ref, tag, NEW_BRANCH_NAME, 0, NULL, NULL));
+ cl_git_fail(git_branch_move(&new_ref, tag, NEW_BRANCH_NAME, 0));
git_reference_free(tag);
}
@@ -143,7 +151,7 @@ void test_refs_branches_move__can_force_move_over_an_existing_branch(void)
cl_git_pass(git_reference_lookup(&original_ref, repo, "refs/heads/br2"));
- cl_git_pass(git_branch_move(&new_ref, original_ref, "master", 1, NULL, NULL));
+ cl_git_pass(git_branch_move(&new_ref, original_ref, "master", 1));
git_reference_free(original_ref);
git_reference_free(new_ref);
@@ -161,7 +169,7 @@ void test_refs_branches_move__moving_a_branch_moves_related_configuration_data(v
assert_config_entry_existence(repo, "branch.moved.remote", false);
assert_config_entry_existence(repo, "branch.moved.merge", false);
- cl_git_pass(git_branch_move(&new_branch, branch, "moved", 0, NULL, NULL));
+ cl_git_pass(git_branch_move(&new_branch, branch, "moved", 0));
git_reference_free(branch);
assert_config_entry_existence(repo, "branch.track-local.remote", false);
@@ -178,7 +186,7 @@ void test_refs_branches_move__moving_the_branch_pointed_at_by_HEAD_updates_HEAD(
git_reference *new_branch;
cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/master"));
- cl_git_pass(git_branch_move(&new_branch, branch, "master2", 0, NULL, NULL));
+ cl_git_pass(git_branch_move(&new_branch, branch, "master2", 0));
git_reference_free(branch);
git_reference_free(new_branch);
@@ -187,30 +195,6 @@ void test_refs_branches_move__moving_the_branch_pointed_at_by_HEAD_updates_HEAD(
git_reference_free(branch);
}
-void test_refs_branches_move__updates_the_reflog(void)
-{
- git_reference *branch;
- git_reference *new_branch;
- git_reflog *log;
- const git_reflog_entry *entry;
- git_signature *sig;
-
- cl_git_pass(git_signature_now(&sig, "me", "foo@example.com"));
-
- cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/master"));
- cl_git_pass(git_branch_move(&new_branch, branch, "master2", 0, sig, "message"));
-
- cl_git_pass(git_reflog_read(&log, repo, git_reference_name(new_branch)));
- entry = git_reflog_entry_byindex(log, 0);
- cl_assert_equal_s("message", git_reflog_entry_message(entry));
- cl_assert_equal_s("foo@example.com", git_reflog_entry_committer(entry)->email);
-
- git_reference_free(branch);
- git_reference_free(new_branch);
- git_reflog_free(log);
- git_signature_free(sig);
-}
-
void test_refs_branches_move__default_reflog_message(void)
{
git_reference *branch;
@@ -219,6 +203,7 @@ void test_refs_branches_move__default_reflog_message(void)
const git_reflog_entry *entry;
git_signature *sig;
git_config *cfg;
+ git_oid id;
cl_git_pass(git_repository_config(&cfg, repo));
cl_git_pass(git_config_set_string(cfg, "user.name", "Foo Bar"));
@@ -228,13 +213,16 @@ void test_refs_branches_move__default_reflog_message(void)
cl_git_pass(git_signature_default(&sig, repo));
cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/master"));
- cl_git_pass(git_branch_move(&new_branch, branch, "master2", 0, NULL, NULL));
+ git_oid_cpy(&id, git_reference_target(branch));
+ cl_git_pass(git_branch_move(&new_branch, branch, "master2", 0));
cl_git_pass(git_reflog_read(&log, repo, git_reference_name(new_branch)));
entry = git_reflog_entry_byindex(log, 0);
- cl_assert_equal_s("Branch: renamed refs/heads/master to refs/heads/master2",
+ cl_assert_equal_s("branch: renamed refs/heads/master to refs/heads/master2",
git_reflog_entry_message(entry));
cl_assert_equal_s(sig->email, git_reflog_entry_committer(entry)->email);
+ cl_assert_equal_oid(&id, git_reflog_entry_id_old(entry));
+ cl_assert_equal_oid(&id, git_reflog_entry_id_new(entry));
git_reference_free(branch);
git_reference_free(new_branch);
@@ -248,7 +236,7 @@ void test_refs_branches_move__can_move_with_unicode(void)
const char *new_branch_name = "\x41\xCC\x8A\x73\x74\x72\x6F\xCC\x88\x6D";
cl_git_pass(git_reference_lookup(&original_ref, repo, "refs/heads/br2"));
- cl_git_pass(git_branch_move(&new_ref, original_ref, new_branch_name, 0, NULL, NULL));
+ cl_git_pass(git_branch_move(&new_ref, original_ref, new_branch_name, 0));
if (cl_repo_get_bool(repo, "core.precomposeunicode"))
cl_assert_equal_s(GIT_REFS_HEADS_DIR "\xC3\x85\x73\x74\x72\xC3\xB6\x6D", git_reference_name(new_ref));
diff --git a/tests/refs/branches/upstream.c b/tests/refs/branches/upstream.c
index b20b93753..351449416 100644
--- a/tests/refs/branches/upstream.c
+++ b/tests/refs/branches/upstream.c
@@ -1,4 +1,5 @@
#include "clar_libgit2.h"
+#include "config/config_helpers.h"
#include "refs.h"
static git_repository *repo;
@@ -91,7 +92,7 @@ static void assert_merge_and_or_remote_key_missing(git_repository *repository, c
git_reference *branch;
cl_assert_equal_i(GIT_OBJ_COMMIT, git_object_type((git_object*)target));
- cl_git_pass(git_branch_create(&branch, repository, entry_name, (git_commit*)target, 0, NULL, NULL));
+ cl_git_pass(git_branch_create(&branch, repository, entry_name, (git_commit*)target, 0));
cl_assert_equal_i(GIT_ENOTFOUND, git_branch_upstream(&upstream, branch));
@@ -123,8 +124,6 @@ void test_refs_branches_upstream__set_unset_upstream(void)
{
git_reference *branch;
git_repository *repository;
- const char *value;
- git_config *config;
repository = cl_git_sandbox_init("testrepo.git");
@@ -132,11 +131,8 @@ void test_refs_branches_upstream__set_unset_upstream(void)
cl_git_pass(git_reference_lookup(&branch, repository, "refs/heads/test"));
cl_git_pass(git_branch_set_upstream(branch, "test/master"));
- cl_git_pass(git_repository_config(&config, repository));
- cl_git_pass(git_config_get_string(&value, config, "branch.test.remote"));
- cl_assert_equal_s(value, "test");
- cl_git_pass(git_config_get_string(&value, config, "branch.test.merge"));
- cl_assert_equal_s(value, "refs/heads/master");
+ assert_config_entry_value(repository, "branch.test.remote", "test");
+ assert_config_entry_value(repository, "branch.test.merge", "refs/heads/master");
git_reference_free(branch);
@@ -144,25 +140,22 @@ void test_refs_branches_upstream__set_unset_upstream(void)
cl_git_pass(git_reference_lookup(&branch, repository, "refs/heads/test"));
cl_git_pass(git_branch_set_upstream(branch, "master"));
- cl_git_pass(git_config_get_string(&value, config, "branch.test.remote"));
- cl_assert_equal_s(value, ".");
- cl_git_pass(git_config_get_string(&value, config, "branch.test.merge"));
- cl_assert_equal_s(value, "refs/heads/master");
+ assert_config_entry_value(repository, "branch.test.remote", ".");
+ assert_config_entry_value(repository, "branch.test.merge", "refs/heads/master");
/* unset */
cl_git_pass(git_branch_set_upstream(branch, NULL));
- cl_git_fail_with(git_config_get_string(&value, config, "branch.test.merge"), GIT_ENOTFOUND);
- cl_git_fail_with(git_config_get_string(&value, config, "branch.test.remote"), GIT_ENOTFOUND);
+ assert_config_entry_existence(repository, "branch.test.remote", false);
+ assert_config_entry_existence(repository, "branch.test.merge", false);
git_reference_free(branch);
cl_git_pass(git_reference_lookup(&branch, repository, "refs/heads/master"));
cl_git_pass(git_branch_set_upstream(branch, NULL));
- cl_git_fail_with(git_config_get_string(&value, config, "branch.master.merge"), GIT_ENOTFOUND);
- cl_git_fail_with(git_config_get_string(&value, config, "branch.master.remote"), GIT_ENOTFOUND);
+ assert_config_entry_existence(repository, "branch.test.remote", false);
+ assert_config_entry_existence(repository, "branch.test.merge", false);
git_reference_free(branch);
- git_config_free(config);
cl_git_sandbox_cleanup();
}
diff --git a/tests/refs/crashes.c b/tests/refs/crashes.c
index 03082d71e..7a10411c8 100644
--- a/tests/refs/crashes.c
+++ b/tests/refs/crashes.c
@@ -7,7 +7,7 @@ void test_refs_crashes__double_free(void)
const char *REFNAME = "refs/heads/xxx";
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
- cl_git_pass(git_reference_symbolic_create(&ref, repo, REFNAME, "refs/heads/master", 0, NULL, NULL));
+ cl_git_pass(git_reference_symbolic_create(&ref, repo, REFNAME, "refs/heads/master", 0, NULL));
cl_git_pass(git_reference_lookup(&ref2, repo, REFNAME));
cl_git_pass(git_reference_delete(ref));
git_reference_free(ref);
diff --git a/tests/refs/create.c b/tests/refs/create.c
index 3af7c1d15..192551dbd 100644
--- a/tests/refs/create.c
+++ b/tests/refs/create.c
@@ -32,7 +32,7 @@ void test_refs_create__symbolic(void)
git_oid_fromstr(&id, current_master_tip);
/* Create and write the new symbolic reference */
- cl_git_pass(git_reference_symbolic_create(&new_reference, g_repo, new_head_tracker, current_head_target, 0, NULL, NULL));
+ cl_git_pass(git_reference_symbolic_create(&new_reference, g_repo, new_head_tracker, current_head_target, 0, NULL));
/* Ensure the reference can be looked-up... */
cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, new_head_tracker));
@@ -73,7 +73,7 @@ void test_refs_create__deep_symbolic(void)
git_oid_fromstr(&id, current_master_tip);
- cl_git_pass(git_reference_symbolic_create(&new_reference, g_repo, new_head_tracker, current_head_target, 0, NULL, NULL));
+ cl_git_pass(git_reference_symbolic_create(&new_reference, g_repo, new_head_tracker, current_head_target, 0, NULL));
cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, new_head_tracker));
cl_git_pass(git_reference_resolve(&resolved_ref, looked_up_ref));
cl_assert_equal_oid(&id, git_reference_target(resolved_ref));
@@ -95,7 +95,7 @@ void test_refs_create__oid(void)
git_oid_fromstr(&id, current_master_tip);
/* Create and write the new object id reference */
- cl_git_pass(git_reference_create(&new_reference, g_repo, new_head, &id, 0, NULL, NULL));
+ cl_git_pass(git_reference_create(&new_reference, g_repo, new_head, &id, 0, NULL));
/* Ensure the reference can be looked-up... */
cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, new_head));
@@ -130,7 +130,7 @@ void test_refs_create__oid_unknown(void)
git_oid_fromstr(&id, "deadbeef3f795b2b4353bcce3a527ad0a4f7f644");
/* Create and write the new object id reference */
- cl_git_fail(git_reference_create(&new_reference, g_repo, new_head, &id, 0, NULL, NULL));
+ cl_git_fail(git_reference_create(&new_reference, g_repo, new_head, &id, 0, NULL));
/* Ensure the reference can't be looked-up... */
cl_git_fail(git_reference_lookup(&looked_up_ref, g_repo, new_head));
@@ -144,10 +144,10 @@ void test_refs_create__propagate_eexists(void)
/* Make sure it works for oid and for symbolic both */
git_oid_fromstr(&oid, current_master_tip);
- error = git_reference_create(&ref, g_repo, current_head_target, &oid, false, NULL, NULL);
+ error = git_reference_create(&ref, g_repo, current_head_target, &oid, false, NULL);
cl_assert(error == GIT_EEXISTS);
- error = git_reference_symbolic_create(&ref, g_repo, "HEAD", current_head_target, false, NULL, NULL);
+ error = git_reference_symbolic_create(&ref, g_repo, "HEAD", current_head_target, false, NULL);
cl_assert(error == GIT_EEXISTS);
}
@@ -159,10 +159,10 @@ static void test_invalid_name(const char *name)
git_oid_fromstr(&id, current_master_tip);
cl_assert_equal_i(GIT_EINVALIDSPEC, git_reference_create(
- &new_reference, g_repo, name, &id, 0, NULL, NULL));
+ &new_reference, g_repo, name, &id, 0, NULL));
cl_assert_equal_i(GIT_EINVALIDSPEC, git_reference_symbolic_create(
- &new_reference, g_repo, name, current_head_target, 0, NULL, NULL));
+ &new_reference, g_repo, name, current_head_target, 0, NULL));
}
void test_refs_create__creating_a_reference_with_an_invalid_name_returns_EINVALIDSPEC(void)
@@ -188,7 +188,7 @@ static void test_win32_name(const char *name)
git_oid_fromstr(&id, current_master_tip);
- ret = git_reference_create(&new_reference, g_repo, name, &id, 0, NULL, NULL);
+ ret = git_reference_create(&new_reference, g_repo, name, &id, 0, NULL);
#ifdef GIT_WIN32
cl_assert_equal_i(GIT_EINVALIDSPEC, ret);
diff --git a/tests/refs/createwithlog.c b/tests/refs/createwithlog.c
index ab13d7d15..4f643635b 100644
--- a/tests/refs/createwithlog.c
+++ b/tests/refs/createwithlog.c
@@ -23,7 +23,6 @@ void test_refs_createwithlog__creating_a_direct_reference_adds_a_reflog_entry(vo
{
git_reference *reference;
git_oid id;
- git_signature *signature;
git_reflog *reflog;
const git_reflog_entry *entry;
@@ -32,10 +31,8 @@ void test_refs_createwithlog__creating_a_direct_reference_adds_a_reflog_entry(vo
git_oid_fromstr(&id, current_master_tip);
- cl_git_pass(git_signature_now(&signature, "foo", "foo@bar"));
-
cl_git_pass(
- git_reference_create(&reference, g_repo, name, &id, 0, signature, message));
+ git_reference_create(&reference, g_repo, name, &id, 0, message));
cl_git_pass(git_reflog_read(&reflog, g_repo, name));
cl_assert_equal_sz(1, git_reflog_entrycount(reflog));
@@ -47,5 +44,4 @@ void test_refs_createwithlog__creating_a_direct_reference_adds_a_reflog_entry(vo
git_reflog_free(reflog);
git_reference_free(reference);
- git_signature_free(signature);
}
diff --git a/tests/refs/delete.c b/tests/refs/delete.c
index 9d1c3fd79..a1b9e251e 100644
--- a/tests/refs/delete.c
+++ b/tests/refs/delete.c
@@ -66,7 +66,7 @@ void test_refs_delete__packed_only(void)
git_oid_fromstr(&id, current_master_tip);
/* Create and write the new object id reference */
- cl_git_pass(git_reference_create(&ref, g_repo, new_ref, &id, 0, NULL, NULL));
+ cl_git_pass(git_reference_create(&ref, g_repo, new_ref, &id, 0, NULL));
git_reference_free(ref);
/* Lookup the reference */
diff --git a/tests/refs/foreachglob.c b/tests/refs/foreachglob.c
index b992b07b8..a09191e79 100644
--- a/tests/refs/foreachglob.c
+++ b/tests/refs/foreachglob.c
@@ -12,7 +12,7 @@ void test_refs_foreachglob__initialize(void)
cl_git_pass(git_repository_open(&repo, "testrepo.git"));
cl_git_pass(git_oid_fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"));
- cl_git_pass(git_reference_create(&fake_remote, repo, "refs/remotes/nulltoken/master", &id, 0, NULL, NULL));
+ cl_git_pass(git_reference_create(&fake_remote, repo, "refs/remotes/nulltoken/master", &id, 0, NULL));
}
void test_refs_foreachglob__cleanup(void)
diff --git a/tests/refs/overwrite.c b/tests/refs/overwrite.c
index c237d76f4..5aea2a764 100644
--- a/tests/refs/overwrite.c
+++ b/tests/refs/overwrite.c
@@ -27,8 +27,8 @@ void test_refs_overwrite__symbolic(void)
git_reference *ref, *branch_ref;
/* The target needds to exist and we need to check the name has changed */
- cl_git_pass(git_reference_symbolic_create(&branch_ref, g_repo, ref_branch_name, ref_master_name, 0, NULL, NULL));
- cl_git_pass(git_reference_symbolic_create(&ref, g_repo, ref_name, ref_branch_name, 0, NULL, NULL));
+ cl_git_pass(git_reference_symbolic_create(&branch_ref, g_repo, ref_branch_name, ref_master_name, 0, NULL));
+ cl_git_pass(git_reference_symbolic_create(&ref, g_repo, ref_name, ref_branch_name, 0, NULL));
git_reference_free(ref);
/* Ensure it points to the right place*/
@@ -38,8 +38,8 @@ void test_refs_overwrite__symbolic(void)
git_reference_free(ref);
/* Ensure we can't create it unless we force it to */
- cl_git_fail(git_reference_symbolic_create(&ref, g_repo, ref_name, ref_master_name, 0, NULL, NULL));
- cl_git_pass(git_reference_symbolic_create(&ref, g_repo, ref_name, ref_master_name, 1, NULL, NULL));
+ cl_git_fail(git_reference_symbolic_create(&ref, g_repo, ref_name, ref_master_name, 0, NULL));
+ cl_git_pass(git_reference_symbolic_create(&ref, g_repo, ref_name, ref_master_name, 1, NULL));
git_reference_free(ref);
/* Ensure it points to the right place */
@@ -63,7 +63,7 @@ void test_refs_overwrite__object_id(void)
git_reference_free(ref);
/* Create it */
- cl_git_pass(git_reference_create(&ref, g_repo, ref_name, &id, 0, NULL, NULL));
+ cl_git_pass(git_reference_create(&ref, g_repo, ref_name, &id, 0, NULL));
git_reference_free(ref);
cl_git_pass(git_reference_lookup(&ref, g_repo, ref_test_name));
@@ -72,8 +72,8 @@ void test_refs_overwrite__object_id(void)
git_reference_free(ref);
/* Ensure we can't overwrite unless we force it */
- cl_git_fail(git_reference_create(&ref, g_repo, ref_name, &id, 0, NULL, NULL));
- cl_git_pass(git_reference_create(&ref, g_repo, ref_name, &id, 1, NULL, NULL));
+ cl_git_fail(git_reference_create(&ref, g_repo, ref_name, &id, 0, NULL));
+ cl_git_pass(git_reference_create(&ref, g_repo, ref_name, &id, 1, NULL));
git_reference_free(ref);
/* Ensure it has been overwritten */
@@ -94,10 +94,10 @@ void test_refs_overwrite__object_id_with_symbolic(void)
git_oid_cpy(&id, git_reference_target(ref));
git_reference_free(ref);
- cl_git_pass(git_reference_create(&ref, g_repo, ref_name, &id, 0, NULL, NULL));
+ cl_git_pass(git_reference_create(&ref, g_repo, ref_name, &id, 0, NULL));
git_reference_free(ref);
- cl_git_fail(git_reference_symbolic_create(&ref, g_repo, ref_name, ref_master_name, 0, NULL, NULL));
- cl_git_pass(git_reference_symbolic_create(&ref, g_repo, ref_name, ref_master_name, 1, NULL, NULL));
+ cl_git_fail(git_reference_symbolic_create(&ref, g_repo, ref_name, ref_master_name, 0, NULL));
+ cl_git_pass(git_reference_symbolic_create(&ref, g_repo, ref_name, ref_master_name, 1, NULL));
git_reference_free(ref);
/* Ensure it points to the right place */
@@ -120,11 +120,11 @@ void test_refs_overwrite__symbolic_with_object_id(void)
git_reference_free(ref);
/* Create the symbolic ref */
- cl_git_pass(git_reference_symbolic_create(&ref, g_repo, ref_name, ref_master_name, 0, NULL, NULL));
+ cl_git_pass(git_reference_symbolic_create(&ref, g_repo, ref_name, ref_master_name, 0, NULL));
git_reference_free(ref);
/* It shouldn't overwrite unless we tell it to */
- cl_git_fail(git_reference_create(&ref, g_repo, ref_name, &id, 0, NULL, NULL));
- cl_git_pass(git_reference_create(&ref, g_repo, ref_name, &id, 1, NULL, NULL));
+ cl_git_fail(git_reference_create(&ref, g_repo, ref_name, &id, 0, NULL));
+ cl_git_pass(git_reference_create(&ref, g_repo, ref_name, &id, 1, NULL));
git_reference_free(ref);
/* Ensure it points to the right place */
diff --git a/tests/refs/pack.c b/tests/refs/pack.c
index dbe377d7f..7dfaf6d8f 100644
--- a/tests/refs/pack.c
+++ b/tests/refs/pack.c
@@ -93,11 +93,11 @@ void test_refs_pack__symbolic(void)
for (i = 0; i < 100; ++i) {
p_snprintf(name, sizeof(name), "refs/heads/symbolic-%03d", i);
cl_git_pass(git_reference_symbolic_create(
- &ref, g_repo, name, "refs/heads/master", 0, NULL, NULL));
+ &ref, g_repo, name, "refs/heads/master", 0, NULL));
git_reference_free(ref);
p_snprintf(name, sizeof(name), "refs/heads/direct-%03d", i);
- cl_git_pass(git_reference_create(&ref, g_repo, name, &head, 0, NULL, NULL));
+ cl_git_pass(git_reference_create(&ref, g_repo, name, &head, 0, NULL));
git_reference_free(ref);
}
diff --git a/tests/refs/races.c b/tests/refs/races.c
index 643290a8e..fbecf4a75 100644
--- a/tests/refs/races.c
+++ b/tests/refs/races.c
@@ -30,11 +30,11 @@ void test_refs_races__create_matching(void)
git_oid_fromstr(&id, commit_id);
git_oid_fromstr(&other_id, other_commit_id);
- cl_git_fail_with(GIT_EMODIFIED, git_reference_create_matching(&ref, g_repo, refname, &other_id, 1, &other_id, NULL, NULL));
+ cl_git_fail_with(GIT_EMODIFIED, git_reference_create_matching(&ref, g_repo, refname, &other_id, 1, &other_id, NULL));
cl_git_pass(git_reference_lookup(&ref, g_repo, refname));
- cl_git_pass(git_reference_create_matching(&ref2, g_repo, refname, &other_id, 1, &id, NULL, NULL));
- cl_git_fail_with(GIT_EMODIFIED, git_reference_set_target(&ref3, ref, &other_id, NULL, NULL));
+ cl_git_pass(git_reference_create_matching(&ref2, g_repo, refname, &other_id, 1, &id, NULL));
+ cl_git_fail_with(GIT_EMODIFIED, git_reference_set_target(&ref3, ref, &other_id, NULL));
git_reference_free(ref);
git_reference_free(ref2);
@@ -49,11 +49,11 @@ void test_refs_races__symbolic_create_matching(void)
git_oid_fromstr(&id, commit_id);
git_oid_fromstr(&other_id, other_commit_id);
- cl_git_fail_with(GIT_EMODIFIED, git_reference_symbolic_create_matching(&ref, g_repo, "HEAD", other_refname, 1, other_refname, NULL, NULL));
+ cl_git_fail_with(GIT_EMODIFIED, git_reference_symbolic_create_matching(&ref, g_repo, "HEAD", other_refname, 1, other_refname, NULL));
cl_git_pass(git_reference_lookup(&ref, g_repo, "HEAD"));
- cl_git_pass(git_reference_symbolic_create_matching(&ref2, g_repo, "HEAD", other_refname, 1, NULL, NULL, refname));
- cl_git_fail_with(GIT_EMODIFIED, git_reference_symbolic_set_target(&ref3, ref, other_refname, NULL, NULL));
+ cl_git_pass(git_reference_symbolic_create_matching(&ref2, g_repo, "HEAD", other_refname, 1, NULL, refname));
+ cl_git_fail_with(GIT_EMODIFIED, git_reference_symbolic_set_target(&ref3, ref, other_refname, NULL));
git_reference_free(ref);
git_reference_free(ref2);
@@ -75,18 +75,18 @@ void test_refs_races__delete(void)
/* We cannot delete a symbolic value that doesn't match */
cl_git_pass(git_reference_lookup(&ref, g_repo, "HEAD"));
- cl_git_pass(git_reference_symbolic_create_matching(&ref2, g_repo, "HEAD", other_refname, 1, NULL, NULL, refname));
+ cl_git_pass(git_reference_symbolic_create_matching(&ref2, g_repo, "HEAD", other_refname, 1, NULL, refname));
cl_git_fail_with(GIT_EMODIFIED, git_reference_delete(ref));
git_reference_free(ref);
git_reference_free(ref2);
- cl_git_pass(git_reference_create(&ref, g_repo, refname, &id, 1, NULL, NULL));
+ cl_git_pass(git_reference_create(&ref, g_repo, refname, &id, 1, NULL));
git_reference_free(ref);
/* We cannot delete an oid value that doesn't match */
cl_git_pass(git_reference_lookup(&ref, g_repo, refname));
- cl_git_pass(git_reference_create_matching(&ref2, g_repo, refname, &other_id, 1, &id, NULL, NULL));
+ cl_git_pass(git_reference_create_matching(&ref2, g_repo, refname, &other_id, 1, &id, NULL));
cl_git_fail_with(GIT_EMODIFIED, git_reference_delete(ref));
git_reference_free(ref);
@@ -103,19 +103,19 @@ void test_refs_races__switch_oid_to_symbolic(void)
/* Removing a direct ref when it's currently symbolic should fail */
cl_git_pass(git_reference_lookup(&ref, g_repo, refname));
- cl_git_pass(git_reference_symbolic_create(&ref2, g_repo, refname, other_refname, 1, NULL, NULL));
+ cl_git_pass(git_reference_symbolic_create(&ref2, g_repo, refname, other_refname, 1, NULL));
cl_git_fail_with(GIT_EMODIFIED, git_reference_delete(ref));
git_reference_free(ref);
git_reference_free(ref2);
- cl_git_pass(git_reference_create(&ref, g_repo, refname, &id, 1, NULL, NULL));
+ cl_git_pass(git_reference_create(&ref, g_repo, refname, &id, 1, NULL));
git_reference_free(ref);
/* Updating a direct ref when it's currently symbolic should fail */
cl_git_pass(git_reference_lookup(&ref, g_repo, refname));
- cl_git_pass(git_reference_symbolic_create(&ref2, g_repo, refname, other_refname, 1, NULL, NULL));
- cl_git_fail_with(GIT_EMODIFIED, git_reference_set_target(&ref3, ref, &other_id, NULL, NULL));
+ cl_git_pass(git_reference_symbolic_create(&ref2, g_repo, refname, other_refname, 1, NULL));
+ cl_git_fail_with(GIT_EMODIFIED, git_reference_set_target(&ref3, ref, &other_id, NULL));
git_reference_free(ref);
git_reference_free(ref2);
@@ -132,19 +132,19 @@ void test_refs_races__switch_symbolic_to_oid(void)
/* Removing a symbolic ref when it's currently direct should fail */
cl_git_pass(git_reference_lookup(&ref, g_repo, "HEAD"));
- cl_git_pass(git_reference_create(&ref2, g_repo, "HEAD", &id, 1, NULL, NULL));
+ cl_git_pass(git_reference_create(&ref2, g_repo, "HEAD", &id, 1, NULL));
cl_git_fail_with(GIT_EMODIFIED, git_reference_delete(ref));
git_reference_free(ref);
git_reference_free(ref2);
- cl_git_pass(git_reference_symbolic_create(&ref, g_repo, "HEAD", refname, 1, NULL, NULL));
+ cl_git_pass(git_reference_symbolic_create(&ref, g_repo, "HEAD", refname, 1, NULL));
git_reference_free(ref);
/* Updating a symbolic ref when it's currently direct should fail */
cl_git_pass(git_reference_lookup(&ref, g_repo, "HEAD"));
- cl_git_pass(git_reference_create(&ref2, g_repo, "HEAD", &id, 1, NULL, NULL));
- cl_git_fail_with(GIT_EMODIFIED, git_reference_symbolic_set_target(&ref3, ref, other_refname, NULL, NULL));
+ cl_git_pass(git_reference_create(&ref2, g_repo, "HEAD", &id, 1, NULL));
+ cl_git_fail_with(GIT_EMODIFIED, git_reference_symbolic_set_target(&ref3, ref, other_refname, NULL));
git_reference_free(ref);
git_reference_free(ref2);
diff --git a/tests/refs/reflog/reflog.c b/tests/refs/reflog/reflog.c
index 792b0f05d..56ec422c3 100644
--- a/tests/refs/reflog/reflog.c
+++ b/tests/refs/reflog/reflog.c
@@ -82,7 +82,7 @@ void test_refs_reflog_reflog__append_then_read(void)
/* Create a new branch pointing at the HEAD */
git_oid_fromstr(&oid, current_master_tip);
- cl_git_pass(git_reference_create(&ref, g_repo, new_ref, &oid, 0, NULL, NULL));
+ cl_git_pass(git_reference_create(&ref, g_repo, new_ref, &oid, 0, NULL));
git_reference_free(ref);
cl_git_pass(git_signature_now(&committer, "foo", "foo@bar"));
@@ -114,7 +114,7 @@ void test_refs_reflog_reflog__renaming_the_reference_moves_the_reflog(void)
cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&moved_log_path)));
cl_git_pass(git_reference_lookup(&master, g_repo, "refs/heads/master"));
- cl_git_pass(git_reference_rename(&new_master, master, "refs/moved", 0, NULL, NULL));
+ cl_git_pass(git_reference_rename(&new_master, master, "refs/moved", 0, NULL));
git_reference_free(master);
cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&master_log_path)));
@@ -165,7 +165,7 @@ void test_refs_reflog_reflog__cannot_write_a_moved_reflog(void)
cl_git_pass(git_reflog_write(reflog));
- cl_git_pass(git_reference_rename(&new_master, master, "refs/moved", 0, NULL, NULL));
+ cl_git_pass(git_reference_rename(&new_master, master, "refs/moved", 0, NULL));
git_reference_free(master);
cl_git_fail(git_reflog_write(reflog));
@@ -189,11 +189,11 @@ void test_refs_reflog_reflog__write_only_std_locations(void)
git_oid_fromstr(&id, current_master_tip);
- cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/foo", &id, 1, NULL, NULL));
+ cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/foo", &id, 1, NULL));
git_reference_free(ref);
- cl_git_pass(git_reference_create(&ref, g_repo, "refs/tags/foo", &id, 1, NULL, NULL));
+ cl_git_pass(git_reference_create(&ref, g_repo, "refs/tags/foo", &id, 1, NULL));
git_reference_free(ref);
- cl_git_pass(git_reference_create(&ref, g_repo, "refs/notes/foo", &id, 1, NULL, NULL));
+ cl_git_pass(git_reference_create(&ref, g_repo, "refs/notes/foo", &id, 1, NULL));
git_reference_free(ref);
assert_has_reflog(true, "refs/heads/foo");
@@ -210,7 +210,7 @@ void test_refs_reflog_reflog__write_when_explicitly_active(void)
git_oid_fromstr(&id, current_master_tip);
git_reference_ensure_log(g_repo, "refs/tags/foo");
- cl_git_pass(git_reference_create(&ref, g_repo, "refs/tags/foo", &id, 1, NULL, NULL));
+ cl_git_pass(git_reference_create(&ref, g_repo, "refs/tags/foo", &id, 1, NULL));
git_reference_free(ref);
assert_has_reflog(true, "refs/tags/foo");
}
@@ -228,7 +228,7 @@ void test_refs_reflog_reflog__append_to_HEAD_when_changing_current_branch(void)
/* Move it back */
git_oid_fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
- cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/master", &id, 1, NULL, NULL));
+ cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/master", &id, 1, NULL));
git_reference_free(ref);
cl_git_pass(git_reflog_read(&log, g_repo, "HEAD"));
@@ -250,7 +250,7 @@ void test_refs_reflog_reflog__do_not_append_when_no_update(void)
cl_git_pass(git_reference_lookup(&ref, g_repo, "refs/heads/master"));
cl_git_pass(git_reference_create(&ref2, g_repo, "refs/heads/master",
- git_reference_target(ref), 1, NULL, NULL));
+ git_reference_target(ref), 1, NULL));
git_reference_free(ref);
git_reference_free(ref2);
@@ -280,7 +280,7 @@ static void assert_no_reflog_update(void)
/* Move it back */
git_oid_fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
- cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/master", &id, 1, NULL, NULL));
+ cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/master", &id, 1, NULL));
git_reference_free(ref);
cl_git_pass(git_reflog_read(&log, g_repo, "HEAD"));
diff --git a/tests/refs/rename.c b/tests/refs/rename.c
index c7901bd8b..6106e6c67 100644
--- a/tests/refs/rename.c
+++ b/tests/refs/rename.c
@@ -22,6 +22,7 @@ static git_repository *g_repo;
void test_refs_rename__initialize(void)
{
g_repo = cl_git_sandbox_init("testrepo");
+ cl_git_pass(git_repository_set_ident(g_repo, "me", "foo@example.com"));
}
void test_refs_rename__cleanup(void)
@@ -49,7 +50,7 @@ void test_refs_rename__loose(void)
cl_assert(reference_is_packed(looked_up_ref) == 0);
/* Now that the reference is renamed... */
- cl_git_pass(git_reference_rename(&new_ref, looked_up_ref, new_name, 0, NULL, NULL));
+ cl_git_pass(git_reference_rename(&new_ref, looked_up_ref, new_name, 0, NULL));
cl_assert_equal_s(new_ref->name, new_name);
git_reference_free(looked_up_ref);
@@ -91,7 +92,7 @@ void test_refs_rename__packed(void)
cl_assert(reference_is_packed(looked_up_ref) != 0);
/* Now that the reference is renamed... */
- cl_git_pass(git_reference_rename(&new_ref, looked_up_ref, brand_new_name, 0, NULL, NULL));
+ cl_git_pass(git_reference_rename(&new_ref, looked_up_ref, brand_new_name, 0, NULL));
cl_assert_equal_s(new_ref->name, brand_new_name);
git_reference_free(looked_up_ref);
@@ -140,7 +141,7 @@ void test_refs_rename__packed_doesnt_pack_others(void)
cl_assert(reference_is_packed(looked_up_ref) != 0);
/* Now that the reference is renamed... */
- cl_git_pass(git_reference_rename(&renamed_ref, looked_up_ref, brand_new_name, 0, NULL, NULL));
+ cl_git_pass(git_reference_rename(&renamed_ref, looked_up_ref, brand_new_name, 0, NULL));
git_reference_free(looked_up_ref);
/* Lookup the other reference */
@@ -166,7 +167,7 @@ void test_refs_rename__name_collision(void)
cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, packed_head_name));
/* Can not be renamed to the name of another existing reference. */
- cl_git_fail(git_reference_rename(&renamed_ref, looked_up_ref, packed_test_head_name, 0, NULL, NULL));
+ cl_git_fail(git_reference_rename(&renamed_ref, looked_up_ref, packed_test_head_name, 0, NULL));
git_reference_free(looked_up_ref);
/* Failure to rename it hasn't corrupted its state */
@@ -187,12 +188,12 @@ void test_refs_rename__invalid_name(void)
/* Can not be renamed with an invalid name. */
cl_assert_equal_i(
GIT_EINVALIDSPEC,
- git_reference_rename(&renamed_ref, looked_up_ref, "Hello! I'm a very invalid name.", 0, NULL, NULL));
+ git_reference_rename(&renamed_ref, looked_up_ref, "Hello! I'm a very invalid name.", 0, NULL));
/* Can not be renamed outside of the refs hierarchy
* unless it's ALL_CAPS_AND_UNDERSCORES.
*/
- cl_assert_equal_i(GIT_EINVALIDSPEC, git_reference_rename(&renamed_ref, looked_up_ref, "i-will-sudo-you", 0, NULL, NULL));
+ cl_assert_equal_i(GIT_EINVALIDSPEC, git_reference_rename(&renamed_ref, looked_up_ref, "i-will-sudo-you", 0, NULL));
/* Failure to rename it hasn't corrupted its state */
git_reference_free(looked_up_ref);
@@ -213,7 +214,7 @@ void test_refs_rename__force_loose_packed(void)
git_oid_cpy(&oid, git_reference_target(looked_up_ref));
/* Can be force-renamed to the name of another existing reference. */
- cl_git_pass(git_reference_rename(&renamed_ref, looked_up_ref, packed_test_head_name, 1, NULL, NULL));
+ cl_git_pass(git_reference_rename(&renamed_ref, looked_up_ref, packed_test_head_name, 1, NULL));
git_reference_free(looked_up_ref);
git_reference_free(renamed_ref);
@@ -238,7 +239,7 @@ void test_refs_rename__force_loose(void)
git_oid_cpy(&oid, git_reference_target(looked_up_ref));
/* Can be force-renamed to the name of another existing reference. */
- cl_git_pass(git_reference_rename(&renamed_ref, looked_up_ref, "refs/heads/test", 1, NULL, NULL));
+ cl_git_pass(git_reference_rename(&renamed_ref, looked_up_ref, "refs/heads/test", 1, NULL));
git_reference_free(looked_up_ref);
git_reference_free(renamed_ref);
@@ -268,15 +269,15 @@ void test_refs_rename__overwrite(void)
git_oid_cpy(&id, git_reference_target(ref));
/* Create loose references */
- cl_git_pass(git_reference_create(&ref_one, g_repo, ref_one_name, &id, 0, NULL, NULL));
- cl_git_pass(git_reference_create(&ref_two, g_repo, ref_two_name, &id, 0, NULL, NULL));
+ cl_git_pass(git_reference_create(&ref_one, g_repo, ref_one_name, &id, 0, NULL));
+ cl_git_pass(git_reference_create(&ref_two, g_repo, ref_two_name, &id, 0, NULL));
/* Pack everything */
cl_git_pass(git_repository_refdb(&refdb, g_repo));
cl_git_pass(git_refdb_compress(refdb));
/* Attempt to create illegal reference */
- cl_git_fail(git_reference_create(&ref_one_new, g_repo, ref_one_name_new, &id, 0, NULL, NULL));
+ cl_git_fail(git_reference_create(&ref_one_new, g_repo, ref_one_name_new, &id, 0, NULL));
/* Illegal reference couldn't be created so this is supposed to fail */
cl_git_fail(git_reference_lookup(&ref_one_new, g_repo, ref_one_name_new));
@@ -301,13 +302,13 @@ void test_refs_rename__prefix(void)
git_oid_cpy(&id, git_reference_target(ref));
/* Create loose references */
- cl_git_pass(git_reference_create(&ref_two, g_repo, ref_two_name, &id, 0, NULL, NULL));
+ cl_git_pass(git_reference_create(&ref_two, g_repo, ref_two_name, &id, 0, NULL));
/* An existing reference... */
cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, ref_two_name));
/* Can be rename to a new name starting with the old name. */
- cl_git_pass(git_reference_rename(&renamed_ref, looked_up_ref, ref_two_name_new, 0, NULL, NULL));
+ cl_git_pass(git_reference_rename(&renamed_ref, looked_up_ref, ref_two_name_new, 0, NULL));
git_reference_free(looked_up_ref);
git_reference_free(renamed_ref);
@@ -334,14 +335,14 @@ void test_refs_rename__move_up(void)
git_oid_cpy(&id, git_reference_target(ref));
/* Create loose references */
- cl_git_pass(git_reference_create(&ref_two, g_repo, ref_two_name_new, &id, 0, NULL, NULL));
+ cl_git_pass(git_reference_create(&ref_two, g_repo, ref_two_name_new, &id, 0, NULL));
git_reference_free(ref_two);
/* An existing reference... */
cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, ref_two_name_new));
/* Can be renamed upward the reference tree. */
- cl_git_pass(git_reference_rename(&renamed_ref, looked_up_ref, ref_two_name, 0, NULL, NULL));
+ cl_git_pass(git_reference_rename(&renamed_ref, looked_up_ref, ref_two_name, 0, NULL));
git_reference_free(looked_up_ref);
git_reference_free(renamed_ref);
@@ -361,7 +362,7 @@ void test_refs_rename__propagate_eexists(void)
cl_git_pass(git_reference_lookup(&ref, g_repo, packed_head_name));
- cl_assert_equal_i(GIT_EEXISTS, git_reference_rename(&new_ref, ref, packed_test_head_name, 0, NULL, NULL));
+ cl_assert_equal_i(GIT_EEXISTS, git_reference_rename(&new_ref, ref, packed_test_head_name, 0, NULL));
git_reference_free(ref);
}
@@ -371,13 +372,10 @@ void test_refs_rename__writes_to_reflog(void)
git_reference *ref, *new_ref;
git_reflog *log;
const git_reflog_entry *entry;
- git_signature *sig;
-
- cl_git_pass(git_signature_now(&sig, "me", "foo@example.com"));
cl_git_pass(git_reference_lookup(&ref, g_repo, ref_master_name));
cl_git_pass(git_reference_rename(&new_ref, ref, ref_one_name_new, false,
- sig, "message"));
+ "message"));
cl_git_pass(git_reflog_read(&log, g_repo, git_reference_name(new_ref)));
entry = git_reflog_entry_byindex(log, 0);
cl_assert_equal_s("message", git_reflog_entry_message(entry));
@@ -386,5 +384,4 @@ void test_refs_rename__writes_to_reflog(void)
git_reflog_free(log);
git_reference_free(ref);
git_reference_free(new_ref);
- git_signature_free(sig);
}
diff --git a/tests/refs/revparse.c b/tests/refs/revparse.c
index 94e55bda4..3f89b5f77 100644
--- a/tests/refs/revparse.c
+++ b/tests/refs/revparse.c
@@ -325,7 +325,7 @@ static void create_fake_stash_reference_and_reflog(git_repository *repo)
cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&log_path)));
cl_git_pass(git_reference_lookup(&master, repo, "refs/heads/master"));
- cl_git_pass(git_reference_rename(&new_master, master, "refs/fakestash", 0, NULL, NULL));
+ cl_git_pass(git_reference_rename(&new_master, master, "refs/fakestash", 0, NULL));
git_reference_free(master);
cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&log_path)));
@@ -597,7 +597,7 @@ void test_refs_revparse__issue_994(void)
"refs/remotes/origin/bim_with_3d@11296",
git_reference_target(head),
0,
- NULL, NULL));
+ NULL));
cl_git_pass(git_revparse_single(&target, repo, "origin/bim_with_3d@11296"));
git_object_free(target);
@@ -634,7 +634,7 @@ void test_refs_revparse__try_to_retrieve_branch_before_described_tag(void)
test_object_inrepo("blah-7-gc47800c", "c47800c7266a2be04c571c04d5a6614691ea99bd", repo);
cl_git_pass(git_revparse_single(&target, repo, "HEAD~3"));
- cl_git_pass(git_branch_create(&branch, repo, "blah-7-gc47800c", (git_commit *)target, 0, NULL, NULL));
+ cl_git_pass(git_branch_create(&branch, repo, "blah-7-gc47800c", (git_commit *)target, 0));
git_oid_tostr(sha, GIT_OID_HEXSZ + 1, git_object_id(target));
@@ -672,7 +672,7 @@ void test_refs_revparse__try_to_retrieve_sha_before_branch(void)
test_object_inrepo("a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", repo);
cl_git_pass(git_revparse_single(&target, repo, "HEAD~3"));
- cl_git_pass(git_branch_create(&branch, repo, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", (git_commit *)target, 0, NULL, NULL));
+ cl_git_pass(git_branch_create(&branch, repo, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", (git_commit *)target, 0));
git_oid_tostr(sha, GIT_OID_HEXSZ + 1, git_object_id(target));
@@ -708,7 +708,7 @@ void test_refs_revparse__try_to_retrieve_branch_before_abbrev_sha(void)
test_object_inrepo("c47800", "c47800c7266a2be04c571c04d5a6614691ea99bd", repo);
cl_git_pass(git_revparse_single(&target, repo, "HEAD~3"));
- cl_git_pass(git_branch_create(&branch, repo, "c47800", (git_commit *)target, 0, NULL, NULL));
+ cl_git_pass(git_branch_create(&branch, repo, "c47800", (git_commit *)target, 0));
git_oid_tostr(sha, GIT_OID_HEXSZ + 1, git_object_id(target));
diff --git a/tests/refs/settargetwithlog.c b/tests/refs/settargetwithlog.c
index 3a3378186..58fbb5fee 100644
--- a/tests/refs/settargetwithlog.c
+++ b/tests/refs/settargetwithlog.c
@@ -25,7 +25,6 @@ void test_refs_settargetwithlog__updating_a_direct_reference_adds_a_reflog_entry
{
git_reference *reference, *reference_out;
git_oid current_id, target_id;
- git_signature *signature;
git_reflog *reflog;
const git_reflog_entry *entry;
@@ -36,10 +35,8 @@ void test_refs_settargetwithlog__updating_a_direct_reference_adds_a_reflog_entry
cl_git_pass(git_reference_lookup(&reference, g_repo, br2_name));
- cl_git_pass(git_signature_now(&signature, "foo", "foo@bar"));
-
cl_git_pass(git_reference_set_target(
- &reference_out, reference, &target_id, signature, message));
+ &reference_out, reference, &target_id, message));
cl_git_pass(git_reflog_read(&reflog, g_repo, br2_name));
@@ -51,5 +48,4 @@ void test_refs_settargetwithlog__updating_a_direct_reference_adds_a_reflog_entry
git_reflog_free(reflog);
git_reference_free(reference_out);
git_reference_free(reference);
- git_signature_free(signature);
}
diff --git a/tests/refs/setter.c b/tests/refs/setter.c
index a5d073a56..2b42ff253 100644
--- a/tests/refs/setter.c
+++ b/tests/refs/setter.c
@@ -34,7 +34,7 @@ void test_refs_setter__update_direct(void)
cl_git_pass(git_reference_lookup(&test_ref, g_repo, ref_test_name));
cl_assert(git_reference_type(test_ref) == GIT_REF_OID);
- cl_git_pass(git_reference_set_target(&new_ref, test_ref, &id, NULL, NULL));
+ cl_git_pass(git_reference_set_target(&new_ref, test_ref, &id, NULL));
git_reference_free(test_ref);
git_reference_free(new_ref);
@@ -53,7 +53,7 @@ void test_refs_setter__update_symbolic(void)
cl_assert(git_reference_type(head) == GIT_REF_SYMBOLIC);
cl_assert(strcmp(git_reference_symbolic_target(head), ref_master_name) == 0);
- cl_git_pass(git_reference_symbolic_set_target(&new_head, head, ref_test_name, NULL, NULL));
+ cl_git_pass(git_reference_symbolic_set_target(&new_head, head, ref_test_name, NULL));
git_reference_free(new_head);
git_reference_free(head);
@@ -73,7 +73,7 @@ void test_refs_setter__cant_update_direct_with_symbolic(void)
cl_assert(git_reference_type(ref) == GIT_REF_OID);
git_oid_cpy(&id, git_reference_target(ref));
- cl_git_fail(git_reference_symbolic_set_target(&new, ref, ref_name, NULL, NULL));
+ cl_git_fail(git_reference_symbolic_set_target(&new, ref, ref_name, NULL));
git_reference_free(ref);
}
@@ -90,10 +90,10 @@ void test_refs_setter__cant_update_symbolic_with_direct(void)
git_reference_free(ref);
/* Create the symbolic ref */
- cl_git_pass(git_reference_symbolic_create(&ref, g_repo, ref_name, ref_master_name, 0, NULL, NULL));
+ cl_git_pass(git_reference_symbolic_create(&ref, g_repo, ref_name, ref_master_name, 0, NULL));
/* Can't set an OID on a direct ref */
- cl_git_fail(git_reference_set_target(&new, ref, &id, NULL, NULL));
+ cl_git_fail(git_reference_set_target(&new, ref, &id, NULL));
git_reference_free(ref);
}
diff --git a/tests/refs/unicode.c b/tests/refs/unicode.c
index 9c7527cd7..a279d5006 100644
--- a/tests/refs/unicode.c
+++ b/tests/refs/unicode.c
@@ -24,7 +24,7 @@ void test_refs_unicode__create_and_lookup(void)
/* Create the reference */
cl_git_pass(git_reference_lookup(&ref0, repo, master));
cl_git_pass(git_reference_create(
- &ref1, repo, REFNAME, git_reference_target(ref0), 0, NULL, NULL));
+ &ref1, repo, REFNAME, git_reference_target(ref0), 0, NULL));
cl_assert_equal_s(REFNAME, git_reference_name(ref1));
git_reference_free(ref0);
diff --git a/tests/refs/update.c b/tests/refs/update.c
index 873fc4ebe..403ea75b8 100644
--- a/tests/refs/update.c
+++ b/tests/refs/update.c
@@ -22,5 +22,5 @@ void test_refs_update__updating_the_target_of_a_symref_with_an_invalid_name_retu
cl_assert_equal_i(GIT_REF_SYMBOLIC, git_reference_type(head));
git_reference_free(head);
- cl_assert_equal_i(GIT_EINVALIDSPEC, git_reference_symbolic_create(&head, g_repo, GIT_HEAD_FILE, "refs/heads/inv@{id", 1, NULL, NULL));
+ cl_assert_equal_i(GIT_EINVALIDSPEC, git_reference_symbolic_create(&head, g_repo, GIT_HEAD_FILE, "refs/heads/inv@{id", 1, NULL));
}
diff --git a/tests/repo/head.c b/tests/repo/head.c
index d678e150e..b26d6acc7 100644
--- a/tests/repo/head.c
+++ b/tests/repo/head.c
@@ -3,11 +3,13 @@
#include "repo_helpers.h"
#include "posix.h"
+static const char *g_email = "foo@example.com";
static git_repository *repo;
void test_repo_head__initialize(void)
{
repo = cl_git_sandbox_init("testrepo.git");
+ cl_git_pass(git_repository_set_ident(repo, "Foo Bar", g_email));
}
void test_repo_head__cleanup(void)
@@ -33,24 +35,20 @@ static void check_last_reflog_entry(const char *email, const char *message)
void test_repo_head__head_detached(void)
{
git_reference *ref;
- git_signature *sig;
-
- cl_git_pass(git_signature_now(&sig, "Foo Bar", "foo@example.com"));
cl_assert_equal_i(false, git_repository_head_detached(repo));
- cl_git_pass(git_repository_detach_head(repo, sig, "CABLE DETACHED"));
- check_last_reflog_entry(sig->email, "CABLE DETACHED");
+ cl_git_pass(git_repository_detach_head(repo));
+ check_last_reflog_entry(g_email, "checkout: moving from master to a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
cl_assert_equal_i(true, git_repository_head_detached(repo));
/* take the repo back to it's original state */
cl_git_pass(git_reference_symbolic_create(&ref, repo, "HEAD", "refs/heads/master",
- true, sig, "REATTACH"));
+ true, "REATTACH"));
git_reference_free(ref);
- check_last_reflog_entry(sig->email, "REATTACH");
+ check_last_reflog_entry(g_email, "REATTACH");
cl_assert_equal_i(false, git_repository_head_detached(repo));
- git_signature_free(sig);
}
void test_repo_head__unborn_head(void)
@@ -65,7 +63,7 @@ void test_repo_head__unborn_head(void)
/* take the repo back to it's original state */
- cl_git_pass(git_reference_symbolic_create(&ref, repo, "HEAD", "refs/heads/master", 1, NULL, NULL));
+ cl_git_pass(git_reference_symbolic_create(&ref, repo, "HEAD", "refs/heads/master", 1, NULL));
cl_assert(git_repository_head_unborn(repo) == 0);
git_reference_free(ref);
@@ -75,7 +73,7 @@ void test_repo_head__set_head_Attaches_HEAD_to_un_unborn_branch_when_the_branch_
{
git_reference *head;
- cl_git_pass(git_repository_set_head(repo, "refs/heads/doesnt/exist/yet", NULL, NULL));
+ cl_git_pass(git_repository_set_head(repo, "refs/heads/doesnt/exist/yet"));
cl_assert_equal_i(false, git_repository_head_detached(repo));
@@ -84,19 +82,19 @@ void test_repo_head__set_head_Attaches_HEAD_to_un_unborn_branch_when_the_branch_
void test_repo_head__set_head_Returns_ENOTFOUND_when_the_reference_doesnt_exist(void)
{
- cl_assert_equal_i(GIT_ENOTFOUND, git_repository_set_head(repo, "refs/tags/doesnt/exist/yet", NULL, NULL));
+ cl_assert_equal_i(GIT_ENOTFOUND, git_repository_set_head(repo, "refs/tags/doesnt/exist/yet"));
}
void test_repo_head__set_head_Fails_when_the_reference_points_to_a_non_commitish(void)
{
- cl_git_fail(git_repository_set_head(repo, "refs/tags/point_to_blob", NULL, NULL));
+ cl_git_fail(git_repository_set_head(repo, "refs/tags/point_to_blob"));
}
void test_repo_head__set_head_Attaches_HEAD_when_the_reference_points_to_a_branch(void)
{
git_reference *head;
- cl_git_pass(git_repository_set_head(repo, "refs/heads/br2", NULL, NULL));
+ cl_git_pass(git_repository_set_head(repo, "refs/heads/br2"));
cl_assert_equal_i(false, git_repository_head_detached(repo));
@@ -123,7 +121,7 @@ static void assert_head_is_correctly_detached(void)
void test_repo_head__set_head_Detaches_HEAD_when_the_reference_doesnt_point_to_a_branch(void)
{
- cl_git_pass(git_repository_set_head(repo, "refs/tags/test", NULL, NULL));
+ cl_git_pass(git_repository_set_head(repo, "refs/tags/test"));
cl_assert_equal_i(true, git_repository_head_detached(repo));
@@ -136,7 +134,7 @@ void test_repo_head__set_head_detached_Return_ENOTFOUND_when_the_object_doesnt_e
cl_git_pass(git_oid_fromstr(&oid, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"));
- cl_assert_equal_i(GIT_ENOTFOUND, git_repository_set_head_detached(repo, &oid, NULL, NULL));
+ cl_assert_equal_i(GIT_ENOTFOUND, git_repository_set_head_detached(repo, &oid));
}
void test_repo_head__set_head_detached_Fails_when_the_object_isnt_a_commitish(void)
@@ -145,7 +143,7 @@ void test_repo_head__set_head_detached_Fails_when_the_object_isnt_a_commitish(vo
cl_git_pass(git_revparse_single(&blob, repo, "point_to_blob"));
- cl_git_fail(git_repository_set_head_detached(repo, git_object_id(blob), NULL, NULL));
+ cl_git_fail(git_repository_set_head_detached(repo, git_object_id(blob)));
git_object_free(blob);
}
@@ -157,7 +155,7 @@ void test_repo_head__set_head_detached_Detaches_HEAD_and_make_it_point_to_the_pe
cl_git_pass(git_revparse_single(&tag, repo, "tags/test"));
cl_assert_equal_i(GIT_OBJ_TAG, git_object_type(tag));
- cl_git_pass(git_repository_set_head_detached(repo, git_object_id(tag), NULL, NULL));
+ cl_git_pass(git_repository_set_head_detached(repo, git_object_id(tag)));
assert_head_is_correctly_detached();
@@ -168,7 +166,7 @@ void test_repo_head__detach_head_Detaches_HEAD_and_make_it_point_to_the_peeled_c
{
cl_assert_equal_i(false, git_repository_head_detached(repo));
- cl_git_pass(git_repository_detach_head(repo, NULL, NULL));
+ cl_git_pass(git_repository_detach_head(repo));
assert_head_is_correctly_detached();
}
@@ -177,9 +175,9 @@ void test_repo_head__detach_head_Fails_if_HEAD_and_point_to_a_non_commitish(void
{
git_reference *head;
- cl_git_pass(git_reference_symbolic_create(&head, repo, GIT_HEAD_FILE, "refs/tags/point_to_blob", 1, NULL, NULL));
+ cl_git_pass(git_reference_symbolic_create(&head, repo, GIT_HEAD_FILE, "refs/tags/point_to_blob", 1, NULL));
- cl_git_fail(git_repository_detach_head(repo, NULL, NULL));
+ cl_git_fail(git_repository_detach_head(repo));
git_reference_free(head);
}
@@ -188,7 +186,7 @@ void test_repo_head__detaching_an_unborn_branch_returns_GIT_EUNBORNBRANCH(void)
{
make_head_unborn(repo, NON_EXISTING_HEAD);
- cl_assert_equal_i(GIT_EUNBORNBRANCH, git_repository_detach_head(repo, NULL, NULL));
+ cl_assert_equal_i(GIT_EUNBORNBRANCH, git_repository_detach_head(repo));
}
void test_repo_head__retrieving_an_unborn_branch_returns_GIT_EUNBORNBRANCH(void)
@@ -256,15 +254,15 @@ void test_repo_head__setting_head_updates_reflog(void)
cl_git_pass(git_signature_now(&sig, "me", "foo@example.com"));
- cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked", sig, "message1"));
- cl_git_pass(git_repository_set_head(repo, "refs/heads/unborn", sig, "message2"));
+ cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked"));
+ cl_git_pass(git_repository_set_head(repo, "refs/heads/unborn"));
cl_git_pass(git_revparse_single(&tag, repo, "tags/test"));
- cl_git_pass(git_repository_set_head_detached(repo, git_object_id(tag), sig, "message3"));
- cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked", sig, "message4"));
+ cl_git_pass(git_repository_set_head_detached(repo, git_object_id(tag)));
+ cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked"));
- test_reflog(repo, 2, NULL, "refs/heads/haacked", "foo@example.com", "message1");
- test_reflog(repo, 1, NULL, "tags/test^{commit}", "foo@example.com", "message3");
- test_reflog(repo, 0, "tags/test^{commit}", "refs/heads/haacked", "foo@example.com", "message4");
+ test_reflog(repo, 2, NULL, "refs/heads/haacked", "foo@example.com", "checkout: moving from master to haacked");
+ test_reflog(repo, 1, NULL, "tags/test^{commit}", "foo@example.com", "checkout: moving from unborn to e90810b8df3e80c413d903f631643c716887138d");
+ test_reflog(repo, 0, "tags/test^{commit}", "refs/heads/haacked", "foo@example.com", "checkout: moving from e90810b8df3e80c413d903f631643c716887138d to haacked");
git_object_free(tag);
git_signature_free(sig);
@@ -299,14 +297,14 @@ void test_repo_head__detaching_writes_reflog(void)
cl_git_pass(git_signature_now(&sig, "me", "foo@example.com"));
- msg = "message1";
+ msg = "checkout: moving from master to e90810b8df3e80c413d903f631643c716887138d";
git_oid_fromstr(&id, "e90810b8df3e80c413d903f631643c716887138d");
- cl_git_pass(git_repository_set_head_detached(repo, &id, sig, msg));
+ cl_git_pass(git_repository_set_head_detached(repo, &id));
assert_head_reflog(repo, 0, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
"e90810b8df3e80c413d903f631643c716887138d", msg);
- msg = "message2";
- cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked", sig, msg));
+ msg = "checkout: moving from e90810b8df3e80c413d903f631643c716887138d to haacked";
+ cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked"));
assert_head_reflog(repo, 0, "e90810b8df3e80c413d903f631643c716887138d",
"258f0e2a959a364e40ed6603d5d44fbb24765b10", msg);
@@ -315,37 +313,30 @@ void test_repo_head__detaching_writes_reflog(void)
void test_repo_head__orphan_branch_does_not_count(void)
{
- git_signature *sig;
git_oid id;
const char *msg;
- cl_git_pass(git_signature_now(&sig, "me", "foo@example.com"));
-
/* Have something known */
- msg = "message1";
+ msg = "checkout: moving from master to e90810b8df3e80c413d903f631643c716887138d";
git_oid_fromstr(&id, "e90810b8df3e80c413d903f631643c716887138d");
- cl_git_pass(git_repository_set_head_detached(repo, &id, sig, msg));
+ cl_git_pass(git_repository_set_head_detached(repo, &id));
assert_head_reflog(repo, 0, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
"e90810b8df3e80c413d903f631643c716887138d", msg);
/* Switching to an orphan branch does not write tot he reflog */
- cl_git_pass(git_repository_set_head(repo, "refs/heads/orphan", sig, "ignored message"));
+ cl_git_pass(git_repository_set_head(repo, "refs/heads/orphan"));
assert_head_reflog(repo, 0, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
"e90810b8df3e80c413d903f631643c716887138d", msg);
/* And coming back, we set the source to zero */
- msg = "message2";
- cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked", sig, msg));
+ msg = "checkout: moving from orphan to haacked";
+ cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked"));
assert_head_reflog(repo, 0, "0000000000000000000000000000000000000000",
"258f0e2a959a364e40ed6603d5d44fbb24765b10", msg);
-
- git_signature_free(sig);
}
void test_repo_head__set_to_current_target(void)
{
- git_signature *sig;
- const char *msg;
git_reflog *log;
size_t nentries, nentries_after;
@@ -353,20 +344,14 @@ void test_repo_head__set_to_current_target(void)
nentries = git_reflog_entrycount(log);
git_reflog_free(log);
- cl_git_pass(git_signature_now(&sig, "me", "foo@example.com"));
-
- msg = "message 1";
- cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked", sig, msg));
- cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked", sig, msg));
+ cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked"));
+ cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked"));
cl_git_pass(git_reflog_read(&log, repo, GIT_HEAD_FILE));
nentries_after = git_reflog_entrycount(log);
git_reflog_free(log);
cl_assert_equal_i(nentries + 1, nentries_after);
-
- git_signature_free(sig);
-
}
void test_repo_head__branch_birth(void)
@@ -389,8 +374,7 @@ void test_repo_head__branch_birth(void)
cl_git_pass(git_reference_peel((git_object **) &tree, ref, GIT_OBJ_TREE));
git_reference_free(ref);
- msg = "message 1";
- cl_git_pass(git_repository_set_head(repo, "refs/heads/orphan", sig, msg));
+ cl_git_pass(git_repository_set_head(repo, "refs/heads/orphan"));
cl_git_pass(git_reflog_read(&log, repo, GIT_HEAD_FILE));
nentries_after = git_reflog_entrycount(log);
@@ -449,7 +433,7 @@ void test_repo_head__symref_chain(void)
nentries_master = entrycount(repo, "refs/heads/master");
msg = "message 1";
- cl_git_pass(git_reference_symbolic_create(&ref, repo, "refs/heads/master", "refs/heads/foo", 1, sig, msg));
+ cl_git_pass(git_reference_symbolic_create(&ref, repo, "refs/heads/master", "refs/heads/foo", 1, msg));
git_reference_free(ref);
cl_assert_equal_i(0, entrycount(repo, "refs/heads/foo"));
diff --git a/tests/repo/headtree.c b/tests/repo/headtree.c
index 79d88c0a7..e899ac399 100644
--- a/tests/repo/headtree.c
+++ b/tests/repo/headtree.c
@@ -20,7 +20,7 @@ void test_repo_headtree__cleanup(void)
void test_repo_headtree__can_retrieve_the_root_tree_from_a_detached_head(void)
{
- cl_git_pass(git_repository_detach_head(repo, NULL, NULL));
+ cl_git_pass(git_repository_detach_head(repo));
cl_git_pass(git_repository_head_tree(&tree, repo));
diff --git a/tests/repo/init.c b/tests/repo/init.c
index 076156817..525020f5a 100644
--- a/tests/repo/init.c
+++ b/tests/repo/init.c
@@ -3,6 +3,7 @@
#include "repository.h"
#include "config.h"
#include "path.h"
+#include "config/config_helpers.h"
enum repo_mode {
STANDARD_REPOSITORY = 0,
@@ -370,8 +371,6 @@ void test_repo_init__extended_1(void)
void test_repo_init__relative_gitdir(void)
{
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
- git_config *cfg;
- const char *worktree_path;
git_buf dot_git_content = GIT_BUF_INIT;
opts.workdir_path = "../c_wd";
@@ -391,24 +390,19 @@ void test_repo_init__relative_gitdir(void)
/* Verify that the gitlink and worktree entries are relative */
/* Verify worktree */
- cl_git_pass(git_repository_config(&cfg, _repo));
- cl_git_pass(git_config_get_string(&worktree_path, cfg, "core.worktree"));
- cl_assert_equal_s("../c_wd/", worktree_path);
+ assert_config_entry_value(_repo, "core.worktree", "../c_wd/");
/* Verify gitlink */
cl_git_pass(git_futils_readbuffer(&dot_git_content, "root/b/c_wd/.git"));
cl_assert_equal_s("gitdir: ../my_repository/", dot_git_content.ptr);
git_buf_free(&dot_git_content);
- git_config_free(cfg);
cleanup_repository("root");
}
void test_repo_init__relative_gitdir_2(void)
{
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
- git_config *cfg;
- const char *worktree_path;
git_buf dot_git_content = GIT_BUF_INIT;
git_buf full_path = GIT_BUF_INIT;
@@ -433,16 +427,13 @@ void test_repo_init__relative_gitdir_2(void)
/* Verify that the gitlink and worktree entries are relative */
/* Verify worktree */
- cl_git_pass(git_repository_config(&cfg, _repo));
- cl_git_pass(git_config_get_string(&worktree_path, cfg, "core.worktree"));
- cl_assert_equal_s("../c_wd/", worktree_path);
+ assert_config_entry_value(_repo, "core.worktree", "../c_wd/");
/* Verify gitlink */
cl_git_pass(git_futils_readbuffer(&dot_git_content, "root/b/c_wd/.git"));
cl_assert_equal_s("gitdir: ../my_repository/", dot_git_content.ptr);
git_buf_free(&dot_git_content);
- git_config_free(cfg);
cleanup_repository("root");
}
diff --git a/tests/repo/new.c b/tests/repo/new.c
new file mode 100644
index 000000000..d77e903f6
--- /dev/null
+++ b/tests/repo/new.c
@@ -0,0 +1,27 @@
+#include "clar_libgit2.h"
+#include "git2/sys/repository.h"
+
+void test_repo_new__has_nothing(void)
+{
+ git_repository *repo;
+
+ cl_git_pass(git_repository_new(&repo));
+ cl_assert_equal_b(true, git_repository_is_bare(repo));
+ cl_assert_equal_p(NULL, git_repository_path(repo));
+ cl_assert_equal_p(NULL, git_repository_workdir(repo));
+ git_repository_free(repo);
+}
+
+void test_repo_new__is_bare_until_workdir_set(void)
+{
+ git_repository *repo;
+
+ cl_git_pass(git_repository_new(&repo));
+ cl_assert_equal_b(true, git_repository_is_bare(repo));
+
+ cl_git_pass(git_repository_set_workdir(repo, clar_sandbox_path(), 0));
+ cl_assert_equal_b(false, git_repository_is_bare(repo));
+
+ git_repository_free(repo);
+}
+
diff --git a/tests/repo/repo_helpers.c b/tests/repo/repo_helpers.c
index 7c5db4a81..61f696865 100644
--- a/tests/repo/repo_helpers.c
+++ b/tests/repo/repo_helpers.c
@@ -7,7 +7,7 @@ void make_head_unborn(git_repository* repo, const char *target)
{
git_reference *head;
- cl_git_pass(git_reference_symbolic_create(&head, repo, GIT_HEAD_FILE, target, 1, NULL, NULL));
+ cl_git_pass(git_reference_symbolic_create(&head, repo, GIT_HEAD_FILE, target, 1, NULL));
git_reference_free(head);
}
diff --git a/tests/repo/setters.c b/tests/repo/setters.c
index f34f1e471..5a83fdbee 100644
--- a/tests/repo/setters.c
+++ b/tests/repo/setters.c
@@ -46,7 +46,7 @@ void test_repo_setters__setting_a_workdir_prettifies_its_path(void)
void test_repo_setters__setting_a_workdir_creates_a_gitlink(void)
{
git_config *cfg;
- const char *val;
+ git_buf buf = GIT_BUF_INIT;
git_buf content = GIT_BUF_INIT;
cl_git_pass(git_repository_set_workdir(repo, "./new_workdir", true));
@@ -59,8 +59,10 @@ void test_repo_setters__setting_a_workdir_creates_a_gitlink(void)
git_buf_free(&content);
cl_git_pass(git_repository_config(&cfg, repo));
- cl_git_pass(git_config_get_string(&val, cfg, "core.worktree"));
- cl_assert(git__suffixcmp(val, "new_workdir/") == 0);
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.worktree"));
+ cl_assert(git__suffixcmp(git_buf_cstr(&buf), "new_workdir/") == 0);
+
+ git_buf_free(&buf);
git_config_free(cfg);
}
diff --git a/tests/repo/state.c b/tests/repo/state.c
index 13407bffc..bf2633c17 100644
--- a/tests/repo/state.c
+++ b/tests/repo/state.c
@@ -37,7 +37,7 @@ void test_repo_state__none_with_HEAD_attached(void)
void test_repo_state__none_with_HEAD_detached(void)
{
- cl_git_pass(git_repository_detach_head(_repo, NULL, NULL));
+ cl_git_pass(git_repository_detach_head(_repo));
assert_repo_state(GIT_REPOSITORY_STATE_NONE);
}
diff --git a/tests/reset/hard.c b/tests/reset/hard.c
index e8cf10071..f6ca1037b 100644
--- a/tests/reset/hard.c
+++ b/tests/reset/hard.c
@@ -71,7 +71,7 @@ void test_reset_hard__resetting_reverts_modified_files(void)
cl_git_pass(git_revparse_single(&target, repo, "26a125e"));
- cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
for (i = 0; i < 4; ++i) {
cl_git_pass(git_buf_joinpath(&path, wd, files[i]));
@@ -96,7 +96,7 @@ void test_reset_hard__cannot_reset_in_a_bare_repository(void)
cl_git_pass(git_revparse_single(&target, bare, KNOWN_COMMIT_IN_BARE_REPO));
- cl_assert_equal_i(GIT_EBAREREPO, git_reset(bare, target, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_assert_equal_i(GIT_EBAREREPO, git_reset(bare, target, GIT_RESET_HARD, NULL));
git_repository_free(bare);
}
@@ -152,7 +152,7 @@ void test_reset_hard__resetting_reverts_unmerged(void)
cl_git_pass(git_index_write(index));
cl_git_pass(git_revparse_single(&target, repo, "26a125e"));
- cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
cl_assert(git_path_exists("status/conflicting_file") == 0);
@@ -183,7 +183,7 @@ void test_reset_hard__cleans_up_merge(void)
cl_git_mkfile(git_buf_cstr(&orig_head_path), "0017bd4ab1ec30440b17bae1680cff124ab5f1f6");
cl_git_pass(git_revparse_single(&target, repo, "0017bd4"));
- cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
cl_assert(!git_path_exists(git_buf_cstr(&merge_head_path)));
cl_assert(!git_path_exists(git_buf_cstr(&merge_msg_path)));
@@ -200,6 +200,7 @@ void test_reset_hard__cleans_up_merge(void)
void test_reset_hard__reflog_is_correct(void)
{
+ git_buf buf = GIT_BUF_INIT;
const char *exp_msg = "commit: Add a file which name should appear before the "
"\"subdir/\" folder while being dealt with by the treewalker";
@@ -208,25 +209,18 @@ void test_reset_hard__reflog_is_correct(void)
/* Branch not moving, no reflog entry */
cl_git_pass(git_revparse_single(&target, repo, "HEAD^{commit}"));
- cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
reflog_check(repo, "HEAD", 3, "emeric.fermas@gmail.com", exp_msg);
reflog_check(repo, "refs/heads/master", 3, "emeric.fermas@gmail.com", exp_msg);
git_object_free(target);
/* Moved branch, expect default message */
- exp_msg = "reset: moving";
cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}"));
- cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL, NULL, NULL));
- reflog_check(repo, "HEAD", 4, NULL, exp_msg);
- reflog_check(repo, "refs/heads/master", 4, NULL, exp_msg);
+ cl_git_pass(git_buf_printf(&buf, "reset: moving to %s", git_oid_tostr_s(git_object_id(target))));
+ cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
+ reflog_check(repo, "HEAD", 4, NULL, git_buf_cstr(&buf));
+ reflog_check(repo, "refs/heads/master", 4, NULL, git_buf_cstr(&buf));
- git_object_free(target);
-
- /* Moved branch, expect custom message */
- exp_msg = "message1";
- cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}"));
- cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL, NULL, "message1"));
- reflog_check(repo, "HEAD", 5, NULL, exp_msg);
- reflog_check(repo, "refs/heads/master", 5, NULL, exp_msg);
+ git_buf_free(&buf);
}
diff --git a/tests/reset/mixed.c b/tests/reset/mixed.c
index cb7a44d5f..b374902aa 100644
--- a/tests/reset/mixed.c
+++ b/tests/reset/mixed.c
@@ -29,7 +29,7 @@ void test_reset_mixed__cannot_reset_in_a_bare_repository(void)
cl_git_pass(git_revparse_single(&target, bare, KNOWN_COMMIT_IN_BARE_REPO));
- cl_assert_equal_i(GIT_EBAREREPO, git_reset(bare, target, GIT_RESET_MIXED, NULL, NULL, NULL));
+ cl_assert_equal_i(GIT_EBAREREPO, git_reset(bare, target, GIT_RESET_MIXED, NULL));
git_repository_free(bare);
}
@@ -42,7 +42,7 @@ void test_reset_mixed__resetting_refreshes_the_index_to_the_commit_tree(void)
cl_assert(status == GIT_STATUS_CURRENT);
cl_git_pass(git_revparse_single(&target, repo, "605812a"));
- cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL));
cl_git_pass(git_status_file(&status, repo, "macro_bad"));
cl_assert(status == GIT_STATUS_WT_NEW);
@@ -50,6 +50,7 @@ void test_reset_mixed__resetting_refreshes_the_index_to_the_commit_tree(void)
void test_reset_mixed__reflog_is_correct(void)
{
+ git_buf buf = GIT_BUF_INIT;
const char *exp_msg = "commit: Updating test data so we can test inter-hunk-context";
reflog_check(repo, "HEAD", 9, "yoram.harmelin@gmail.com", exp_msg);
@@ -57,7 +58,7 @@ void test_reset_mixed__reflog_is_correct(void)
/* Branch not moving, no reflog entry */
cl_git_pass(git_revparse_single(&target, repo, "HEAD^{commit}"));
- cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL));
reflog_check(repo, "HEAD", 9, "yoram.harmelin@gmail.com", exp_msg);
reflog_check(repo, "refs/heads/master", 9, "yoram.harmelin@gmail.com", exp_msg);
@@ -65,19 +66,12 @@ void test_reset_mixed__reflog_is_correct(void)
target = NULL;
/* Moved branch, expect default message */
- exp_msg = "reset: moving";
cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}"));
- cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL, NULL, NULL));
- reflog_check(repo, "HEAD", 10, NULL, exp_msg);
- reflog_check(repo, "refs/heads/master", 10, NULL, exp_msg);
+ git_buf_clear(&buf);
+ cl_git_pass(git_buf_printf(&buf, "reset: moving to %s", git_oid_tostr_s(git_object_id(target))));
+ cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL));
+ reflog_check(repo, "HEAD", 10, NULL, git_buf_cstr(&buf));
+ reflog_check(repo, "refs/heads/master", 10, NULL, git_buf_cstr(&buf));
- git_object_free(target);
- target = NULL;
-
- /* Moved branch, expect custom message */
- exp_msg = "message1";
- cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}"));
- cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL, NULL, "message1"));
- reflog_check(repo, "HEAD", 11, NULL, exp_msg);
- reflog_check(repo, "refs/heads/master", 11, NULL, exp_msg);
+ git_buf_free(&buf);
}
diff --git a/tests/reset/reset_helpers.c b/tests/reset/reset_helpers.c
index 7a335a600..e6acec9ef 100644
--- a/tests/reset/reset_helpers.c
+++ b/tests/reset/reset_helpers.c
@@ -7,12 +7,12 @@ void reflog_check(git_repository *repo, const char *refname,
git_reflog *log;
const git_reflog_entry *entry;
+ GIT_UNUSED(exp_email);
+
cl_git_pass(git_reflog_read(&log, repo, refname));
cl_assert_equal_i(exp_count, git_reflog_entrycount(log));
entry = git_reflog_entry_byindex(log, 0);
- if (exp_email)
- cl_assert_equal_s(exp_email, git_reflog_entry_committer(entry)->email);
if (exp_msg)
cl_assert_equal_s(exp_msg, git_reflog_entry_message(entry));
diff --git a/tests/reset/soft.c b/tests/reset/soft.c
index 95b86683a..a5bb13cc8 100644
--- a/tests/reset/soft.c
+++ b/tests/reset/soft.c
@@ -30,7 +30,7 @@ static void assert_reset_soft(bool should_be_detached)
cl_assert(git_repository_head_detached(repo) == should_be_detached);
- cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT, NULL));
cl_assert(git_repository_head_detached(repo) == should_be_detached);
@@ -45,7 +45,7 @@ void test_reset_soft__can_reset_the_non_detached_Head_to_the_specified_commit(vo
void test_reset_soft__can_reset_the_detached_Head_to_the_specified_commit(void)
{
- git_repository_detach_head(repo, NULL, NULL);
+ git_repository_detach_head(repo);
assert_reset_soft(true);
}
@@ -61,7 +61,7 @@ void test_reset_soft__resetting_to_the_commit_pointed_at_by_the_Head_does_not_ch
cl_git_pass(git_revparse_single(&target, repo, raw_head_oid));
- cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT, NULL));
cl_git_pass(git_reference_name_to_id(&oid, repo, "HEAD"));
cl_git_pass(git_oid_streq(&oid, raw_head_oid));
@@ -74,7 +74,7 @@ void test_reset_soft__resetting_to_a_tag_sets_the_Head_to_the_peeled_commit(void
/* b25fa35 is a tag, pointing to another tag which points to commit e90810b */
cl_git_pass(git_revparse_single(&target, repo, "b25fa35"));
- cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT, NULL));
cl_assert(git_repository_head_detached(repo) == false);
cl_git_pass(git_reference_name_to_id(&oid, repo, "HEAD"));
@@ -86,12 +86,12 @@ void test_reset_soft__cannot_reset_to_a_tag_not_pointing_at_a_commit(void)
/* 53fc32d is the tree of commit e90810b */
cl_git_pass(git_revparse_single(&target, repo, "53fc32d"));
- cl_git_fail(git_reset(repo, target, GIT_RESET_SOFT, NULL, NULL, NULL));
+ cl_git_fail(git_reset(repo, target, GIT_RESET_SOFT, NULL));
git_object_free(target);
/* 521d87c is an annotated tag pointing to a blob */
cl_git_pass(git_revparse_single(&target, repo, "521d87c"));
- cl_git_fail(git_reset(repo, target, GIT_RESET_SOFT, NULL, NULL, NULL));
+ cl_git_fail(git_reset(repo, target, GIT_RESET_SOFT, NULL));
}
void test_reset_soft__resetting_against_an_unborn_head_repo_makes_the_head_no_longer_unborn(void)
@@ -104,7 +104,7 @@ void test_reset_soft__resetting_against_an_unborn_head_repo_makes_the_head_no_lo
cl_assert_equal_i(true, git_repository_head_unborn(repo));
- cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT, NULL));
cl_assert_equal_i(false, git_repository_head_unborn(repo));
@@ -118,13 +118,13 @@ void test_reset_soft__fails_when_merging(void)
{
git_buf merge_head_path = GIT_BUF_INIT;
- cl_git_pass(git_repository_detach_head(repo, NULL, NULL));
+ cl_git_pass(git_repository_detach_head(repo));
cl_git_pass(git_buf_joinpath(&merge_head_path, git_repository_path(repo), "MERGE_HEAD"));
cl_git_mkfile(git_buf_cstr(&merge_head_path), "beefbeefbeefbeefbeefbeefbeefbeefbeefbeef\n");
cl_git_pass(git_revparse_single(&target, repo, KNOWN_COMMIT_IN_BARE_REPO));
- cl_assert_equal_i(GIT_EUNMERGED, git_reset(repo, target, GIT_RESET_SOFT, NULL, NULL, NULL));
+ cl_assert_equal_i(GIT_EUNMERGED, git_reset(repo, target, GIT_RESET_SOFT, NULL));
cl_git_pass(p_unlink(git_buf_cstr(&merge_head_path)));
git_buf_free(&merge_head_path);
@@ -152,7 +152,7 @@ void test_reset_soft__fails_when_index_contains_conflicts_independently_of_MERGE
cl_git_pass(git_reference_peel(&target, head, GIT_OBJ_COMMIT));
git_reference_free(head);
- cl_assert_equal_i(GIT_EUNMERGED, git_reset(repo, target, GIT_RESET_SOFT, NULL, NULL, NULL));
+ cl_assert_equal_i(GIT_EUNMERGED, git_reset(repo, target, GIT_RESET_SOFT, NULL));
}
void test_reset_soft_reflog_is_correct(void)
@@ -164,19 +164,19 @@ void test_reset_soft_reflog_is_correct(void)
/* Branch not moving, no reflog entry */
cl_git_pass(git_revparse_single(&target, repo, "HEAD^{commit}"));
- cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT, NULL));
reflog_check(repo, "HEAD", 9, "yoram.harmelin@gmail.com", exp_msg);
reflog_check(repo, "refs/heads/master", 9, "yoram.harmelin@gmail.com", exp_msg);
/* Moved branch, expect default message */
cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}"));
- cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT, NULL));
reflog_check(repo, "HEAD", 9, "yoram.harmelin@gmail.com", exp_msg);
reflog_check(repo, "refs/heads/master", 10, NULL, "reset: moving");
/* Moved branch, expect custom message */
cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}"));
- cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT, NULL, NULL, "message1"));
+ cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT, NULL));
reflog_check(repo, "HEAD", 9, "yoram.harmelin@gmail.com", exp_msg);
reflog_check(repo, "refs/heads/master", 11, NULL, "message1");
}
diff --git a/tests/revert/workdir.c b/tests/revert/workdir.c
index 6a7b335c4..171cacb25 100644
--- a/tests/revert/workdir.c
+++ b/tests/revert/workdir.c
@@ -48,7 +48,7 @@ void test_revert_workdir__automerge(void)
git_oid_fromstr(&head_oid, "72333f47d4e83616630ff3b0ffe4c0faebcc3c45");
cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
- cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
git_oid_fromstr(&revert_oid, "d1d403d22cbe24592d725f442835cf46fe60c8ac");
cl_git_pass(git_commit_lookup(&commit, repo, &revert_oid));
@@ -81,7 +81,7 @@ void test_revert_workdir__conflicts(void)
cl_git_pass(git_repository_head(&head_ref, repo));
cl_git_pass(git_reference_peel((git_object **)&head, head_ref, GIT_OBJ_COMMIT));
- cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
cl_git_pass(git_commit_lookup(&commit, repo, &revert_oid));
cl_git_pass(git_revert(repo, commit, NULL));
@@ -144,7 +144,7 @@ void test_revert_workdir__orphan(void)
git_oid_fromstr(&head_oid, "39467716290f6df775a91cdb9a4eb39295018145");
cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
- cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
git_oid_fromstr(&revert_oid, "ebb03002cee5d66c7732dd06241119fe72ab96a5");
cl_git_pass(git_commit_lookup(&commit, repo, &revert_oid));
@@ -179,7 +179,7 @@ void test_revert_workdir__again(void)
cl_git_pass(git_repository_head(&head_ref, repo));
cl_git_pass(git_reference_peel((git_object **)&orig_head, head_ref, GIT_OBJ_COMMIT));
- cl_git_pass(git_reset(repo, (git_object *)orig_head, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, (git_object *)orig_head, GIT_RESET_HARD, NULL));
cl_git_pass(git_revert(repo, orig_head, NULL));
@@ -227,7 +227,7 @@ void test_revert_workdir__again_after_automerge(void)
git_oid_fromstr(&head_oid, "72333f47d4e83616630ff3b0ffe4c0faebcc3c45");
cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
- cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
git_oid_fromstr(&revert_oid, "d1d403d22cbe24592d725f442835cf46fe60c8ac");
cl_git_pass(git_commit_lookup(&commit, repo, &revert_oid));
@@ -275,7 +275,7 @@ void test_revert_workdir__again_after_edit(void)
cl_git_pass(git_oid_fromstr(&orig_head_oid, "399fb3aba3d9d13f7d40a9254ce4402067ef3149"));
cl_git_pass(git_commit_lookup(&orig_head, repo, &orig_head_oid));
- cl_git_pass(git_reset(repo, (git_object *)orig_head, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, (git_object *)orig_head, GIT_RESET_HARD, NULL));
cl_git_pass(git_oid_fromstr(&revert_oid, "2d440f2b3147d3dc7ad1085813478d6d869d5a4d"));
cl_git_pass(git_commit_lookup(&commit, repo, &revert_oid));
@@ -324,7 +324,7 @@ void test_revert_workdir__again_after_edit_two(void)
cl_git_pass(git_oid_fromstr(&head_commit_oid, "75ec9929465623f17ff3ad68c0438ea56faba815"));
cl_git_pass(git_commit_lookup(&head_commit, repo, &head_commit_oid));
- cl_git_pass(git_reset(repo, (git_object *)head_commit, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, (git_object *)head_commit, GIT_RESET_HARD, NULL));
cl_git_pass(git_oid_fromstr(&revert_commit_oid, "97e52d5e81f541080cd6b92829fb85bc4d81d90b"));
cl_git_pass(git_commit_lookup(&revert_commit, repo, &revert_commit_oid));
@@ -377,7 +377,7 @@ void test_revert_workdir__conflict_use_ours(void)
git_oid_fromstr(&head_oid, "72333f47d4e83616630ff3b0ffe4c0faebcc3c45");
cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
- cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
git_oid_fromstr(&revert_oid, "d1d403d22cbe24592d725f442835cf46fe60c8ac");
cl_git_pass(git_commit_lookup(&commit, repo, &revert_oid));
@@ -413,7 +413,7 @@ void test_revert_workdir__rename_1_of_2(void)
git_oid_fromstr(&head_oid, "cef56612d71a6af8d8015691e4865f7fece905b5");
cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
- cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
git_oid_fromstr(&revert_oid, "55568c8de5322ff9a95d72747a239cdb64a19965");
cl_git_pass(git_commit_lookup(&commit, repo, &revert_oid));
@@ -447,7 +447,7 @@ void test_revert_workdir__rename(void)
git_oid_fromstr(&head_oid, "55568c8de5322ff9a95d72747a239cdb64a19965");
cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
- cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
git_oid_fromstr(&revert_oid, "0aa8c7e40d342fff78d60b29a4ba8e993ed79c51");
cl_git_pass(git_commit_lookup(&commit, repo, &revert_oid));
@@ -476,7 +476,7 @@ void test_revert_workdir__head(void)
/* HEAD is 2d440f2b3147d3dc7ad1085813478d6d869d5a4d */
cl_git_pass(git_repository_head(&head, repo));
cl_git_pass(git_reference_peel((git_object **)&commit, head, GIT_OBJ_COMMIT));
- cl_git_pass(git_reset(repo, (git_object *)commit, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, (git_object *)commit, GIT_RESET_HARD, NULL));
cl_git_pass(git_revert(repo, commit, NULL));
cl_assert(merge_test_index(repo_index, merge_index_entries, 4));
@@ -513,7 +513,7 @@ void test_revert_workdir__merge_fails_without_mainline_specified(void)
git_oid_fromstr(&head_oid, "5acdc74af27172ec491d213ee36cea7eb9ef2579");
cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
- cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
cl_must_fail(git_revert(repo, head, NULL));
cl_assert(!git_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG"));
@@ -540,7 +540,7 @@ void test_revert_workdir__merge_first_parent(void)
git_oid_fromstr(&head_oid, "5acdc74af27172ec491d213ee36cea7eb9ef2579");
cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
- cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
cl_git_pass(git_revert(repo, head, &opts));
@@ -565,7 +565,7 @@ void test_revert_workdir__merge_second_parent(void)
git_oid_fromstr(&head_oid, "5acdc74af27172ec491d213ee36cea7eb9ef2579");
cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
- cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL, NULL));
+ cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
cl_git_pass(git_revert(repo, head, &opts));
diff --git a/tests/stash/save.c b/tests/stash/save.c
index a5bdd0cbe..e07877516 100644
--- a/tests/stash/save.c
+++ b/tests/stash/save.c
@@ -195,7 +195,7 @@ void test_stash_save__cannot_stash_against_an_unborn_branch(void)
{
git_reference *head;
- cl_git_pass(git_reference_symbolic_create(&head, repo, "HEAD", "refs/heads/unborn", 1, NULL, NULL));
+ cl_git_pass(git_reference_symbolic_create(&head, repo, "HEAD", "refs/heads/unborn", 1, NULL));
cl_assert_equal_i(GIT_EUNBORNBRANCH,
git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_DEFAULT));
@@ -217,7 +217,7 @@ void test_stash_save__cannot_stash_against_a_bare_repository(void)
void test_stash_save__can_stash_against_a_detached_head(void)
{
- git_repository_detach_head(repo, NULL, NULL);
+ git_repository_detach_head(repo);
cl_git_pass(git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_DEFAULT));
@@ -399,3 +399,22 @@ void test_stash_save__skip_submodules(void)
assert_status(repo, "untracked_repo/", GIT_STATUS_WT_NEW);
}
+
+void test_stash_save__deleted_in_index_modified_in_workdir(void)
+{
+ git_index *index;
+
+ git_repository_index(&index, repo);
+
+ cl_git_pass(git_index_remove_bypath(index, "who"));
+ cl_git_pass(git_index_write(index));
+
+ assert_status(repo, "who", GIT_STATUS_WT_NEW | GIT_STATUS_INDEX_DELETED);
+
+ cl_git_pass(git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_DEFAULT));
+
+ assert_blob_oid("stash@{0}^0:who", "a0400d4954659306a976567af43125a0b1aa8595");
+ assert_blob_oid("stash@{0}^2:who", NULL);
+
+ git_index_free(index);
+}
diff --git a/tests/status/submodules.c b/tests/status/submodules.c
index b0bb4524f..e6de60088 100644
--- a/tests/status/submodules.c
+++ b/tests/status/submodules.c
@@ -143,7 +143,7 @@ void test_status_submodules__moved_head(void)
/* move submodule HEAD to c47800c7266a2be04c571c04d5a6614691ea99bd */
cl_git_pass(
git_oid_fromstr(&oid, "c47800c7266a2be04c571c04d5a6614691ea99bd"));
- cl_git_pass(git_repository_set_head_detached(smrepo, &oid, NULL, NULL));
+ cl_git_pass(git_repository_set_head_detached(smrepo, &oid));
/* first do a normal status, which should now include the submodule */
@@ -503,7 +503,7 @@ void test_status_submodules__entry_but_dir_tracked(void)
cl_git_pass(git_signature_now(&sig, "Sloppy Submoduler", "sloppy@example.com"));
cl_git_pass(git_tree_lookup(&tree, repo, &tree_id));
cl_git_pass(git_commit_create(&commit_id, repo, NULL, sig, sig, NULL, "message", tree, 0, NULL));
- cl_git_pass(git_reference_create(&ref, repo, "refs/heads/master", &commit_id, 1, sig, "commit: foo"));
+ cl_git_pass(git_reference_create(&ref, repo, "refs/heads/master", &commit_id, 1, "commit: foo"));
git_reference_free(ref);
git_signature_free(sig);
}
diff --git a/tests/submodule/add.c b/tests/submodule/add.c
index 05dbafd88..01625d3aa 100644
--- a/tests/submodule/add.c
+++ b/tests/submodule/add.c
@@ -2,6 +2,7 @@
#include "posix.h"
#include "path.h"
#include "submodule_helpers.h"
+#include "config/config_helpers.h"
#include "fileops.h"
static git_repository *g_repo = NULL;
@@ -13,26 +14,19 @@ void test_submodule_add__cleanup(void)
static void assert_submodule_url(const char* name, const char *url)
{
- git_config *cfg;
- const char *s;
git_buf key = GIT_BUF_INIT;
- cl_git_pass(git_repository_config(&cfg, g_repo));
cl_git_pass(git_buf_printf(&key, "submodule.%s.url", name));
- cl_git_pass(git_config_get_string(&s, cfg, git_buf_cstr(&key)));
- cl_assert_equal_s(s, url);
+ assert_config_entry_value(g_repo, git_buf_cstr(&key), url);
- git_config_free(cfg);
git_buf_free(&key);
}
void test_submodule_add__url_absolute(void)
{
git_submodule *sm;
- git_config *cfg;
git_repository *repo;
- const char *worktree_path;
git_buf dot_git_content = GIT_BUF_INIT;
g_repo = setup_fixture_submod2();
@@ -59,15 +53,12 @@ void test_submodule_add__url_absolute(void)
cl_git_pass(git_repository_open(&repo, "submod2/" "sm_libgit2"));
/* Verify worktree path is relative */
- cl_git_pass(git_repository_config(&cfg, repo));
- cl_git_pass(git_config_get_string(&worktree_path, cfg, "core.worktree"));
- cl_assert_equal_s("../../../sm_libgit2/", worktree_path);
+ assert_config_entry_value(repo, "core.worktree", "../../../sm_libgit2/");
/* Verify gitdir path is relative */
cl_git_pass(git_futils_readbuffer(&dot_git_content, "submod2/" "sm_libgit2" "/.git"));
cl_assert_equal_s("gitdir: ../.git/modules/sm_libgit2/", dot_git_content.ptr);
- git_config_free(cfg);
git_repository_free(repo);
git_buf_free(&dot_git_content);
diff --git a/tests/submodule/init.c b/tests/submodule/init.c
index 29004d6cd..dbde0f284 100644
--- a/tests/submodule/init.c
+++ b/tests/submodule/init.c
@@ -34,9 +34,9 @@ void test_submodule_init__absolute_url(void)
/* init and verify that absolute path is written to .git/config */
cl_git_pass(git_submodule_init(sm, false));
- cl_git_pass(git_repository_config(&cfg, g_repo));
+ cl_git_pass(git_repository_config_snapshot(&cfg, g_repo));
- git_config_get_string(&config_url, cfg, "submodule.testrepo.url");
+ cl_git_pass(git_config_get_string(&config_url, cfg, "submodule.testrepo.url"));
cl_assert_equal_s(absolute_url.ptr, config_url);
git_buf_free(&absolute_url);
@@ -64,9 +64,9 @@ void test_submodule_init__relative_url(void)
/* init and verify that absolute path is written to .git/config */
cl_git_pass(git_submodule_init(sm, false));
- cl_git_pass(git_repository_config(&cfg, g_repo));
+ cl_git_pass(git_repository_config_snapshot(&cfg, g_repo));
- git_config_get_string(&config_url, cfg, "submodule.testrepo.url");
+ cl_git_pass(git_config_get_string(&config_url, cfg, "submodule.testrepo.url"));
cl_assert_equal_s(absolute_url.ptr, config_url);
git_buf_free(&absolute_url);
@@ -89,7 +89,7 @@ void test_submodule_init__relative_url_detached_head(void)
cl_git_pass(git_repository_head(&head_ref, g_repo));
cl_git_pass(git_reference_peel(&head_commit, head_ref, GIT_OBJ_COMMIT));
- cl_git_pass(git_repository_set_head_detached(g_repo, git_commit_id((git_commit *)head_commit), NULL, NULL));
+ cl_git_pass(git_repository_set_head_detached(g_repo, git_commit_id((git_commit *)head_commit)));
cl_assert(git_path_dirname_r(&absolute_url, git_repository_workdir(g_repo)) > 0);
cl_git_pass(git_buf_joinpath(&absolute_url, absolute_url.ptr, "testrepo.git"));
@@ -102,9 +102,9 @@ void test_submodule_init__relative_url_detached_head(void)
/* init and verify that absolute path is written to .git/config */
cl_git_pass(git_submodule_init(sm, false));
- cl_git_pass(git_repository_config(&cfg, g_repo));
+ cl_git_pass(git_repository_config_snapshot(&cfg, g_repo));
- git_config_get_string(&config_url, cfg, "submodule.testrepo.url");
+ cl_git_pass(git_config_get_string(&config_url, cfg, "submodule.testrepo.url"));
cl_assert_equal_s(absolute_url.ptr, config_url);
git_buf_free(&absolute_url);
diff --git a/tests/submodule/lookup.c b/tests/submodule/lookup.c
index fa452fb82..666f56ef1 100644
--- a/tests/submodule/lookup.c
+++ b/tests/submodule/lookup.c
@@ -112,7 +112,7 @@ void test_submodule_lookup__lookup_even_with_unborn_head(void)
/* put us on an unborn branch */
cl_git_pass(git_reference_symbolic_create(
- &head, g_repo, "HEAD", "refs/heads/garbage", 1, NULL, NULL));
+ &head, g_repo, "HEAD", "refs/heads/garbage", 1, NULL));
git_reference_free(head);
test_submodule_lookup__simple_lookup(); /* baseline should still pass */
@@ -259,10 +259,7 @@ void test_submodule_lookup__just_added(void)
assert_submodule_exists(g_repo, "sm_just_added_head");
{
- git_signature *sig;
- cl_git_pass(git_signature_now(&sig, "resetter", "resetter@email.com"));
- cl_git_pass(git_reference_create(NULL, g_repo, "refs/heads/master", git_reference_target(original_head), 1, sig, "move head back"));
- git_signature_free(sig);
+ cl_git_pass(git_reference_create(NULL, g_repo, "refs/heads/master", git_reference_target(original_head), 1, "move head back"));
git_reference_free(original_head);
}
diff --git a/tests/submodule/modify.c b/tests/submodule/modify.c
index 9bb48bad2..3d7269bff 100644
--- a/tests/submodule/modify.c
+++ b/tests/submodule/modify.c
@@ -2,6 +2,7 @@
#include "posix.h"
#include "path.h"
#include "submodule_helpers.h"
+#include "config/config_helpers.h"
static git_repository *g_repo = NULL;
@@ -51,7 +52,7 @@ void test_submodule_modify__init(void)
git_submodule_reload_all(g_repo, 1);
/* confirm submodule data in config */
- cl_git_pass(git_repository_config(&cfg, g_repo));
+ cl_git_pass(git_repository_config_snapshot(&cfg, g_repo));
cl_git_pass(git_config_get_string(&str, cfg, "submodule.sm_unchanged.url"));
cl_assert(git__suffixcmp(str, "/submod2_target") == 0);
cl_git_pass(git_config_get_string(&str, cfg, "submodule.sm_changed_head.url"));
@@ -72,20 +73,12 @@ static int sync_one_submodule(
static void assert_submodule_url_is_synced(
git_submodule *sm, const char *parent_key, const char *child_key)
{
- git_config *cfg;
- const char *str;
git_repository *smrepo;
- cl_git_pass(git_repository_config(&cfg, g_repo));
- cl_git_pass(git_config_get_string(&str, cfg, parent_key));
- cl_assert_equal_s(git_submodule_url(sm), str);
- git_config_free(cfg);
+ assert_config_entry_value(g_repo, parent_key, git_submodule_url(sm));
cl_git_pass(git_submodule_open(&smrepo, sm));
- cl_git_pass(git_repository_config(&cfg, smrepo));
- cl_git_pass(git_config_get_string(&str, cfg, child_key));
- cl_assert_equal_s(git_submodule_url(sm), str);
- git_config_free(cfg);
+ assert_config_entry_value(smrepo, child_key, git_submodule_url(sm));
git_repository_free(smrepo);
}
@@ -111,7 +104,7 @@ void test_submodule_modify__sync(void)
*/
/* check submodule info does not match before sync */
- cl_git_pass(git_repository_config(&cfg, g_repo));
+ cl_git_pass(git_repository_config_snapshot(&cfg, g_repo));
cl_git_pass(git_config_get_string(&str, cfg, "submodule."SM1".url"));
cl_assert(strcmp(git_submodule_url(sm1), str) != 0);
cl_git_pass(git_config_get_string(&str, cfg, "submodule."SM2".url"));
diff --git a/tests/submodule/repository_init.c b/tests/submodule/repository_init.c
index bf1968d66..9be1e0b23 100644
--- a/tests/submodule/repository_init.c
+++ b/tests/submodule/repository_init.c
@@ -2,6 +2,7 @@
#include "posix.h"
#include "path.h"
#include "submodule_helpers.h"
+#include "config/config_helpers.h"
#include "fileops.h"
static git_repository *g_repo = NULL;
@@ -10,8 +11,6 @@ void test_submodule_repository_init__basic(void)
{
git_submodule *sm;
git_repository *repo;
- git_config *cfg;
- const char *worktree_path;
git_buf dot_git_content = GIT_BUF_INIT;
g_repo = setup_fixture_submod2();
@@ -21,9 +20,7 @@ void test_submodule_repository_init__basic(void)
cl_git_pass(git_submodule_repo_init(&repo, sm, 1));
/* Verify worktree */
- cl_git_pass(git_repository_config(&cfg, repo));
- cl_git_pass(git_config_get_string(&worktree_path, cfg, "core.worktree"));
- cl_assert_equal_s("../../../sm_gitmodules_only/", worktree_path);
+ assert_config_entry_value(repo, "core.worktree", "../../../sm_gitmodules_only/");
/* Verify gitlink */
cl_git_pass(git_futils_readbuffer(&dot_git_content, "submod2/" "sm_gitmodules_only" "/.git"));
@@ -35,7 +32,6 @@ void test_submodule_repository_init__basic(void)
cl_assert(git_path_isdir("submod2/.git/modules/" "sm_gitmodules_only"));
cl_assert(git_path_isfile("submod2/.git/modules/" "sm_gitmodules_only" "/HEAD"));
- git_config_free(cfg);
git_submodule_free(sm);
git_repository_free(repo);
git_buf_free(&dot_git_content);
diff --git a/tests/submodule/update.c b/tests/submodule/update.c
index ebf864d9f..533e64efc 100644
--- a/tests/submodule/update.c
+++ b/tests/submodule/update.c
@@ -196,7 +196,7 @@ void test_submodule_update__update_already_checked_out_submodule(void)
cl_git_pass(git_reference_lookup(&branch_reference, g_repo, "refs/heads/alternate_1"));
cl_git_pass(git_reference_peel(&branch_commit, branch_reference, GIT_OBJ_COMMIT));
cl_git_pass(git_checkout_tree(g_repo, branch_commit, &checkout_options));
- cl_git_pass(git_repository_set_head(g_repo, git_reference_name(branch_reference), NULL, NULL));
+ cl_git_pass(git_repository_set_head(g_repo, git_reference_name(branch_reference)));
/*
* Verify state after checkout of parent repository. The submodule ID in the
@@ -270,7 +270,7 @@ void test_submodule_update__update_blocks_on_dirty_wd(void)
cl_git_pass(git_reference_lookup(&branch_reference, g_repo, "refs/heads/alternate_1"));
cl_git_pass(git_reference_peel(&branch_commit, branch_reference, GIT_OBJ_COMMIT));
cl_git_pass(git_checkout_tree(g_repo, branch_commit, &checkout_options));
- cl_git_pass(git_repository_set_head(g_repo, git_reference_name(branch_reference), NULL, NULL));
+ cl_git_pass(git_repository_set_head(g_repo, git_reference_name(branch_reference)));
/*
* Verify state after checkout of parent repository. The submodule ID in the
@@ -343,7 +343,7 @@ void test_submodule_update__can_force_update(void)
cl_git_pass(git_reference_lookup(&branch_reference, g_repo, "refs/heads/alternate_1"));
cl_git_pass(git_reference_peel(&branch_commit, branch_reference, GIT_OBJ_COMMIT));
cl_git_pass(git_checkout_tree(g_repo, branch_commit, &checkout_options));
- cl_git_pass(git_repository_set_head(g_repo, git_reference_name(branch_reference), NULL, NULL));
+ cl_git_pass(git_repository_set_head(g_repo, git_reference_name(branch_reference)));
/*
* Verify state after checkout of parent repository. The submodule ID in the
diff --git a/tests/threads/refdb.c b/tests/threads/refdb.c
index 078267aa8..6589e3922 100644
--- a/tests/threads/refdb.c
+++ b/tests/threads/refdb.c
@@ -59,7 +59,7 @@ void test_threads_refdb__iterator(void)
for (r = 0; r < 200; ++r) {
p_snprintf(name, sizeof(name), "refs/heads/direct-%03d", r);
- cl_git_pass(git_reference_create(&ref, g_repo, name, &head, 0, NULL, NULL));
+ cl_git_pass(git_reference_create(&ref, g_repo, name, &head, 0, NULL));
git_reference_free(ref);
}
@@ -103,7 +103,7 @@ static void *create_refs(void *arg)
for (i = 0; i < 10; ++i) {
p_snprintf(name, sizeof(name), "refs/heads/thread-%03d-%02d", *id, i);
- cl_git_pass(git_reference_create(&ref[i], g_repo, name, &head, 0, NULL, NULL));
+ cl_git_pass(git_reference_create(&ref[i], g_repo, name, &head, 0, NULL));
if (i == 5) {
git_refdb *refdb;
@@ -168,7 +168,7 @@ void test_threads_refdb__edit_while_iterate(void)
for (r = 0; r < 50; ++r) {
p_snprintf(name, sizeof(name), "refs/heads/starter-%03d", r);
- cl_git_pass(git_reference_create(&ref, g_repo, name, &head, 0, NULL, NULL));
+ cl_git_pass(git_reference_create(&ref, g_repo, name, &head, 0, NULL));
git_reference_free(ref);
}
diff --git a/tests/trace/trace.c b/tests/trace/trace.c
index 87b325378..097208bff 100644
--- a/tests/trace/trace.c
+++ b/tests/trace/trace.c
@@ -1,4 +1,5 @@
#include "clar_libgit2.h"
+#include "clar_libgit2_trace.h"
#include "trace.h"
static int written = 0;
@@ -14,6 +15,9 @@ static void trace_callback(git_trace_level_t level, const char *message)
void test_trace_trace__initialize(void)
{
+ /* If global tracing is enabled, disable for the duration of this test. */
+ cl_global_trace_disable();
+
git_trace_set(GIT_TRACE_INFO, trace_callback);
written = 0;
}
@@ -21,12 +25,17 @@ void test_trace_trace__initialize(void)
void test_trace_trace__cleanup(void)
{
git_trace_set(GIT_TRACE_NONE, NULL);
+
+ /* If global tracing was enabled, restart it. */
+ cl_global_trace_register();
}
void test_trace_trace__sets(void)
{
#ifdef GIT_TRACE
cl_assert(git_trace_level() == GIT_TRACE_INFO);
+#else
+ cl_skip();
#endif
}
@@ -42,6 +51,8 @@ void test_trace_trace__can_reset(void)
git_trace(GIT_TRACE_ERROR, "Hello %s!", "world");
cl_assert(written == 1);
+#else
+ cl_skip();
#endif
}
@@ -56,6 +67,8 @@ void test_trace_trace__can_unset(void)
cl_assert(written == 0);
git_trace(GIT_TRACE_FATAL, "Hello %s!", "world");
cl_assert(written == 0);
+#else
+ cl_skip();
#endif
}
@@ -65,6 +78,8 @@ void test_trace_trace__skips_higher_level(void)
cl_assert(written == 0);
git_trace(GIT_TRACE_DEBUG, "Hello %s!", "world");
cl_assert(written == 0);
+#else
+ cl_skip();
#endif
}
@@ -74,6 +89,8 @@ void test_trace_trace__writes(void)
cl_assert(written == 0);
git_trace(GIT_TRACE_INFO, "Hello %s!", "world");
cl_assert(written == 1);
+#else
+ cl_skip();
#endif
}
@@ -83,5 +100,7 @@ void test_trace_trace__writes_lower_level(void)
cl_assert(written == 0);
git_trace(GIT_TRACE_ERROR, "Hello %s!", "world");
cl_assert(written == 1);
+#else
+ cl_skip();
#endif
}