2 * Copyright (C) the libgit2 contributors. All rights reserved.
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
9 #include "repository.h"
14 #include "git2/diff.h"
15 #include "git2/stash.h"
16 #include "git2/status.h"
17 #include "git2/checkout.h"
18 #include "git2/index.h"
19 #include "git2/transaction.h"
20 #include "git2/merge.h"
22 #include "signature.h"
26 static int create_error(int error
, const char *msg
)
28 giterr_set(GITERR_STASH
, "Cannot stash changes - %s", msg
);
32 static int retrieve_head(git_reference
**out
, git_repository
*repo
)
34 int error
= git_repository_head(out
, repo
);
36 if (error
== GIT_EUNBORNBRANCH
)
37 return create_error(error
, "You do not have the initial commit yet.");
42 static int append_abbreviated_oid(git_buf
*out
, const git_oid
*b_commit
)
46 formatted_oid
= git_oid_allocfmt(b_commit
);
47 GITERR_CHECK_ALLOC(formatted_oid
);
49 git_buf_put(out
, formatted_oid
, 7);
50 git__free(formatted_oid
);
52 return git_buf_oom(out
) ? -1 : 0;
55 static int append_commit_description(git_buf
*out
, git_commit
* commit
)
57 const char *summary
= git_commit_summary(commit
);
58 GITERR_CHECK_ALLOC(summary
);
60 if (append_abbreviated_oid(out
, git_commit_id(commit
)) < 0)
63 git_buf_putc(out
, ' ');
64 git_buf_puts(out
, summary
);
65 git_buf_putc(out
, '\n');
67 return git_buf_oom(out
) ? -1 : 0;
70 static int retrieve_base_commit_and_message(
71 git_commit
**b_commit
,
72 git_buf
*stash_message
,
75 git_reference
*head
= NULL
;
78 if ((error
= retrieve_head(&head
, repo
)) < 0)
81 if (strcmp("HEAD", git_reference_name(head
)) == 0)
82 error
= git_buf_puts(stash_message
, "(no branch): ");
84 error
= git_buf_printf(
87 git_reference_name(head
) + strlen(GIT_REFS_HEADS_DIR
));
91 if ((error
= git_commit_lookup(
92 b_commit
, repo
, git_reference_target(head
))) < 0)
95 if ((error
= append_commit_description(stash_message
, *b_commit
)) < 0)
99 git_reference_free(head
);
103 static int build_tree_from_index(git_tree
**out
, git_index
*index
)
108 if ((error
= git_index_write_tree(&i_tree_oid
, index
)) < 0)
111 return git_tree_lookup(out
, git_index_owner(index
), &i_tree_oid
);
114 static int commit_index(
115 git_commit
**i_commit
,
117 const git_signature
*stasher
,
119 const git_commit
*parent
)
121 git_tree
*i_tree
= NULL
;
122 git_oid i_commit_oid
;
123 git_buf msg
= GIT_BUF_INIT
;
126 if ((error
= build_tree_from_index(&i_tree
, index
)) < 0)
129 if ((error
= git_buf_printf(&msg
, "index on %s\n", message
)) < 0)
132 if ((error
= git_commit_create(
134 git_index_owner(index
),
145 error
= git_commit_lookup(i_commit
, git_index_owner(index
), &i_commit_oid
);
148 git_tree_free(i_tree
);
153 struct stash_update_rules
{
154 bool include_changed
;
155 bool include_untracked
;
156 bool include_ignored
;
159 static int stash_update_index_from_diff(
161 const git_diff
*diff
,
162 struct stash_update_rules
*data
)
165 size_t d
, max_d
= git_diff_num_deltas(diff
);
167 for (d
= 0; !error
&& d
< max_d
; ++d
) {
168 const char *add_path
= NULL
;
169 const git_diff_delta
*delta
= git_diff_get_delta(diff
, d
);
171 switch (delta
->status
) {
172 case GIT_DELTA_IGNORED
:
173 if (data
->include_ignored
)
174 add_path
= delta
->new_file
.path
;
177 case GIT_DELTA_UNTRACKED
:
178 if (data
->include_untracked
&&
179 delta
->new_file
.mode
!= GIT_FILEMODE_TREE
)
180 add_path
= delta
->new_file
.path
;
183 case GIT_DELTA_ADDED
:
184 case GIT_DELTA_MODIFIED
:
185 if (data
->include_changed
)
186 add_path
= delta
->new_file
.path
;
189 case GIT_DELTA_DELETED
:
190 if (data
->include_changed
&&
191 !git_index_find(NULL
, index
, delta
->old_file
.path
))
192 error
= git_index_remove(index
, delta
->old_file
.path
, 0);
199 "Cannot update index. Unimplemented status (%d)",
204 if (add_path
!= NULL
)
205 error
= git_index_add_bypath(index
, add_path
);
211 static int build_untracked_tree(
214 git_commit
*i_commit
,
217 git_tree
*i_tree
= NULL
;
218 git_diff
*diff
= NULL
;
219 git_diff_options opts
= GIT_DIFF_OPTIONS_INIT
;
220 struct stash_update_rules data
= {0};
223 git_index_clear(index
);
225 if (flags
& GIT_STASH_INCLUDE_UNTRACKED
) {
226 opts
.flags
|= GIT_DIFF_INCLUDE_UNTRACKED
|
227 GIT_DIFF_RECURSE_UNTRACKED_DIRS
;
228 data
.include_untracked
= true;
231 if (flags
& GIT_STASH_INCLUDE_IGNORED
) {
232 opts
.flags
|= GIT_DIFF_INCLUDE_IGNORED
|
233 GIT_DIFF_RECURSE_IGNORED_DIRS
;
234 data
.include_ignored
= true;
237 if ((error
= git_commit_tree(&i_tree
, i_commit
)) < 0)
240 if ((error
= git_diff_tree_to_workdir(
241 &diff
, git_index_owner(index
), i_tree
, &opts
)) < 0)
244 if ((error
= stash_update_index_from_diff(index
, diff
, &data
)) < 0)
247 error
= build_tree_from_index(tree_out
, index
);
251 git_tree_free(i_tree
);
255 static int commit_untracked(
256 git_commit
**u_commit
,
258 const git_signature
*stasher
,
260 git_commit
*i_commit
,
263 git_tree
*u_tree
= NULL
;
264 git_oid u_commit_oid
;
265 git_buf msg
= GIT_BUF_INIT
;
268 if ((error
= build_untracked_tree(&u_tree
, index
, i_commit
, flags
)) < 0)
271 if ((error
= git_buf_printf(&msg
, "untracked files on %s\n", message
)) < 0)
274 if ((error
= git_commit_create(
276 git_index_owner(index
),
287 error
= git_commit_lookup(u_commit
, git_index_owner(index
), &u_commit_oid
);
290 git_tree_free(u_tree
);
295 static int build_workdir_tree(
298 git_commit
*b_commit
)
300 git_repository
*repo
= git_index_owner(index
);
301 git_tree
*b_tree
= NULL
;
302 git_diff
*diff
= NULL
;
303 git_diff_options opts
= GIT_DIFF_OPTIONS_INIT
;
304 struct stash_update_rules data
= {0};
307 opts
.flags
= GIT_DIFF_IGNORE_SUBMODULES
;
309 if ((error
= git_commit_tree(&b_tree
, b_commit
)) < 0)
312 if ((error
= git_diff_tree_to_workdir(&diff
, repo
, b_tree
, &opts
)) < 0)
315 data
.include_changed
= true;
317 if ((error
= stash_update_index_from_diff(index
, diff
, &data
)) < 0)
320 error
= build_tree_from_index(tree_out
, index
);
324 git_tree_free(b_tree
);
329 static int commit_worktree(
330 git_oid
*w_commit_oid
,
332 const git_signature
*stasher
,
334 git_commit
*i_commit
,
335 git_commit
*b_commit
,
336 git_commit
*u_commit
)
339 git_tree
*w_tree
= NULL
, *i_tree
= NULL
;
340 const git_commit
*parents
[] = { NULL
, NULL
, NULL
};
342 parents
[0] = b_commit
;
343 parents
[1] = i_commit
;
344 parents
[2] = u_commit
;
346 if ((error
= git_commit_tree(&i_tree
, i_commit
)) < 0)
349 if ((error
= git_index_read_tree(index
, i_tree
)) < 0)
352 if ((error
= build_workdir_tree(&w_tree
, index
, b_commit
)) < 0)
355 error
= git_commit_create(
357 git_index_owner(index
),
368 git_tree_free(i_tree
);
369 git_tree_free(w_tree
);
373 static int prepare_worktree_commit_message(
375 const char *user_message
)
377 git_buf buf
= GIT_BUF_INIT
;
380 if ((error
= git_buf_set(&buf
, git_buf_cstr(msg
), git_buf_len(msg
))) < 0)
386 git_buf_printf(msg
, "WIP on %s", git_buf_cstr(&buf
));
390 if ((colon
= strchr(git_buf_cstr(&buf
), ':')) == NULL
)
393 git_buf_puts(msg
, "On ");
394 git_buf_put(msg
, git_buf_cstr(&buf
), colon
- buf
.ptr
);
395 git_buf_printf(msg
, ": %s\n", user_message
);
398 error
= (git_buf_oom(msg
) || git_buf_oom(&buf
)) ? -1 : 0;
406 static int update_reflog(
407 git_oid
*w_commit_oid
,
408 git_repository
*repo
,
411 git_reference
*stash
;
414 if ((error
= git_reference_ensure_log(repo
, GIT_REFS_STASH_FILE
)) < 0)
417 error
= git_reference_create(&stash
, repo
, GIT_REFS_STASH_FILE
, w_commit_oid
, 1, message
);
419 git_reference_free(stash
);
424 static int is_dirty_cb(const char *path
, unsigned int status
, void *payload
)
430 return GIT_PASSTHROUGH
;
433 static int ensure_there_are_changes_to_stash(
434 git_repository
*repo
,
435 bool include_untracked_files
,
436 bool include_ignored_files
)
439 git_status_options opts
= GIT_STATUS_OPTIONS_INIT
;
441 opts
.show
= GIT_STATUS_SHOW_INDEX_AND_WORKDIR
;
442 opts
.flags
= GIT_STATUS_OPT_EXCLUDE_SUBMODULES
;
444 if (include_untracked_files
)
445 opts
.flags
|= GIT_STATUS_OPT_INCLUDE_UNTRACKED
|
446 GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS
;
448 if (include_ignored_files
)
449 opts
.flags
|= GIT_STATUS_OPT_INCLUDE_IGNORED
|
450 GIT_STATUS_OPT_RECURSE_IGNORED_DIRS
;
452 error
= git_status_foreach_ext(repo
, &opts
, is_dirty_cb
, NULL
);
454 if (error
== GIT_PASSTHROUGH
)
458 return create_error(GIT_ENOTFOUND
, "There is nothing to stash.");
463 static int reset_index_and_workdir(
464 git_repository
*repo
,
466 bool remove_untracked
,
469 git_checkout_options opts
= GIT_CHECKOUT_OPTIONS_INIT
;
471 opts
.checkout_strategy
= GIT_CHECKOUT_FORCE
;
473 if (remove_untracked
)
474 opts
.checkout_strategy
|= GIT_CHECKOUT_REMOVE_UNTRACKED
;
477 opts
.checkout_strategy
|= GIT_CHECKOUT_REMOVE_IGNORED
;
479 return git_checkout_tree(repo
, (git_object
*)commit
, &opts
);
484 git_repository
*repo
,
485 const git_signature
*stasher
,
489 git_index
*index
= NULL
;
490 git_commit
*b_commit
= NULL
, *i_commit
= NULL
, *u_commit
= NULL
;
491 git_buf msg
= GIT_BUF_INIT
;
494 assert(out
&& repo
&& stasher
);
496 if ((error
= git_repository__ensure_not_bare(repo
, "stash save")) < 0)
499 if ((error
= retrieve_base_commit_and_message(&b_commit
, &msg
, repo
)) < 0)
502 if ((error
= ensure_there_are_changes_to_stash(
504 (flags
& GIT_STASH_INCLUDE_UNTRACKED
) != 0,
505 (flags
& GIT_STASH_INCLUDE_IGNORED
) != 0)) < 0)
508 if ((error
= git_repository_index(&index
, repo
)) < 0)
511 if ((error
= commit_index(
512 &i_commit
, index
, stasher
, git_buf_cstr(&msg
), b_commit
)) < 0)
515 if ((flags
& (GIT_STASH_INCLUDE_UNTRACKED
| GIT_STASH_INCLUDE_IGNORED
)) &&
516 (error
= commit_untracked(
517 &u_commit
, index
, stasher
, git_buf_cstr(&msg
),
518 i_commit
, flags
)) < 0)
521 if ((error
= prepare_worktree_commit_message(&msg
, message
)) < 0)
524 if ((error
= commit_worktree(
525 out
, index
, stasher
, git_buf_cstr(&msg
),
526 i_commit
, b_commit
, u_commit
)) < 0)
531 if ((error
= update_reflog(out
, repo
, git_buf_cstr(&msg
))) < 0)
534 if ((error
= reset_index_and_workdir(
536 ((flags
& GIT_STASH_KEEP_INDEX
) != 0) ? i_commit
: b_commit
,
537 (flags
& GIT_STASH_INCLUDE_UNTRACKED
) != 0,
538 (flags
& GIT_STASH_INCLUDE_IGNORED
) != 0)) < 0)
544 git_commit_free(i_commit
);
545 git_commit_free(b_commit
);
546 git_commit_free(u_commit
);
547 git_index_free(index
);
552 static int retrieve_stash_commit(
554 git_repository
*repo
,
557 git_reference
*stash
= NULL
;
558 git_reflog
*reflog
= NULL
;
561 const git_reflog_entry
*entry
;
563 if ((error
= git_reference_lookup(&stash
, repo
, GIT_REFS_STASH_FILE
)) < 0)
566 if ((error
= git_reflog_read(&reflog
, repo
, GIT_REFS_STASH_FILE
)) < 0)
569 max
= git_reflog_entrycount(reflog
);
570 if (!max
|| index
> max
- 1) {
571 error
= GIT_ENOTFOUND
;
572 giterr_set(GITERR_STASH
, "No stashed state at position %" PRIuZ
, index
);
576 entry
= git_reflog_entry_byindex(reflog
, index
);
577 if ((error
= git_commit_lookup(commit
, repo
, git_reflog_entry_id_new(entry
))) < 0)
581 git_reference_free(stash
);
582 git_reflog_free(reflog
);
586 static int retrieve_stash_trees(
587 git_tree
**out_stash_tree
,
588 git_tree
**out_base_tree
,
589 git_tree
**out_index_tree
,
590 git_tree
**out_index_parent_tree
,
591 git_tree
**out_untracked_tree
,
592 git_commit
*stash_commit
)
594 git_tree
*stash_tree
= NULL
;
595 git_commit
*base_commit
= NULL
;
596 git_tree
*base_tree
= NULL
;
597 git_commit
*index_commit
= NULL
;
598 git_tree
*index_tree
= NULL
;
599 git_commit
*index_parent_commit
= NULL
;
600 git_tree
*index_parent_tree
= NULL
;
601 git_commit
*untracked_commit
= NULL
;
602 git_tree
*untracked_tree
= NULL
;
605 if ((error
= git_commit_tree(&stash_tree
, stash_commit
)) < 0)
608 if ((error
= git_commit_parent(&base_commit
, stash_commit
, 0)) < 0)
610 if ((error
= git_commit_tree(&base_tree
, base_commit
)) < 0)
613 if ((error
= git_commit_parent(&index_commit
, stash_commit
, 1)) < 0)
615 if ((error
= git_commit_tree(&index_tree
, index_commit
)) < 0)
618 if ((error
= git_commit_parent(&index_parent_commit
, index_commit
, 0)) < 0)
620 if ((error
= git_commit_tree(&index_parent_tree
, index_parent_commit
)) < 0)
623 if (git_commit_parentcount(stash_commit
) == 3) {
624 if ((error
= git_commit_parent(&untracked_commit
, stash_commit
, 2)) < 0)
626 if ((error
= git_commit_tree(&untracked_tree
, untracked_commit
)) < 0)
630 *out_stash_tree
= stash_tree
;
631 *out_base_tree
= base_tree
;
632 *out_index_tree
= index_tree
;
633 *out_index_parent_tree
= index_parent_tree
;
634 *out_untracked_tree
= untracked_tree
;
637 git_commit_free(untracked_commit
);
638 git_commit_free(index_parent_commit
);
639 git_commit_free(index_commit
);
640 git_commit_free(base_commit
);
642 git_tree_free(stash_tree
);
643 git_tree_free(base_tree
);
644 git_tree_free(index_tree
);
645 git_tree_free(index_parent_tree
);
646 git_tree_free(untracked_tree
);
651 static int merge_index_and_tree(
653 git_repository
*repo
,
654 git_tree
*ancestor_tree
,
655 git_index
*ours_index
,
656 git_tree
*theirs_tree
)
658 git_iterator
*ancestor
= NULL
, *ours
= NULL
, *theirs
= NULL
;
659 const git_iterator_flag_t flags
= GIT_ITERATOR_DONT_IGNORE_CASE
;
662 if ((error
= git_iterator_for_tree(&ancestor
, ancestor_tree
, flags
, NULL
, NULL
)) < 0 ||
663 (error
= git_iterator_for_index(&ours
, ours_index
, flags
, NULL
, NULL
)) < 0 ||
664 (error
= git_iterator_for_tree(&theirs
, theirs_tree
, flags
, NULL
, NULL
)) < 0)
667 error
= git_merge__iterators(out
, repo
, ancestor
, ours
, theirs
, NULL
);
670 git_iterator_free(ancestor
);
671 git_iterator_free(ours
);
672 git_iterator_free(theirs
);
676 static void normalize_checkout_options(
677 git_checkout_options
*checkout_opts
,
678 const git_checkout_options
*given_checkout_opts
)
680 if (given_checkout_opts
!= NULL
) {
681 memcpy(checkout_opts
, given_checkout_opts
, sizeof(git_checkout_options
));
683 git_checkout_options default_checkout_opts
= GIT_CHECKOUT_OPTIONS_INIT
;
684 default_checkout_opts
.checkout_strategy
= GIT_CHECKOUT_SAFE
;
686 memcpy(checkout_opts
, &default_checkout_opts
, sizeof(git_checkout_options
));
689 if (!checkout_opts
->our_label
)
690 checkout_opts
->our_label
= "Updated upstream";
692 if (!checkout_opts
->their_label
)
693 checkout_opts
->their_label
= "Stashed changes";
697 git_repository
*repo
,
699 const git_checkout_options
*given_checkout_opts
,
702 git_checkout_options checkout_opts
;
703 unsigned int checkout_strategy
;
704 git_commit
*stash_commit
= NULL
;
705 git_tree
*stash_tree
= NULL
;
706 git_tree
*stash_parent_tree
= NULL
;
707 git_tree
*index_tree
= NULL
;
708 git_tree
*index_parent_tree
= NULL
;
709 git_tree
*untracked_tree
= NULL
;
710 git_index
*repo_index
= NULL
;
711 git_index
*unstashed_index
= NULL
;
712 git_index
*modified_index
= NULL
;
713 git_index
*untracked_index
= NULL
;
716 normalize_checkout_options(&checkout_opts
, given_checkout_opts
);
717 checkout_strategy
= checkout_opts
.checkout_strategy
;
719 /* Retrieve commit corresponding to the given stash */
720 if ((error
= retrieve_stash_commit(&stash_commit
, repo
, index
)) < 0)
723 /* Retrieve all trees in the stash */
724 if ((error
= retrieve_stash_trees(
725 &stash_tree
, &stash_parent_tree
, &index_tree
,
726 &index_parent_tree
, &untracked_tree
, stash_commit
)) < 0)
729 /* Load repo index */
730 if ((error
= git_repository_index(&repo_index
, repo
)) < 0)
733 /* Restore index if required */
734 if ((flags
& GIT_APPLY_REINSTATE_INDEX
) &&
735 git_oid_cmp(git_tree_id(stash_parent_tree
), git_tree_id(index_tree
))) {
737 if ((error
= merge_index_and_tree(
738 &unstashed_index
, repo
, index_parent_tree
, repo_index
, index_tree
)) < 0)
741 if (git_index_has_conflicts(unstashed_index
)) {
742 error
= GIT_EMERGECONFLICT
;
747 /* Restore modified files in workdir */
748 if ((error
= merge_index_and_tree(
749 &modified_index
, repo
, stash_parent_tree
, repo_index
, stash_tree
)) < 0)
752 /* If applicable, restore untracked / ignored files in workdir */
753 if (untracked_tree
&&
754 (error
= merge_index_and_tree(&untracked_index
, repo
, NULL
, repo_index
, untracked_tree
)) < 0)
757 if (untracked_index
) {
758 checkout_opts
.checkout_strategy
|= GIT_CHECKOUT_DONT_UPDATE_INDEX
;
760 if ((error
= git_checkout_index(repo
, untracked_index
, &checkout_opts
)) < 0)
763 checkout_opts
.checkout_strategy
= checkout_strategy
;
767 /* If there are conflicts in the modified index, then we need to actually
768 * check that out as the repo's index. Otherwise, we don't update the
772 if (!git_index_has_conflicts(modified_index
))
773 checkout_opts
.checkout_strategy
|= GIT_CHECKOUT_DONT_UPDATE_INDEX
;
775 /* Check out the modified index using the existing repo index as baseline,
776 * so that existing modifications in the index can be rewritten even when
777 * checking out safely.
779 checkout_opts
.baseline_index
= repo_index
;
781 if ((error
= git_checkout_index(repo
, modified_index
, &checkout_opts
)) < 0)
784 if (unstashed_index
&& !git_index_has_conflicts(modified_index
)) {
785 if ((error
= git_index_read_index(repo_index
, unstashed_index
)) < 0)
790 git_index_free(untracked_index
);
791 git_index_free(modified_index
);
792 git_index_free(unstashed_index
);
793 git_index_free(repo_index
);
794 git_tree_free(untracked_tree
);
795 git_tree_free(index_parent_tree
);
796 git_tree_free(index_tree
);
797 git_tree_free(stash_parent_tree
);
798 git_tree_free(stash_tree
);
799 git_commit_free(stash_commit
);
803 int git_stash_foreach(
804 git_repository
*repo
,
805 git_stash_cb callback
,
808 git_reference
*stash
;
809 git_reflog
*reflog
= NULL
;
812 const git_reflog_entry
*entry
;
814 error
= git_reference_lookup(&stash
, repo
, GIT_REFS_STASH_FILE
);
815 if (error
== GIT_ENOTFOUND
) {
822 if ((error
= git_reflog_read(&reflog
, repo
, GIT_REFS_STASH_FILE
)) < 0)
825 max
= git_reflog_entrycount(reflog
);
826 for (i
= 0; i
< max
; i
++) {
827 entry
= git_reflog_entry_byindex(reflog
, i
);
830 git_reflog_entry_message(entry
),
831 git_reflog_entry_id_new(entry
),
835 giterr_set_after_callback(error
);
841 git_reference_free(stash
);
842 git_reflog_free(reflog
);
847 git_repository
*repo
,
851 git_reference
*stash
= NULL
;
852 git_reflog
*reflog
= NULL
;
856 if ((error
= git_transaction_new(&tx
, repo
)) < 0)
859 if ((error
= git_transaction_lock_ref(tx
, GIT_REFS_STASH_FILE
)) < 0)
862 if ((error
= git_reference_lookup(&stash
, repo
, GIT_REFS_STASH_FILE
)) < 0)
865 if ((error
= git_reflog_read(&reflog
, repo
, GIT_REFS_STASH_FILE
)) < 0)
868 max
= git_reflog_entrycount(reflog
);
870 if (!max
|| index
> max
- 1) {
871 error
= GIT_ENOTFOUND
;
872 giterr_set(GITERR_STASH
, "No stashed state at position %" PRIuZ
, index
);
876 if ((error
= git_reflog_drop(reflog
, index
, true)) < 0)
879 if ((error
= git_transaction_set_reflog(tx
, GIT_REFS_STASH_FILE
, reflog
)) < 0)
883 if ((error
= git_transaction_remove(tx
, GIT_REFS_STASH_FILE
)) < 0)
885 } else if (index
== 0) {
886 const git_reflog_entry
*entry
;
888 entry
= git_reflog_entry_byindex(reflog
, 0);
889 if ((error
= git_transaction_set_target(tx
, GIT_REFS_STASH_FILE
, &entry
->oid_cur
, NULL
, NULL
)) < 0)
893 error
= git_transaction_commit(tx
);
896 git_reference_free(stash
);
897 git_transaction_free(tx
);
898 git_reflog_free(reflog
);
903 git_repository
*repo
,
905 const git_checkout_options
*checkout_options
,
910 if ((error
= git_stash_apply(repo
, index
, checkout_options
, flags
)) < 0)
913 return git_stash_drop(repo
, index
);