diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2014-02-05 11:47:33 +0100 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2014-02-05 12:07:57 +0100 |
commit | b7ae71ecf263047c427be099a3e1536cca17dc5d (patch) | |
tree | 76b9825136be14dd560afedf6c77351d701bc036 /src/refdb_fs.c | |
parent | f44fd59ed7b3533bf9cbaa07969a8a57475a77aa (diff) | |
download | libgit2-b7ae71ecf263047c427be099a3e1536cca17dc5d.tar.gz |
refs: catch cases where the ref type has changed
If the type of the on-disk reference has changed, the old value
comparison should fail.
Diffstat (limited to 'src/refdb_fs.c')
-rw-r--r-- | src/refdb_fs.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/refdb_fs.c b/src/refdb_fs.c index c9f9c0f1c..ea758deea 100644 --- a/src/refdb_fs.c +++ b/src/refdb_fs.c @@ -937,9 +937,21 @@ static int cmp_old_ref(int *cmp, git_refdb_backend *backend, const char *name, git_reference *old_ref = NULL; *cmp = 0; - if (old_id || old_target) { - if ((error = refdb_fs_backend__lookup(&old_ref, backend, name)) < 0) - goto out; + /* It "matches" if there is no old value to compare against */ + if (!old_id && !old_target) + return 0; + + if ((error = refdb_fs_backend__lookup(&old_ref, backend, name)) < 0) + goto out; + + /* If the types don't match, there's no way the values do */ + if (old_id && old_ref->type != GIT_REF_OID) { + *cmp = -1; + goto out; + } + if (old_target && old_ref->type != GIT_REF_SYMBOLIC) { + *cmp = 1; + goto out; } if (old_id && old_ref->type == GIT_REF_OID) |