summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitattributes1
-rw-r--r--.github/workflows/main.yml18
-rw-r--r--.github/workflows/nightly.yml3
-rw-r--r--.gitignore4
-rw-r--r--README.md24
-rwxr-xr-xci/build.sh13
-rw-r--r--examples/blame.c2
-rw-r--r--examples/checkout.c2
-rw-r--r--examples/common.h2
-rw-r--r--examples/log.c6
-rw-r--r--examples/rev-list.c2
-rw-r--r--examples/rev-parse.c6
-rw-r--r--examples/tag.c4
-rw-r--r--include/git2/blob.h18
-rw-r--r--include/git2/config.h2
-rw-r--r--include/git2/deprecated.h30
-rw-r--r--include/git2/index.h2
-rw-r--r--include/git2/patch.h8
-rw-r--r--include/git2/refs.h6
-rw-r--r--include/git2/repository.h147
-rw-r--r--include/git2/revparse.h10
-rw-r--r--include/git2/transport.h2
-rw-r--r--src/blame.c25
-rw-r--r--src/blob.c11
-rw-r--r--src/cc-compat.h2
-rw-r--r--src/clone.c63
-rw-r--r--src/index.c11
-rw-r--r--src/indexer.c4
-rw-r--r--src/merge.c7
-rw-r--r--src/midx.c9
-rw-r--r--src/mwindow.c4
-rw-r--r--src/pack.c3
-rw-r--r--src/patch.c5
-rw-r--r--src/refdb_fs.c6
-rw-r--r--src/refs.c2
-rw-r--r--src/remote.c16
-rw-r--r--src/repository.c3
-rw-r--r--src/revparse.c6
-rw-r--r--src/revwalk.c2
-rw-r--r--src/transports/winhttp.c2
-rw-r--r--src/win32/w32_leakcheck.c2
-rw-r--r--tests/clone/nonetwork.c8
-rw-r--r--tests/core/structinit.c5
-rw-r--r--tests/fetchhead/nonetwork.c29
-rw-r--r--tests/filter/bare.c2
-rw-r--r--tests/pack/midx.c1
-rw-r--r--tests/refs/revparse.c26
-rw-r--r--tests/repo/init.c16
48 files changed, 409 insertions, 173 deletions
diff --git a/.gitattributes b/.gitattributes
index 176a458f9..3d90b7d61 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1 +1,2 @@
* text=auto
+tests/resources/** linguist-vendored
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 091f51844..7179a613d 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -1,12 +1,13 @@
# Continuous integration and pull request validation builds for the
-# master and maintenance branches.
+# main and maintenance branches.
name: CI Build
on:
push:
- branches: [ master, maint/* ]
+ branches: [ main, maint/* ]
pull_request:
- branches: [ master, maint/* ]
+ branches: [ main, maint/* ]
+ workflow_dispatch:
env:
docker-registry: docker.pkg.github.com
@@ -48,7 +49,7 @@ jobs:
uses: actions/checkout@v2
with:
fetch-depth: 0
- if: github.event_name == 'push'
+ if: github.event_name != 'pull_request'
- name: Setup QEMU
run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
if: matrix.container.qemu == true
@@ -59,7 +60,7 @@ jobs:
DOCKER_REGISTRY: ${{ env.docker-registry }}
GITHUB_TOKEN: ${{ secrets.github_token }}
working-directory: ${{ env.docker-config-path }}
- if: github.event_name == 'push'
+ if: github.event_name != 'pull_request'
- name: Build and publish image
run: |
if [ "${{ matrix.container.base }}" != "" ]; then
@@ -68,7 +69,7 @@ jobs:
docker build -t ${{ env.docker-registry-container-sha }} ${BASE_ARG} -f ${{ env.dockerfile }} .
docker push ${{ env.docker-registry-container-sha }}
working-directory: ${{ env.docker-config-path }}
- if: github.event_name == 'push' && env.docker-container-exists != 'true'
+ if: github.event_name != 'pull_request' && env.docker-container-exists != 'true'
# Run our CI/CD builds. We build a matrix with the various build targets
# and their details. Then we build either in a docker container (Linux)
@@ -153,7 +154,6 @@ jobs:
env:
CC: clang
CMAKE_OPTIONS: -DREGEX_BACKEND=regcomp_l -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=leaks -DUSE_GSSAPI=ON
- CMAKE_GENERATOR: Ninja
PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig
SKIP_SSH_TESTS: true
SKIP_NEGOTIATE_TESTS: true
@@ -254,7 +254,7 @@ jobs:
# Generate documentation using docurium. We'll upload the documentation
# as a build artifact so that it can be reviewed as part of a pull
# request or in a forked build. For CI builds in the main repository's
- # master branch, we'll push the gh-pages branch back up so that it is
+ # main branch, we'll push the gh-pages branch back up so that it is
# published to our documentation site.
documentation:
name: Generate documentation
@@ -293,4 +293,4 @@ jobs:
path: api-documentation.zip
- name: Push documentation branch
run: git push origin gh-pages
- if: github.event_name == 'push' && github.repository == 'libgit2/libgit2'
+ if: github.event_name != 'pull_request' && github.repository == 'libgit2/libgit2'
diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml
index fa83491ba..b52b398d8 100644
--- a/.github/workflows/nightly.yml
+++ b/.github/workflows/nightly.yml
@@ -1,4 +1,4 @@
-# Nightly build for the master branch across multiple targets.
+# Nightly build for the main branch across multiple targets.
name: Nightly Build
on:
@@ -112,7 +112,6 @@ jobs:
env:
CC: clang
CMAKE_OPTIONS: -DREGEX_BACKEND=regcomp_l -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=leaks -DUSE_GSSAPI=ON
- CMAKE_GENERATOR: Ninja
PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig
SKIP_SSH_TESTS: true
SKIP_NEGOTIATE_TESTS: true
diff --git a/.gitignore b/.gitignore
index b38b7e16e..69d388f8e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,7 @@
-build/
+/build/
.DS_Store
*~
.*.swp
-tags
+/tags
CMakeSettings.json
.vs
diff --git a/README.md b/README.md
index 9bbdeaf3b..1f72f277f 100644
--- a/README.md
+++ b/README.md
@@ -33,6 +33,7 @@ Additionally, the example code has been released to the public domain (see the
Table of Contents
=================
+* [Using libgit2](#using-libgit2)
* [Quick Start](#quick-start)
* [Getting Help](#getting-help)
* [What It Can Do](#what-it-can-do)
@@ -52,6 +53,28 @@ Table of Contents
* [How Can I Contribute?](#how-can-i-contribute)
* [License](#license)
+Using libgit2
+=============
+
+Most of these instructions assume that you're writing an application
+in C and want to use libgit2 directly. If you're _not_ using C,
+and you're writing in a different language or platform like .NET,
+Node.js, or Ruby, then there is probably a
+"[language binding](#language-bindings)" that you can use to take care
+of the messy tasks of calling into native code.
+
+But if you _do_ want to use libgit2 directly - because you're building
+an application in C - then you may be able use an existing binary.
+There are packages for the
+[vcpkg](https://github.com/Microsoft/vcpkg) and
+[conan](https://conan.io/center/libgit2)
+package managers. And libgit2 is available in
+[Homebrew](https://formulae.brew.sh/formula/libgit2) and most Linux
+distributions.
+
+However, these versions _may_ be outdated and we recommend using the
+latest version if possible. Thankfully libgit2 is not hard to compile.
+
Quick Start
===========
@@ -369,6 +392,7 @@ Here are the bindings to libgit2 that are currently available:
* Python
* pygit2 <https://github.com/libgit2/pygit2>
* R
+ * gert <https://docs.ropensci.org/gert>
* git2r <https://github.com/ropensci/git2r>
* Ruby
* Rugged <https://github.com/libgit2/rugged>
diff --git a/ci/build.sh b/ci/build.sh
index c230e67d6..5a51f925a 100755
--- a/ci/build.sh
+++ b/ci/build.sh
@@ -33,6 +33,9 @@ if [ -f "/etc/debian_version" ]; then
(source /etc/lsb-release && echo "${DISTRIB_DESCRIPTION}") | indent
fi
+CORES=$(getconf _NPROCESSORS_ONLN || true)
+echo "Number of cores: ${CORES:-(Unknown)}"
+
echo "Kernel version:"
uname -a 2>&1 | indent
@@ -64,4 +67,12 @@ echo "##########################################################################
echo "## Building libgit2"
echo "##############################################################################"
-env PATH="${BUILD_PATH}" "${CMAKE}" --build .
+# Determine parallelism; newer cmake supports `--build --parallel` but
+# we cannot yet rely on that.
+if [ "${CMAKE_GENERATOR}" = "Unix Makefiles" -a "${CORES}" != "" ]; then
+ BUILDER=(make -j ${CORES})
+else
+ BUILDER=("${CMAKE}" --build .)
+fi
+
+env PATH="${BUILD_PATH}" "${BUILDER[@]}"
diff --git a/examples/blame.c b/examples/blame.c
index 49350fc0f..954c97b17 100644
--- a/examples/blame.c
+++ b/examples/blame.c
@@ -54,7 +54,7 @@ int lg2_blame(git_repository *repo, int argc, char *argv[])
*/
if (o.commitspec) {
check_lg2(git_revparse(&revspec, repo, o.commitspec), "Couldn't parse commit spec", NULL);
- if (revspec.flags & GIT_REVPARSE_SINGLE) {
+ if (revspec.flags & GIT_REVSPEC_SINGLE) {
git_oid_cpy(&blameopts.newest_commit, git_object_id(revspec.from));
git_object_free(revspec.from);
} else {
diff --git a/examples/checkout.c b/examples/checkout.c
index 204b58d88..ac7b7422d 100644
--- a/examples/checkout.c
+++ b/examples/checkout.c
@@ -14,7 +14,7 @@
#include "common.h"
-/* Define the printf format specifer to use for size_t output */
+/* Define the printf format specifier to use for size_t output */
#if defined(_MSC_VER) || defined(__MINGW32__)
# define PRIuZ "Iu"
# define PRIxZ "Ix"
diff --git a/examples/common.h b/examples/common.h
index 0126568ab..f86e92c35 100644
--- a/examples/common.h
+++ b/examples/common.h
@@ -36,7 +36,7 @@
#endif
#ifndef PRIuZ
-/* Define the printf format specifer to use for size_t output */
+/* Define the printf format specifier to use for size_t output */
#if defined(_MSC_VER) || defined(__MINGW32__)
# define PRIuZ "Iu"
#else
diff --git a/examples/log.c b/examples/log.c
index ee18df542..9060f3f3e 100644
--- a/examples/log.c
+++ b/examples/log.c
@@ -245,7 +245,7 @@ static int add_revision(struct log_state *s, const char *revstr)
}
if (*revstr == '^') {
- revs.flags = GIT_REVPARSE_SINGLE;
+ revs.flags = GIT_REVSPEC_SINGLE;
hide = !hide;
if (git_revparse_single(&revs.from, s->repo, revstr + 1) < 0)
@@ -253,12 +253,12 @@ static int add_revision(struct log_state *s, const char *revstr)
} else if (git_revparse(&revs, s->repo, revstr) < 0)
return -1;
- if ((revs.flags & GIT_REVPARSE_SINGLE) != 0)
+ if ((revs.flags & GIT_REVSPEC_SINGLE) != 0)
push_rev(s, revs.from, hide);
else {
push_rev(s, revs.to, hide);
- if ((revs.flags & GIT_REVPARSE_MERGE_BASE) != 0) {
+ if ((revs.flags & GIT_REVSPEC_MERGE_BASE) != 0) {
git_oid base;
check_lg2(git_merge_base(&base, s->repo,
git_object_id(revs.from), git_object_id(revs.to)),
diff --git a/examples/rev-list.c b/examples/rev-list.c
index 75fb19e70..d10f16690 100644
--- a/examples/rev-list.c
+++ b/examples/rev-list.c
@@ -73,7 +73,7 @@ static int push_range(git_repository *repo, git_revwalk *walk, const char *range
if ((error = git_revparse(&revspec, repo, range)))
return error;
- if (revspec.flags & GIT_REVPARSE_MERGE_BASE) {
+ if (revspec.flags & GIT_REVSPEC_MERGE_BASE) {
/* TODO: support "<commit>...<commit>" */
return GIT_EINVALIDSPEC;
}
diff --git a/examples/rev-parse.c b/examples/rev-parse.c
index 7d6e9986f..90258c101 100644
--- a/examples/rev-parse.c
+++ b/examples/rev-parse.c
@@ -69,17 +69,17 @@ static int parse_revision(git_repository *repo, struct parse_state *ps)
check_lg2(git_revparse(&rs, repo, ps->spec), "Could not parse", ps->spec);
- if ((rs.flags & GIT_REVPARSE_SINGLE) != 0) {
+ if ((rs.flags & GIT_REVSPEC_SINGLE) != 0) {
git_oid_tostr(str, sizeof(str), git_object_id(rs.from));
printf("%s\n", str);
git_object_free(rs.from);
}
- else if ((rs.flags & GIT_REVPARSE_RANGE) != 0) {
+ else if ((rs.flags & GIT_REVSPEC_RANGE) != 0) {
git_oid_tostr(str, sizeof(str), git_object_id(rs.to));
printf("%s\n", str);
git_object_free(rs.to);
- if ((rs.flags & GIT_REVPARSE_MERGE_BASE) != 0) {
+ if ((rs.flags & GIT_REVSPEC_MERGE_BASE) != 0) {
git_oid base;
check_lg2(git_merge_base(&base, repo,
git_object_id(rs.from), git_object_id(rs.to)),
diff --git a/examples/tag.c b/examples/tag.c
index 03d9c2bf9..e4f71ae62 100644
--- a/examples/tag.c
+++ b/examples/tag.c
@@ -188,7 +188,7 @@ static void action_delete_tag(tag_state *state)
git_object_free(obj);
}
-static void action_create_lighweight_tag(tag_state *state)
+static void action_create_lightweight_tag(tag_state *state)
{
git_repository *repo = state->repo;
struct tag_options *opts = state->opts;
@@ -260,7 +260,7 @@ static void parse_options(tag_action *action, struct tag_options *opts, int argc
print_usage();
if (*action != &action_create_tag)
- *action = &action_create_lighweight_tag;
+ *action = &action_create_lightweight_tag;
} else if (!strcmp(curr, "-n")) {
opts->num_lines = 1;
*action = &action_list_tags;
diff --git a/include/git2/blob.h b/include/git2/blob.h
index 8e977267d..ff473993a 100644
--- a/include/git2/blob.h
+++ b/include/git2/blob.h
@@ -113,11 +113,15 @@ typedef enum {
* When set, filters will be loaded from a `.gitattributes` file
* in the HEAD commit.
*/
- GIT_BLOB_FILTER_ATTTRIBUTES_FROM_HEAD = (1 << 2),
+ GIT_BLOB_FILTER_ATTRIBUTES_FROM_HEAD = (1 << 2),
} git_blob_filter_flag_t;
/**
* The options used when applying filter options to a file.
+ *
+ * Initialize with `GIT_BLOB_FILTER_OPTIONS_INIT`. Alternatively, you can
+ * use `git_blob_filter_options_init`.
+ *
*/
typedef struct {
int version;
@@ -130,6 +134,18 @@ typedef struct {
#define GIT_BLOB_FILTER_OPTIONS_INIT {GIT_BLOB_FILTER_OPTIONS_VERSION, GIT_BLOB_FILTER_CHECK_FOR_BINARY}
/**
+ * Initialize git_blob_filter_options structure
+ *
+ * Initializes a `git_blob_filter_options` with default values. Equivalent
+ * to creating an instance with `GIT_BLOB_FILTER_OPTIONS_INIT`.
+ *
+ * @param opts The `git_blob_filter_options` struct to initialize.
+ * @param version The struct version; pass `GIT_BLOB_FILTER_OPTIONS_VERSION`.
+ * @return Zero on success; -1 on failure.
+ */
+GIT_EXTERN(int) git_blob_filter_options_init(git_blob_filter_options *opts, unsigned int version);
+
+/**
* Get a buffer with the filtered content of a blob.
*
* This applies filters as if the blob was being checked out to the
diff --git a/include/git2/config.h b/include/git2/config.h
index abf5bbbd0..7c8e388b2 100644
--- a/include/git2/config.h
+++ b/include/git2/config.h
@@ -263,7 +263,7 @@ GIT_EXTERN(int) git_config_open_level(
*
* Git allows you to store your global configuration at
* `$HOME/.gitconfig` or `$XDG_CONFIG_HOME/git/config`. For backwards
- * compatability, the XDG file shouldn't be used unless the use has
+ * compatibility, the XDG file shouldn't be used unless the use has
* created it explicitly. With this function you'll open the correct
* one to write to.
*
diff --git a/include/git2/deprecated.h b/include/git2/deprecated.h
index 4e43c4536..d18fffc0e 100644
--- a/include/git2/deprecated.h
+++ b/include/git2/deprecated.h
@@ -29,6 +29,7 @@
#include "trace.h"
#include "repository.h"
#include "revert.h"
+#include "revparse.h"
#include "stash.h"
#include "status.h"
#include "submodule.h"
@@ -80,16 +81,19 @@ typedef git_attr_value_t git_attr_t;
/**@}*/
-/** @name Deprecated Blob Functions
+/** @name Deprecated Blob Functions and Constants
*
- * These functions are retained for backward compatibility. The newer
- * versions of these functions should be preferred in all new code.
+ * These functions and enumeration values are retained for backward
+ * compatibility. The newer versions of these functions and values
+ * should be preferred in all new code.
*
* There is no plan to remove these backward compatibility values at
* this time.
*/
/**@{*/
+#define GIT_BLOB_FILTER_ATTTRIBUTES_FROM_HEAD GIT_BLOB_FILTER_ATTRIBUTES_FROM_HEAD
+
GIT_EXTERN(int) git_blob_create_fromworkdir(git_oid *id, git_repository *repo, const char *relative_path);
GIT_EXTERN(int) git_blob_create_fromdisk(git_oid *id, git_repository *repo, const char *path);
GIT_EXTERN(int) git_blob_create_fromstream(
@@ -411,6 +415,25 @@ GIT_EXTERN(int) git_tag_create_frombuffer(
/**@}*/
+/** @name Deprecated Revspec Constants
+ *
+ * These enumeration values are retained for backward compatibility.
+ * The newer versions of these values should be preferred in all new
+ * code.
+ *
+ * There is no plan to remove these backward compatibility values at
+ * this time.
+ */
+/**@{*/
+
+typedef git_revspec_t git_revparse_mode_t;
+
+#define GIT_REVPARSE_SINGLE GIT_REVSPEC_SINGLE
+#define GIT_REVPARSE_RANGE GIT_REVSPEC_RANGE
+#define GIT_REVPARSE_MERGE_BASE GIT_REVSPEC_MERGE_BASE
+
+/**@}*/
+
/** @name Deprecated Credential Types
*
* These types are retained for backward compatibility. The newer
@@ -419,6 +442,7 @@ GIT_EXTERN(int) git_tag_create_frombuffer(
* There is no plan to remove these backward compatibility values at
* this time.
*/
+/**@{*/
typedef git_credential git_cred;
typedef git_credential_userpass_plaintext git_cred_userpass_plaintext;
diff --git a/include/git2/index.h b/include/git2/index.h
index 314135109..14a132497 100644
--- a/include/git2/index.h
+++ b/include/git2/index.h
@@ -349,7 +349,7 @@ GIT_EXTERN(int) git_index_write_tree(git_oid *out, git_index *index);
*
* The index must not contain any file in conflict.
*
- * @param out Pointer where to store OID of the the written tree
+ * @param out Pointer where to store OID of the written tree
* @param index Index to write
* @param repo Repository where to write the tree
* @return 0 on success, GIT_EUNMERGED when the index is not clean
diff --git a/include/git2/patch.h b/include/git2/patch.h
index b177798e6..fde9659e7 100644
--- a/include/git2/patch.h
+++ b/include/git2/patch.h
@@ -29,6 +29,14 @@ GIT_BEGIN_DECL
typedef struct git_patch git_patch;
/**
+ * Get the repository associated with this patch. May be NULL.
+ *
+ * @param patch the patch
+ * @return a pointer to the repository
+ */
+GIT_EXTERN(git_repository *) git_patch_owner(const git_patch *patch);
+
+/**
* Return a patch for an entry in the diff list.
*
* The `git_patch` is a newly created object contains the text diffs
diff --git a/include/git2/refs.h b/include/git2/refs.h
index a20a1265b..8bc99e15e 100644
--- a/include/git2/refs.h
+++ b/include/git2/refs.h
@@ -169,7 +169,7 @@ GIT_EXTERN(int) git_reference_symbolic_create(git_reference **out, git_repositor
*
* 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.
+ * branches) and it does not have a reflog.
*
* @param out Pointer to the newly created reference
* @param repo Repository where that reference will live
@@ -206,7 +206,7 @@ GIT_EXTERN(int) git_reference_create(git_reference **out, git_repository *repo,
*
* 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.
+ * 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_id`
@@ -318,7 +318,7 @@ GIT_EXTERN(git_repository *) git_reference_owner(const git_reference *ref);
*
* 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.
+ * branches) and it does not have a reflog.
*
* @param out Pointer to the newly created reference
* @param ref The reference
diff --git a/include/git2/repository.h b/include/git2/repository.h
index 9ddcd3404..45becc73d 100644
--- a/include/git2/repository.h
+++ b/include/git2/repository.h
@@ -219,36 +219,54 @@ GIT_EXTERN(int) git_repository_init(
*
* These flags configure extra behaviors to `git_repository_init_ext`.
* In every case, the default behavior is the zero value (i.e. flag is
- * not set). Just OR the flag values together for the `flags` parameter
- * when initializing a new repo. Details of individual values are:
- *
- * * BARE - Create a bare repository with no working directory.
- * * NO_REINIT - Return an GIT_EEXISTS error if the repo_path appears to
- * already be an git repository.
- * * NO_DOTGIT_DIR - Normally a "/.git/" will be appended to the repo
- * path for non-bare repos (if it is not already there), but
- * passing this flag prevents that behavior.
- * * MKDIR - Make the repo_path (and workdir_path) as needed. Init is
- * always willing to create the ".git" directory even without this
- * flag. This flag tells init to create the trailing component of
- * the repo and workdir paths as needed.
- * * MKPATH - Recursively make all components of the repo and workdir
- * paths as necessary.
- * * EXTERNAL_TEMPLATE - libgit2 normally uses internal templates to
- * initialize a new repo. This flags enables external templates,
- * looking the "template_path" from the options if set, or the
- * `init.templatedir` global config if not, or falling back on
- * "/usr/share/git-core/templates" if it exists.
- * * GIT_REPOSITORY_INIT_RELATIVE_GITLINK - If an alternate workdir is
- * specified, use relative paths for the gitdir and core.worktree.
+ * not set). Just OR the flag values together for the `flags` parameter
+ * when initializing a new repo.
*/
typedef enum {
+ /**
+ * Create a bare repository with no working directory.
+ */
GIT_REPOSITORY_INIT_BARE = (1u << 0),
+
+ /**
+ * Return an GIT_EEXISTS error if the repo_path appears to already be
+ * an git repository.
+ */
GIT_REPOSITORY_INIT_NO_REINIT = (1u << 1),
+
+ /**
+ * Normally a "/.git/" will be appended to the repo path for
+ * non-bare repos (if it is not already there), but passing this flag
+ * prevents that behavior.
+ */
GIT_REPOSITORY_INIT_NO_DOTGIT_DIR = (1u << 2),
+
+ /**
+ * Make the repo_path (and workdir_path) as needed. Init is always willing
+ * to create the ".git" directory even without this flag. This flag tells
+ * init to create the trailing component of the repo and workdir paths
+ * as needed.
+ */
GIT_REPOSITORY_INIT_MKDIR = (1u << 3),
+
+ /**
+ * Recursively make all components of the repo and workdir paths as
+ * necessary.
+ */
GIT_REPOSITORY_INIT_MKPATH = (1u << 4),
+
+ /**
+ * libgit2 normally uses internal templates to initialize a new repo.
+ * This flags enables external templates, looking the "template_path" from
+ * the options if set, or the `init.templatedir` global config if not,
+ * or falling back on "/usr/share/git-core/templates" if it exists.
+ */
GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE = (1u << 5),
+
+ /**
+ * If an alternate workdir is specified, use relative paths for the gitdir
+ * and core.worktree.
+ */
GIT_REPOSITORY_INIT_RELATIVE_GITLINK = (1u << 6),
} git_repository_init_flag_t;
@@ -257,17 +275,23 @@ typedef enum {
*
* Set the mode field of the `git_repository_init_options` structure
* either to the custom mode that you would like, or to one of the
- * following modes:
- *
- * * SHARED_UMASK - Use permissions configured by umask - the default.
- * * SHARED_GROUP - Use "--shared=group" behavior, chmod'ing the new repo
- * to be group writable and "g+sx" for sticky group assignment.
- * * SHARED_ALL - Use "--shared=all" behavior, adding world readability.
- * * Anything else - Set to custom value.
+ * defined modes.
*/
typedef enum {
+ /**
+ * Use permissions configured by umask - the default.
+ */
GIT_REPOSITORY_INIT_SHARED_UMASK = 0,
+
+ /**
+ * Use "--shared=group" behavior, chmod'ing the new repo to be group
+ * writable and "g+sx" for sticky group assignment.
+ */
GIT_REPOSITORY_INIT_SHARED_GROUP = 0002775,
+
+ /**
+ * Use "--shared=all" behavior, adding world readability.
+ */
GIT_REPOSITORY_INIT_SHARED_ALL = 0002777,
} git_repository_init_mode_t;
@@ -275,38 +299,57 @@ typedef enum {
* Extended options structure for `git_repository_init_ext`.
*
* This contains extra options for `git_repository_init_ext` that enable
- * additional initialization features. The fields are:
- *
- * * flags - Combination of GIT_REPOSITORY_INIT flags above.
- * * mode - Set to one of the standard GIT_REPOSITORY_INIT_SHARED_...
- * constants above, or to a custom value that you would like.
- * * workdir_path - The path to the working dir or NULL for default (i.e.
- * repo_path parent on non-bare repos). IF THIS IS RELATIVE PATH,
- * IT WILL BE EVALUATED RELATIVE TO THE REPO_PATH. If this is not
- * the "natural" working directory, a .git gitlink file will be
- * created here linking to the repo_path.
- * * description - If set, this will be used to initialize the "description"
- * file in the repository, instead of using the template content.
- * * template_path - When GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE is set,
- * this contains the path to use for the template directory. If
- * this is NULL, the config or default directory options will be
- * used instead.
- * * initial_head - The name of the head to point HEAD at. If NULL, then
- * this will be treated as "master" and the HEAD ref will be set
- * to "refs/heads/master". If this begins with "refs/" it will be
- * used verbatim; otherwise "refs/heads/" will be prefixed.
- * * origin_url - If this is non-NULL, then after the rest of the
- * repository initialization is completed, an "origin" remote
- * will be added pointing to this URL.
+ * additional initialization features.
*/
typedef struct {
unsigned int version;
+
+ /**
+ * Combination of GIT_REPOSITORY_INIT flags above.
+ */
uint32_t flags;
+
+ /**
+ * Set to one of the standard GIT_REPOSITORY_INIT_SHARED_... constants
+ * above, or to a custom value that you would like.
+ */
uint32_t mode;
+
+ /**
+ * The path to the working dir or NULL for default (i.e. repo_path parent
+ * on non-bare repos). IF THIS IS RELATIVE PATH, IT WILL BE EVALUATED
+ * RELATIVE TO THE REPO_PATH. If this is not the "natural" working
+ * directory, a .git gitlink file will be created here linking to the
+ * repo_path.
+ */
const char *workdir_path;
+
+ /**
+ * If set, this will be used to initialize the "description" file in the
+ * repository, instead of using the template content.
+ */
const char *description;
+
+ /**
+ * When GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE is set, this contains
+ * the path to use for the template directory. If this is NULL, the config
+ * or default directory options will be used instead.
+ */
const char *template_path;
+
+ /**
+ * The name of the head to point HEAD at. If NULL, then this will be
+ * treated as "master" and the HEAD ref will be set to "refs/heads/master".
+ * If this begins with "refs/" it will be used verbatim;
+ * otherwise "refs/heads/" will be prefixed.
+ */
const char *initial_head;
+
+ /**
+ * If this is non-NULL, then after the rest of the repository
+ * initialization is completed, an "origin" remote will be added
+ * pointing to this URL.
+ */
const char *origin_url;
} git_repository_init_options;
diff --git a/include/git2/revparse.h b/include/git2/revparse.h
index d170e1621..e14ddee96 100644
--- a/include/git2/revparse.h
+++ b/include/git2/revparse.h
@@ -70,12 +70,12 @@ GIT_EXTERN(int) git_revparse_ext(
*/
typedef enum {
/** The spec targeted a single object. */
- GIT_REVPARSE_SINGLE = 1 << 0,
+ GIT_REVSPEC_SINGLE = 1 << 0,
/** The spec targeted a range of commits. */
- GIT_REVPARSE_RANGE = 1 << 1,
+ GIT_REVSPEC_RANGE = 1 << 1,
/** The spec used the '...' operator, which invokes special semantics. */
- GIT_REVPARSE_MERGE_BASE = 1 << 2,
-} git_revparse_mode_t;
+ GIT_REVSPEC_MERGE_BASE = 1 << 2,
+} git_revspec_t;
/**
* Git Revision Spec: output of a `git_revparse` operation
@@ -85,7 +85,7 @@ typedef struct {
git_object *from;
/** The right element of the revspec; must be freed by the user */
git_object *to;
- /** The intent of the revspec (i.e. `git_revparse_mode_t` flags) */
+ /** The intent of the revspec (i.e. `git_revspec_mode_t` flags) */
unsigned int flags;
} git_revspec;
diff --git a/include/git2/transport.h b/include/git2/transport.h
index fc99ce8f3..5a27de9a8 100644
--- a/include/git2/transport.h
+++ b/include/git2/transport.h
@@ -23,7 +23,7 @@
GIT_BEGIN_DECL
/**
- * Callback for messages recieved by the transport.
+ * Callback for messages received by the transport.
*
* Return a negative value to cancel the network operation.
*
diff --git a/src/blame.c b/src/blame.c
index 651b7a003..10e311aee 100644
--- a/src/blame.c
+++ b/src/blame.c
@@ -76,6 +76,14 @@ static git_blame_hunk* new_hunk(
return hunk;
}
+static void free_hunk(git_blame_hunk *hunk)
+{
+ git__free((void*)hunk->orig_path);
+ git_signature_free(hunk->final_signature);
+ git_signature_free(hunk->orig_signature);
+ git__free(hunk);
+}
+
static git_blame_hunk* dup_hunk(git_blame_hunk *hunk)
{
git_blame_hunk *newhunk = new_hunk(
@@ -90,17 +98,14 @@ static git_blame_hunk* dup_hunk(git_blame_hunk *hunk)
git_oid_cpy(&newhunk->orig_commit_id, &hunk->orig_commit_id);
git_oid_cpy(&newhunk->final_commit_id, &hunk->final_commit_id);
newhunk->boundary = hunk->boundary;
- git_signature_dup(&newhunk->final_signature, hunk->final_signature);
- git_signature_dup(&newhunk->orig_signature, hunk->orig_signature);
- return newhunk;
-}
-static void free_hunk(git_blame_hunk *hunk)
-{
- git__free((void*)hunk->orig_path);
- git_signature_free(hunk->final_signature);
- git_signature_free(hunk->orig_signature);
- git__free(hunk);
+ if (git_signature_dup(&newhunk->final_signature, hunk->final_signature) < 0 ||
+ git_signature_dup(&newhunk->orig_signature, hunk->orig_signature) < 0) {
+ free_hunk(newhunk);
+ return NULL;
+ }
+
+ return newhunk;
}
/* Starting with the hunk that includes start_line, shift all following hunks'
diff --git a/src/blob.c b/src/blob.c
index 97069645c..ef4ad2e7e 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -408,6 +408,15 @@ int git_blob_is_binary(const git_blob *blob)
return git_buf_text_is_binary(&content);
}
+int git_blob_filter_options_init(
+ git_blob_filter_options *opts,
+ unsigned int version)
+{
+ GIT_INIT_STRUCTURE_FROM_TEMPLATE(opts, version,
+ git_blob_filter_options, GIT_BLOB_FILTER_OPTIONS_INIT);
+ return 0;
+}
+
int git_blob_filter(
git_buf *out,
git_blob *blob,
@@ -439,7 +448,7 @@ int git_blob_filter(
if ((opts.flags & GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES) != 0)
flags |= GIT_FILTER_NO_SYSTEM_ATTRIBUTES;
- if ((opts.flags & GIT_BLOB_FILTER_ATTTRIBUTES_FROM_HEAD) != 0)
+ if ((opts.flags & GIT_BLOB_FILTER_ATTRIBUTES_FROM_HEAD) != 0)
flags |= GIT_FILTER_ATTRIBUTES_FROM_HEAD;
if (!(error = git_filter_list_load(
diff --git a/src/cc-compat.h b/src/cc-compat.h
index 7ade561f3..de1469da8 100644
--- a/src/cc-compat.h
+++ b/src/cc-compat.h
@@ -45,7 +45,7 @@
#define GIT_UNUSED(x) ((void)(x))
-/* Define the printf format specifer to use for size_t output */
+/* Define the printf format specifier to use for size_t output */
#if defined(_MSC_VER) || defined(__MINGW32__)
/* Visual Studio 2012 and prior lack PRId64 entirely */
diff --git a/src/clone.c b/src/clone.c
index 7ae90b09e..6d5ebf6b0 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -162,6 +162,37 @@ done:
return error;
}
+static int update_remote_head_byname(
+ git_repository *repo,
+ const char *remote_name,
+ const char *tracking_branch_name,
+ const char *reflog_message)
+{
+ git_buf tracking_head_name = GIT_BUF_INIT;
+ git_reference *remote_head = NULL;
+ int error;
+
+ if ((error = git_buf_printf(&tracking_head_name,
+ "%s%s/%s",
+ GIT_REFS_REMOTES_DIR,
+ remote_name,
+ GIT_HEAD_FILE)) < 0)
+ goto cleanup;
+
+ error = git_reference_symbolic_create(
+ &remote_head,
+ repo,
+ git_buf_cstr(&tracking_head_name),
+ tracking_branch_name,
+ true,
+ reflog_message);
+
+cleanup:
+ git_reference_free(remote_head);
+ git_buf_dispose(&tracking_head_name);
+ return error;
+}
+
static int update_remote_head(
git_repository *repo,
git_remote *remote,
@@ -169,9 +200,7 @@ static int update_remote_head(
const char *reflog_message)
{
git_refspec *refspec;
- git_reference *remote_head = NULL;
- git_buf remote_head_name = GIT_BUF_INIT;
- git_buf remote_branch_name = GIT_BUF_INIT;
+ git_buf tracking_branch_name = GIT_BUF_INIT;
int error;
/* Determine the remote tracking ref name from the local branch */
@@ -184,30 +213,19 @@ static int update_remote_head(
}
if ((error = git_refspec_transform(
- &remote_branch_name,
+ &tracking_branch_name,
refspec,
git_buf_cstr(target))) < 0)
goto cleanup;
- if ((error = git_buf_printf(&remote_head_name,
- "%s%s/%s",
- GIT_REFS_REMOTES_DIR,
- git_remote_name(remote),
- GIT_HEAD_FILE)) < 0)
- goto cleanup;
-
- error = git_reference_symbolic_create(
- &remote_head,
+ error = update_remote_head_byname(
repo,
- git_buf_cstr(&remote_head_name),
- git_buf_cstr(&remote_branch_name),
- true,
+ git_remote_name(remote),
+ git_buf_cstr(&tracking_branch_name),
reflog_message);
cleanup:
- git_reference_free(remote_head);
- git_buf_dispose(&remote_branch_name);
- git_buf_dispose(&remote_head_name);
+ git_buf_dispose(&tracking_branch_name);
return error;
}
@@ -277,8 +295,11 @@ static int update_head_to_branch(
if ((retcode = git_reference_lookup(&remote_ref, repo, git_buf_cstr(&remote_branch_name))) < 0)
goto cleanup;
- retcode = update_head_to_new_branch(repo, git_reference_target(remote_ref), branch,
- reflog_message);
+ if ((retcode = update_head_to_new_branch(repo, git_reference_target(remote_ref), branch,
+ reflog_message)) < 0)
+ goto cleanup;
+
+ retcode = update_remote_head_byname(repo, remote_name, remote_branch_name.ptr, reflog_message);
cleanup:
git_reference_free(remote_ref);
diff --git a/src/index.c b/src/index.c
index 7ebe07582..3d46030f7 100644
--- a/src/index.c
+++ b/src/index.c
@@ -2861,14 +2861,16 @@ static int write_entries(git_index *index, git_filebuf *file)
{
int error = 0;
size_t i;
- git_vector case_sorted, *entries;
+ git_vector case_sorted = GIT_VECTOR_INIT, *entries = NULL;
git_index_entry *entry;
const char *last = NULL;
/* If index->entries is sorted case-insensitively, then we need
* to re-sort it case-sensitively before writing */
if (index->ignore_case) {
- git_vector_dup(&case_sorted, &index->entries, git_index_entry_cmp);
+ if ((error = git_vector_dup(&case_sorted, &index->entries, git_index_entry_cmp)) < 0)
+ goto done;
+
git_vector_sort(&case_sorted);
entries = &case_sorted;
} else {
@@ -2885,9 +2887,8 @@ static int write_entries(git_index *index, git_filebuf *file)
last = entry->path;
}
- if (index->ignore_case)
- git_vector_free(&case_sorted);
-
+done:
+ git_vector_free(&case_sorted);
return error;
}
diff --git a/src/indexer.c b/src/indexer.c
index ba82d716d..d546888cc 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -656,7 +656,6 @@ static int append_to_pack(git_indexer *idx, const void *data, size_t size)
size_t page_offset;
off64_t page_start;
off64_t current_size = idx->pack->mwf.size;
- int fd = idx->pack->mwf.fd;
int error;
if (!size)
@@ -673,8 +672,7 @@ static int append_to_pack(git_indexer *idx, const void *data, size_t size)
page_offset = new_size % mmap_alignment;
page_start = new_size - page_offset;
- if (p_lseek(fd, page_start + mmap_alignment - 1, SEEK_SET) < 0 ||
- p_write(idx->pack->mwf.fd, data, 1) < 0) {
+ if (p_pwrite(idx->pack->mwf.fd, data, 1, page_start + mmap_alignment - 1) < 0) {
git_error_set(GIT_ERROR_OS, "cannot extend packfile '%s'", idx->pack->pack_name);
return -1;
}
diff --git a/src/merge.c b/src/merge.c
index e02ea9169..82b028b4a 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -2277,8 +2277,11 @@ static int create_virtual_base(
result->type = GIT_ANNOTATED_COMMIT_VIRTUAL;
result->index = index;
- insert_head_ids(&result->parents, one);
- insert_head_ids(&result->parents, two);
+ if (insert_head_ids(&result->parents, one) < 0 ||
+ insert_head_ids(&result->parents, two) < 0) {
+ git_annotated_commit_free(result);
+ return -1;
+ }
*out = result;
return 0;
diff --git a/src/midx.c b/src/midx.c
index ee93b03c1..d6bb9c1e7 100644
--- a/src/midx.c
+++ b/src/midx.c
@@ -353,18 +353,13 @@ bool git_midx_needs_refresh(
return true;
}
- if (p_lseek(fd, -GIT_OID_RAWSZ, SEEK_END) < 0) {
- p_close(fd);
- return true;
- }
-
- bytes_read = p_read(fd, &idx_checksum, GIT_OID_RAWSZ);
+ bytes_read = p_pread(fd, &idx_checksum, GIT_OID_RAWSZ, st.st_size - GIT_OID_RAWSZ);
p_close(fd);
if (bytes_read != GIT_OID_RAWSZ)
return true;
- return git_oid_cmp(&idx_checksum, &idx->checksum) == 0;
+ return !git_oid_equal(&idx_checksum, &idx->checksum);
}
int git_midx_entry_find(
diff --git a/src/mwindow.c b/src/mwindow.c
index 7832d9c8b..5fcae2eed 100644
--- a/src/mwindow.c
+++ b/src/mwindow.c
@@ -312,8 +312,10 @@ static int git_mwindow_find_lru_file_locked(git_mwindow_file **out)
current_file, &mru_window, NULL, true, GIT_MWINDOW__MRU)) {
continue;
}
- if (!lru_window || lru_window->last_used > mru_window->last_used)
+ if (!lru_window || lru_window->last_used > mru_window->last_used) {
+ lru_window = mru_window;
lru_file = current_file;
+ }
}
if (!lru_file) {
diff --git a/src/pack.c b/src/pack.c
index 30b1464b6..5d284ca9e 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -1130,8 +1130,7 @@ static int packfile_open_locked(struct git_pack_file *p)
/* Verify the pack matches its index. */
if (p->num_objects != ntohl(hdr.hdr_entries) ||
- p_lseek(p->mwf.fd, p->mwf.size - GIT_OID_RAWSZ, SEEK_SET) == -1 ||
- p_read(p->mwf.fd, sha1.id, GIT_OID_RAWSZ) < 0)
+ p_pread(p->mwf.fd, sha1.id, GIT_OID_RAWSZ, p->mwf.size - GIT_OID_RAWSZ) < 0)
goto cleanup;
idx_sha1 = ((unsigned char *)p->index_map.data) + p->index_map.len - 40;
diff --git a/src/patch.c b/src/patch.c
index 8f8bd7a08..f02c928de 100644
--- a/src/patch.c
+++ b/src/patch.c
@@ -204,6 +204,11 @@ int git_patch_get_line_in_hunk(
return 0;
}
+git_repository *git_patch_owner(const git_patch *patch)
+{
+ return patch->repo;
+}
+
int git_patch_from_diff(git_patch **out, git_diff *diff, size_t idx)
{
GIT_ASSERT_ARG(out);
diff --git a/src/refdb_fs.c b/src/refdb_fs.c
index aef5ab237..a5a6b3c0e 100644
--- a/src/refdb_fs.c
+++ b/src/refdb_fs.c
@@ -254,7 +254,8 @@ static int loose_lookup_to_packfile(refdb_fs_backend *backend, const char *name)
if ((error = loose_parse_oid(&oid, name, &ref_file)) < 0)
goto done;
- git_sortedcache_wlock(backend->refcache);
+ if ((error = git_sortedcache_wlock(backend->refcache)) < 0)
+ goto done;
if (!(error = git_sortedcache_upsert(
(void **)&ref, backend->refcache, name))) {
@@ -760,7 +761,8 @@ static int reference_path_available(
}
}
- git_sortedcache_rlock(backend->refcache);
+ if ((error = git_sortedcache_rlock(backend->refcache)) < 0)
+ return error;
for (i = 0; i < git_sortedcache_entrycount(backend->refcache); ++i) {
struct packref *ref = git_sortedcache_entry(backend->refcache, i);
diff --git a/src/refs.c b/src/refs.c
index a954b8359..4900afabf 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -1343,7 +1343,7 @@ const char *git_reference__shorthand(const char *name)
else if (!git__prefixcmp(name, GIT_REFS_DIR))
return name + strlen(GIT_REFS_DIR);
- /* No shorthands are avaiable, so just return the name */
+ /* No shorthands are available, so just return the name. */
return name;
}
diff --git a/src/remote.c b/src/remote.c
index 29e15bbdf..5f6ba5bf7 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -121,7 +121,7 @@ static int write_add_refspec(git_repository *repo, const char *name, const char
return error;
/*
- * "$^" is a unmatcheable regexp: it will not match anything at all, so
+ * "$^" is an unmatchable regexp: it will not match anything at all, so
* all values will be considered new and we will not replace any
* present value.
*/
@@ -1141,6 +1141,16 @@ static int remote_head_for_ref(git_remote_head **out, git_remote *remote, git_re
ref_name = git_reference_name(resolved_ref);
}
+ /*
+ * The ref name may be unresolvable - perhaps it's pointing to
+ * something invalid. In this case, there is no remote head for
+ * this ref.
+ */
+ if (!ref_name) {
+ error = 0;
+ goto cleanup;
+ }
+
if ((error = ref_to_update(&update, &remote_name, remote, spec, ref_name)) < 0)
goto cleanup;
@@ -1307,7 +1317,7 @@ int git_remote_prune(git_remote *remote, const git_remote_callbacks *callbacks)
if (error == GIT_ENOTFOUND)
continue;
- /* if we did find a source, remove it from the candiates */
+ /* If we did find a source, remove it from the candidates. */
if ((error = git_vector_set((void **) &src_name, &candidates, i, NULL)) < 0)
goto cleanup;
@@ -1672,7 +1682,7 @@ int git_remote_update_tips(
goto out;
}
- /* only try to do opportunisitic updates if the refpec lists differ */
+ /* Only try to do opportunistic updates if the refpec lists differ. */
if (remote->passed_refspecs)
error = opportunistic_updates(remote, callbacks, &refs, reflog_message);
diff --git a/src/repository.c b/src/repository.c
index 948413d17..de1a89582 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -2092,7 +2092,8 @@ static int repo_init_head(const char *repo_dir, const char *given)
if (given) {
initial_head = given;
} else if ((error = git_config_open_default(&cfg)) >= 0 &&
- (error = git_config_get_string_buf(&cfg_branch, cfg, "init.defaultbranch")) >= 0) {
+ (error = git_config_get_string_buf(&cfg_branch, cfg, "init.defaultbranch")) >= 0 &&
+ *cfg_branch.ptr) {
initial_head = cfg_branch.ptr;
}
diff --git a/src/revparse.c b/src/revparse.c
index 4b919d32a..b0c312d72 100644
--- a/src/revparse.c
+++ b/src/revparse.c
@@ -894,7 +894,7 @@ int git_revparse(
if ((dotdot = strstr(spec, "..")) != NULL) {
char *lstr;
const char *rstr;
- revspec->flags = GIT_REVPARSE_RANGE;
+ revspec->flags = GIT_REVSPEC_RANGE;
/*
* Following git.git, don't allow '..' because it makes command line
@@ -910,7 +910,7 @@ int git_revparse(
lstr = git__substrdup(spec, dotdot - spec);
rstr = dotdot + 2;
if (dotdot[2] == '.') {
- revspec->flags |= GIT_REVPARSE_MERGE_BASE;
+ revspec->flags |= GIT_REVSPEC_MERGE_BASE;
rstr++;
}
@@ -928,7 +928,7 @@ int git_revparse(
git__free((void*)lstr);
} else {
- revspec->flags = GIT_REVPARSE_SINGLE;
+ revspec->flags = GIT_REVSPEC_SINGLE;
error = git_revparse_single(&revspec->from, repo, spec);
}
diff --git a/src/revwalk.c b/src/revwalk.c
index 249cb16bf..a686a9f6f 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -238,7 +238,7 @@ int git_revwalk_push_range(git_revwalk *walk, const char *range)
goto out;
}
- if (revspec.flags & GIT_REVPARSE_MERGE_BASE) {
+ if (revspec.flags & GIT_REVSPEC_MERGE_BASE) {
/* TODO: support "<commit>...<commit>" */
git_error_set(GIT_ERROR_INVALID, "symmetric differences not implemented in revwalk");
error = GIT_EINVALIDSPEC;
diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c
index 54aacdba3..a2a71be95 100644
--- a/src/transports/winhttp.c
+++ b/src/transports/winhttp.c
@@ -268,7 +268,7 @@ static int acquire_fallback_cred(
pISM->lpVtbl->Release(pISM);
}
- /* Only unitialize if the call to CoInitializeEx was successful. */
+ /* Only uninitialize if the call to CoInitializeEx was successful. */
if (SUCCEEDED(hCoInitResult))
CoUninitialize();
}
diff --git a/src/win32/w32_leakcheck.c b/src/win32/w32_leakcheck.c
index 95187a570..ef1700443 100644
--- a/src/win32/w32_leakcheck.c
+++ b/src/win32/w32_leakcheck.c
@@ -513,7 +513,7 @@ int git_win32_leakcheck_stacktrace_dump(
*/
void git_win32_leakcheck_stacktrace_cleanup(void)
{
- /* At shutdown/cleanup, dump cummulative leak info
+ /* At shutdown/cleanup, dump cumulative leak info
* with everything since startup. This might generate
* extra noise if the caller has been doing checkpoint
* dumps, but it might also eliminate some false
diff --git a/tests/clone/nonetwork.c b/tests/clone/nonetwork.c
index 7ca49085c..d4da3d3af 100644
--- a/tests/clone/nonetwork.c
+++ b/tests/clone/nonetwork.c
@@ -158,6 +158,8 @@ void test_clone_nonetwork__can_prevent_the_checkout_of_a_standard_repo(void)
void test_clone_nonetwork__can_checkout_given_branch(void)
{
+ git_reference *remote_head;
+
g_options.checkout_branch = "test";
cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
@@ -167,6 +169,12 @@ void test_clone_nonetwork__can_checkout_given_branch(void)
cl_assert_equal_s(git_reference_name(g_ref), "refs/heads/test");
cl_assert(git_path_exists("foo/readme.txt"));
+
+ cl_git_pass(git_reference_lookup(&remote_head, g_repo, "refs/remotes/origin/HEAD"));
+ cl_assert_equal_i(GIT_REFERENCE_SYMBOLIC, git_reference_type(remote_head));
+ cl_assert_equal_s("refs/remotes/origin/test", git_reference_symbolic_target(remote_head));
+
+ git_reference_free(remote_head);
}
static int clone_cancel_fetch_transfer_progress_cb(
diff --git a/tests/core/structinit.c b/tests/core/structinit.c
index 192096be3..b6377bdde 100644
--- a/tests/core/structinit.c
+++ b/tests/core/structinit.c
@@ -82,6 +82,11 @@ void test_core_structinit__compare(void)
git_blame_options, GIT_BLAME_OPTIONS_VERSION, \
GIT_BLAME_OPTIONS_INIT, git_blame_options_init);
+ /* blob_filter_options */
+ CHECK_MACRO_FUNC_INIT_EQUAL( \
+ git_blob_filter_options, GIT_BLOB_FILTER_OPTIONS_VERSION, \
+ GIT_BLOB_FILTER_OPTIONS_INIT, git_blob_filter_options_init);
+
/* checkout */
CHECK_MACRO_FUNC_INIT_EQUAL( \
git_checkout_options, GIT_CHECKOUT_OPTIONS_VERSION, \
diff --git a/tests/fetchhead/nonetwork.c b/tests/fetchhead/nonetwork.c
index 6cea6d166..02e7ecfdb 100644
--- a/tests/fetchhead/nonetwork.c
+++ b/tests/fetchhead/nonetwork.c
@@ -319,6 +319,16 @@ static int assert_master_for_merge(const char *ref, const char *url, const git_o
return 0;
}
+static int assert_none_for_merge(const char *ref, const char *url, const git_oid *id, unsigned int is_merge, void *data)
+{
+ GIT_UNUSED(ref);
+ GIT_UNUSED(url);
+ GIT_UNUSED(id);
+ GIT_UNUSED(data);
+
+ return is_merge ? -1 : 0;
+}
+
void test_fetchhead_nonetwork__unborn_with_upstream(void)
{
git_repository *repo;
@@ -366,6 +376,25 @@ void test_fetchhead_nonetwork__fetch_into_repo_with_symrefs(void)
cl_git_sandbox_cleanup();
}
+void test_fetchhead_nonetwork__fetch_into_repo_with_invalid_head(void)
+{
+ git_remote *remote;
+ char *strings[] = { "refs/heads/*:refs/remotes/origin/*" };
+ git_strarray refspecs = { strings, 1 };
+
+ cl_set_cleanup(&cleanup_repository, "./test1");
+ cl_git_pass(git_repository_init(&g_repo, "./test1", 0));
+
+ /* HEAD pointing to nonexistent branch */
+ cl_git_rewritefile("./test1/.git/HEAD", "ref: refs/heads/\n");
+
+ cl_git_pass(git_remote_create_anonymous(&remote, g_repo, cl_fixture("testrepo.git")));
+ cl_git_pass(git_remote_fetch(remote, &refspecs, NULL, NULL));
+ cl_git_pass(git_repository_fetchhead_foreach(g_repo, assert_none_for_merge, NULL));
+
+ git_remote_free(remote);
+}
+
void test_fetchhead_nonetwork__quote_in_branch_name(void)
{
cl_set_cleanup(&cleanup_repository, "./test1");
diff --git a/tests/filter/bare.c b/tests/filter/bare.c
index 430931ee8..7319b5203 100644
--- a/tests/filter/bare.c
+++ b/tests/filter/bare.c
@@ -10,7 +10,7 @@ void test_filter_bare__initialize(void)
cl_git_pass(git_repository_open(&g_repo, "crlf.git"));
filter_opts.flags |= GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES;
- filter_opts.flags |= GIT_BLOB_FILTER_ATTTRIBUTES_FROM_HEAD;
+ filter_opts.flags |= GIT_BLOB_FILTER_ATTRIBUTES_FROM_HEAD;
}
void test_filter_bare__cleanup(void)
diff --git a/tests/pack/midx.c b/tests/pack/midx.c
index 92d9ae24c..0d7efbef1 100644
--- a/tests/pack/midx.c
+++ b/tests/pack/midx.c
@@ -15,6 +15,7 @@ void test_pack_midx__parse(void)
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
cl_git_pass(git_buf_joinpath(&midx_path, git_repository_path(repo), "objects/pack/multi-pack-index"));
cl_git_pass(git_midx_open(&idx, git_buf_cstr(&midx_path)));
+ cl_assert_equal_i(git_midx_needs_refresh(idx, git_buf_cstr(&midx_path)), 0);
cl_git_pass(git_oid_fromstr(&id, "5001298e0c09ad9c34e4249bc5801c75e9754fa5"));
cl_git_pass(git_midx_entry_find(&e, idx, &id, GIT_OID_HEXSZ));
diff --git a/tests/refs/revparse.c b/tests/refs/revparse.c
index 3c4ed9af5..bc6e0a4c4 100644
--- a/tests/refs/revparse.c
+++ b/tests/refs/revparse.c
@@ -50,7 +50,7 @@ static void test_id_inrepo(
const char *spec,
const char *expected_left,
const char *expected_right,
- git_revparse_mode_t expected_flags,
+ git_revspec_t expected_flags,
git_repository *repo)
{
git_revspec revspec;
@@ -90,7 +90,7 @@ static void test_object_and_ref(const char *spec, const char *expected_oid, cons
static void test_rangelike(const char *rangelike,
const char *expected_left,
const char *expected_right,
- git_revparse_mode_t expected_revparseflags)
+ git_revspec_t expected_revparseflags)
{
char objstr[64] = {0};
git_revspec revspec;
@@ -117,7 +117,7 @@ static void test_id(
const char *spec,
const char *expected_left,
const char *expected_right,
- git_revparse_mode_t expected_flags)
+ git_revspec_t expected_flags)
{
test_id_inrepo(spec, expected_left, expected_right, expected_flags, g_repo);
}
@@ -735,53 +735,53 @@ void test_refs_revparse__range(void)
test_rangelike("be3563a^1..be3563a",
"9fd738e8f7967c078dceed8190330fc8648ee56a",
"be3563ae3f795b2b4353bcce3a527ad0a4f7f644",
- GIT_REVPARSE_RANGE);
+ GIT_REVSPEC_RANGE);
test_rangelike("be3563a^1...be3563a",
"9fd738e8f7967c078dceed8190330fc8648ee56a",
"be3563ae3f795b2b4353bcce3a527ad0a4f7f644",
- GIT_REVPARSE_RANGE | GIT_REVPARSE_MERGE_BASE);
+ GIT_REVSPEC_RANGE | GIT_REVSPEC_MERGE_BASE);
test_rangelike("be3563a^1.be3563a", NULL, NULL, 0);
}
void test_refs_revparse__parses_range_operator(void)
{
- test_id("HEAD", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", NULL, GIT_REVPARSE_SINGLE);
+ test_id("HEAD", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", NULL, GIT_REVSPEC_SINGLE);
test_id("HEAD~3..HEAD",
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045",
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
- GIT_REVPARSE_RANGE);
+ GIT_REVSPEC_RANGE);
test_id("HEAD~3...HEAD",
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045",
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
- GIT_REVPARSE_RANGE | GIT_REVPARSE_MERGE_BASE);
+ GIT_REVSPEC_RANGE | GIT_REVSPEC_MERGE_BASE);
test_id("HEAD~3..",
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045",
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
- GIT_REVPARSE_RANGE);
+ GIT_REVSPEC_RANGE);
test_id("HEAD~3...",
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045",
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
- GIT_REVPARSE_RANGE | GIT_REVPARSE_MERGE_BASE);
+ GIT_REVSPEC_RANGE | GIT_REVSPEC_MERGE_BASE);
test_id("..HEAD~3",
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045",
- GIT_REVPARSE_RANGE);
+ GIT_REVSPEC_RANGE);
test_id("...HEAD~3",
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045",
- GIT_REVPARSE_RANGE | GIT_REVPARSE_MERGE_BASE);
+ GIT_REVSPEC_RANGE | GIT_REVSPEC_MERGE_BASE);
test_id("...",
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
- GIT_REVPARSE_RANGE | GIT_REVPARSE_MERGE_BASE);
+ GIT_REVSPEC_RANGE | GIT_REVSPEC_MERGE_BASE);
test_invalid_revspec("..");
}
diff --git a/tests/repo/init.c b/tests/repo/init.c
index b86e09a58..01371ba78 100644
--- a/tests/repo/init.c
+++ b/tests/repo/init.c
@@ -688,3 +688,19 @@ void test_repo_init__defaultbranch_config(void)
git_reference_free(head);
}
+
+void test_repo_init__defaultbranch_config_empty(void)
+{
+ git_reference *head;
+
+ cl_set_cleanup(&cleanup_repository, "repo");
+
+ create_tmp_global_config("tmp_global_path", "init.defaultbranch", "");
+
+ cl_git_pass(git_repository_init(&g_repo, "repo", 0));
+ cl_git_pass(git_reference_lookup(&head, g_repo, "HEAD"));
+
+ cl_assert_equal_s("refs/heads/master", git_reference_symbolic_target(head));
+
+ git_reference_free(head);
+}