mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-06 11:19:47 +00:00
stash: Update the reference when dropping the topmost stash
This commit is contained in:
parent
39bcb4deb8
commit
9ccab8dfb8
@ -646,6 +646,12 @@ int git_stash_drop(
|
|||||||
if (max == 1) {
|
if (max == 1) {
|
||||||
error = git_reference_delete(stash);
|
error = git_reference_delete(stash);
|
||||||
stash = NULL;
|
stash = NULL;
|
||||||
|
} else if (index == 0) {
|
||||||
|
const git_reflog_entry *entry;
|
||||||
|
|
||||||
|
entry = git_reflog_entry_byindex(reflog, 0);
|
||||||
|
|
||||||
|
error = git_reference_set_target(stash, &entry->oid_cur);
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
@ -137,3 +137,36 @@ void test_stash_drop__dropping_the_last_entry_removes_the_stash(void)
|
|||||||
cl_git_fail_with(
|
cl_git_fail_with(
|
||||||
git_reference_lookup(&stash, repo, GIT_REFS_STASH_FILE), GIT_ENOTFOUND);
|
git_reference_lookup(&stash, repo, GIT_REFS_STASH_FILE), GIT_ENOTFOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void retrieve_top_stash_id(git_oid *out)
|
||||||
|
{
|
||||||
|
git_object *top_stash;
|
||||||
|
|
||||||
|
cl_git_pass(git_revparse_single(&top_stash, repo, "stash@{0}"));
|
||||||
|
cl_git_pass(git_reference_name_to_id(out, repo, GIT_REFS_STASH_FILE));
|
||||||
|
|
||||||
|
cl_assert_equal_i(true, git_oid_cmp(out, git_object_id(top_stash)) == 0);
|
||||||
|
|
||||||
|
git_object_free(top_stash);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_stash_drop__dropping_the_top_stash_updates_the_stash_reference(void)
|
||||||
|
{
|
||||||
|
git_object *next_top_stash;
|
||||||
|
git_oid oid;
|
||||||
|
|
||||||
|
push_three_states();
|
||||||
|
|
||||||
|
retrieve_top_stash_id(&oid);
|
||||||
|
|
||||||
|
cl_git_pass(git_revparse_single(&next_top_stash, repo, "stash@{1}"));
|
||||||
|
cl_assert_equal_i(
|
||||||
|
false, git_oid_cmp(&oid, git_object_id(next_top_stash)) == 0);
|
||||||
|
|
||||||
|
cl_git_pass(git_stash_drop(repo, 0));
|
||||||
|
|
||||||
|
retrieve_top_stash_id(&oid);
|
||||||
|
|
||||||
|
cl_assert_equal_i(
|
||||||
|
true, git_oid_cmp(&oid, git_object_id(next_top_stash)) == 0);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user