diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2014-03-18 19:41:03 +0100 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2014-03-18 19:58:52 +0100 |
commit | bac95e6e1e99b1e364c5ebd39887a8e24bc1ad9d (patch) | |
tree | ccbbd903a453f88cca47da9e8fbac4c9a87e8715 /src/refdb_fs.c | |
parent | 5dd7d2432ed77651110bcbb37479b2d4e5b01b19 (diff) | |
download | libgit2-bac95e6e1e99b1e364c5ebd39887a8e24bc1ad9d.tar.gz |
reflog: more comprehensive HEAD tests
The existing ones lack checking zeroed ids when switching back from an
unborn branch as well as what happens when detaching.
The reflog appending function mistakenly wrote zeros when dealing with a
detached HEAD. This explicitly checks for those situations and fixes
them.
Diffstat (limited to 'src/refdb_fs.c')
-rw-r--r-- | src/refdb_fs.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/refdb_fs.c b/src/refdb_fs.c index f494afa71..0c3011083 100644 --- a/src/refdb_fs.c +++ b/src/refdb_fs.c @@ -1555,7 +1555,7 @@ success: /* Append to the reflog, must be called under reference lock */ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, const git_oid *old, const git_oid *new, const git_signature *who, const char *message) { - int error, is_symbolic, was_symbolic = 0; + int error, is_symbolic, currently_exists; git_oid old_id = {{0}}, new_id = {{0}}; git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT; git_repository *repo = backend->repo; @@ -1573,14 +1573,14 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co if (error < 0 && error != GIT_ENOTFOUND) return error; - if (current_ref) - was_symbolic = current_ref->type == GIT_REF_SYMBOLIC; + currently_exists = !!current_ref; + git_reference_free(current_ref); /* From here on is_symoblic also means that it's HEAD */ if (old) { git_oid_cpy(&old_id, old); - } else if (!was_symbolic) { + } else if (currently_exists) { error = git_reference_name_to_id(&old_id, repo, ref->name); if (error == GIT_ENOTFOUND) { memset(&old_id, 0, sizeof(git_oid)); |