summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2017-06-06 14:54:19 +0200
committerPatrick Steinhardt <ps@pks.im>2017-06-08 12:05:35 +0200
commit0f642f3168e847c33a9607e4b8562e9ca955b26d (patch)
tree09615715f2a0ccbf1d96e40bed5b3a7ce6f44226
parent0c28c72d136548ac4db4422e5192ad273d5460c6 (diff)
downloadlibgit2-0f642f3168e847c33a9607e4b8562e9ca955b26d.tar.gz
refs: properly report errors from `update_wt_heads`
-rw-r--r--src/refs.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/refs.c b/src/refs.c
index 632a5299c..f7120d9ee 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -622,15 +622,25 @@ typedef struct {
static int update_wt_heads(git_repository *repo, const char *path, void *payload)
{
rename_cb_data *data = (rename_cb_data *) payload;
- git_reference *head;
+ git_reference *head = NULL;
char *gitdir = NULL;
- int error = 0;
+ int error;
+
+ if ((error = git_reference__read_head(&head, repo, path)) < 0) {
+ giterr_set(GITERR_REFERENCE, "could not read HEAD when renaming references");
+ goto out;
+ }
- if (git_reference__read_head(&head, repo, path) < 0 ||
- git_reference_type(head) != GIT_REF_SYMBOLIC ||
- git__strcmp(head->target.symbolic, data->old_name) != 0 ||
- (gitdir = git_path_dirname(path)) == NULL)
+ if ((gitdir = git_path_dirname(path)) == NULL) {
+ error = -1;
goto out;
+ }
+
+ if (git_reference_type(head) != GIT_REF_SYMBOLIC ||
+ git__strcmp(head->target.symbolic, data->old_name) != 0) {
+ error = 0;
+ goto out;
+ }
/* Update HEAD it was pointing to the reference being renamed */
if ((error = git_repository_create_head(gitdir, data->new_name)) < 0) {