summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/branch.c16
-rw-r--r--src/commit.c17
-rw-r--r--src/refdb_fs.c5
-rw-r--r--src/reset.c1
-rw-r--r--src/transports/local.c3
5 files changed, 27 insertions, 15 deletions
diff --git a/src/branch.c b/src/branch.c
index 1ebaf8e24..7c888729d 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -66,16 +66,22 @@ int git_branch_create(
assert(branch_name && commit && ref_out);
assert(git_object_owner((const git_object *)commit) == repository);
- if (git_branch_lookup(&branch, repository, branch_name, GIT_BRANCH_LOCAL) == 0) {
- if ((is_head = git_branch_is_head(branch)) < 0) {
- error = is_head;
+
+ if (force && git_branch_lookup(&branch, repository, branch_name, GIT_BRANCH_LOCAL) == 0) {
+ error = git_branch_is_head(branch);
+ git_reference_free(branch);
+ branch = NULL;
+
+ if (error < 0)
goto cleanup;
- }
+
+ is_head = error;
}
if (is_head && force) {
giterr_set(GITERR_REFERENCE, "Cannot force update branch '%s' as it is "
- "the current HEAD of the repository.", git_reference_name(branch));
+ "the current HEAD of the repository.", branch_name);
+ error = -1;
goto cleanup;
}
diff --git a/src/commit.c b/src/commit.c
index 2f5a5b51e..255debe82 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -455,19 +455,18 @@ int git_commit_nth_gen_ancestor(
assert(ancestor && commit);
- current = (git_commit *)commit;
+ if (git_object_dup((git_object **) &current, (git_object *) commit) < 0)
+ return -1;
- if (n == 0)
- return git_commit_lookup(
- ancestor,
- commit->object.repo,
- git_object_id((const git_object *)commit));
+ if (n == 0) {
+ *ancestor = current;
+ return 0;
+ }
while (n--) {
- error = git_commit_parent(&parent, (git_commit *)current, 0);
+ error = git_commit_parent(&parent, current, 0);
- if (current != commit)
- git_commit_free(current);
+ git_commit_free(current);
if (error < 0)
return error;
diff --git a/src/refdb_fs.c b/src/refdb_fs.c
index 3219b0519..8a26bec0b 100644
--- a/src/refdb_fs.c
+++ b/src/refdb_fs.c
@@ -1343,7 +1343,10 @@ static int refdb_reflog_fs__ensure_log(git_refdb_backend *_backend, const char *
if ((error = retrieve_reflog_path(&path, repo, name)) < 0)
return error;
- return create_new_reflog_file(git_buf_cstr(&path));
+ error = create_new_reflog_file(git_buf_cstr(&path));
+ git_buf_free(&path);
+
+ return error;
}
static int has_reflog(git_repository *repo, const char *name)
diff --git a/src/reset.c b/src/reset.c
index 07fd08863..2a78d312c 100644
--- a/src/reset.c
+++ b/src/reset.c
@@ -167,6 +167,7 @@ cleanup:
git_object_free(commit);
git_index_free(index);
git_tree_free(tree);
+ git_buf_free(&log_message_buf);
return error;
}
diff --git a/src/transports/local.c b/src/transports/local.c
index 26ada48e6..f8d511ed6 100644
--- a/src/transports/local.c
+++ b/src/transports/local.c
@@ -194,6 +194,9 @@ static int local_connect(
GIT_UNUSED(cred_acquire_cb);
GIT_UNUSED(cred_acquire_payload);
+ if (t->connected)
+ return 0;
+
t->url = git__strdup(url);
GITERR_CHECK_ALLOC(t->url);
t->direction = direction;