Skip to content

Commit ae8bcad

Browse files
committed
Merge branch 'pw/stash-change-check-only-once' into jch
"git stash create/push" checked if there are checks that need to be saved twice, which has been reduced to just once. * pw/stash-change-check-only-once: stash push: remove duplicate changes detection stash create: remove duplicate changes detection
2 parents 8932173 + c6622e7 commit ae8bcad

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

‎builtin/stash.c‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,7 @@ static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_b
14941494
}
14951495

14961496
if (!check_changes(ps, include_untracked, &untracked_files)) {
1497-
ret = 1;
1497+
ret = 2;
14981498
goto done;
14991499
}
15001500

@@ -1611,8 +1611,6 @@ static int create_stash(int argc, const char **argv, const char *prefix UNUSED,
16111611
strbuf_join_argv(&stash_msg_buf, argc - 1, ++argv, ' ');
16121612

16131613
memset(&ps, 0, sizeof(ps));
1614-
if (!check_changes_tracked_files(&ps))
1615-
return 0;
16161614

16171615
ret = do_create_stash(&ps, &stash_msg_buf, 0, 0, NULL, 0, &info,
16181616
NULL, 0);
@@ -1621,7 +1619,11 @@ static int create_stash(int argc, const char **argv, const char *prefix UNUSED,
16211619

16221620
free_stash_info(&info);
16231621
strbuf_release(&stash_msg_buf);
1624-
return ret;
1622+
/*
1623+
* ret is greater than zero if there were no changes. In this case,
1624+
* we should not error out.
1625+
*/
1626+
return ret < 0;
16251627
}
16261628

16271629
static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int quiet,
@@ -1682,12 +1684,6 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
16821684
goto done;
16831685
}
16841686

1685-
if (!check_changes(ps, include_untracked, &untracked_files)) {
1686-
if (!quiet)
1687-
printf_ln(_("No local changes to save"));
1688-
goto done;
1689-
}
1690-
16911687
if (!refs_reflog_exists(get_main_ref_store(the_repository), ref_stash) && do_clear_stash()) {
16921688
ret = -1;
16931689
if (!quiet)
@@ -1697,8 +1693,15 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
16971693

16981694
if (stash_msg)
16991695
strbuf_addstr(&stash_msg_buf, stash_msg);
1700-
if (do_create_stash(ps, &stash_msg_buf, include_untracked, patch_mode,
1701-
interactive_opts, only_staged, &info, &patch, quiet)) {
1696+
ret = do_create_stash(ps, &stash_msg_buf, include_untracked,
1697+
patch_mode, interactive_opts, only_staged, &info,
1698+
&patch, quiet);
1699+
if (ret == 2) {
1700+
if (!quiet)
1701+
printf_ln(_("No local changes to save"));
1702+
ret = 0;
1703+
goto done;
1704+
} else if (ret) {
17021705
ret = -1;
17031706
goto done;
17041707
}

0 commit comments

Comments
 (0)