summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/reflog.c2
-rw-r--r--src/stash.c40
2 files changed, 41 insertions, 1 deletions
diff --git a/src/reflog.c b/src/reflog.c
index f0a6e2a8c..5d1465eca 100644
--- a/src/reflog.c
+++ b/src/reflog.c
@@ -481,7 +481,7 @@ int git_reflog_drop(
/* If the oldest entry has just been removed... */
if (idx == 0) {
- /* ...clear the oid_old member of the "new" last entry */
+ /* ...clear the oid_old member of the "new" oldest entry */
if (git_oid_fromstr(&entry->oid_old, GIT_OID_HEX_ZERO) < 0)
return -1;
diff --git a/src/stash.c b/src/stash.c
index ed0b20f93..3011f00f0 100644
--- a/src/stash.c
+++ b/src/stash.c
@@ -617,3 +617,43 @@ cleanup:
git_reflog_free(reflog);
return error;
}
+
+int git_stash_drop(
+ git_repository *repo,
+ size_t index)
+{
+ git_reference *stash;
+ git_reflog *reflog = NULL;
+ size_t max;
+ int error;
+
+ if ((error = git_reference_lookup(&stash, repo, GIT_REFS_STASH_FILE)) < 0)
+ return error;
+
+ if ((error = git_reflog_read(&reflog, stash)) < 0)
+ goto cleanup;
+
+ max = git_reflog_entrycount(reflog);
+
+ if (index > max - 1) {
+ error = GIT_ENOTFOUND;
+ giterr_set(GITERR_STASH, "No stashed state at position %" PRIuZ, index);
+ goto cleanup;
+ }
+
+ if ((error = git_reflog_drop(reflog, max - index - 1, true)) < 0)
+ goto cleanup;
+
+ if ((error = git_reflog_write(reflog)) < 0)
+ goto cleanup;
+
+ if (max == 1) {
+ error = git_reference_delete(stash);
+ stash = NULL;
+ }
+
+cleanup:
+ git_reference_free(stash);
+ git_reflog_free(reflog);
+ return error;
+}