Skip to content

Commit dc2ae9a

Browse files
authored
Merge pull request #2119 from dscho/update-stash-to-current
Update the built-in `git stash` to the latest version
2 parents eb5d06f + 66af0b6 commit dc2ae9a

File tree

5 files changed

+29
-20
lines changed

5 files changed

+29
-20
lines changed

builtin/stash.c

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ static struct strbuf stash_index_path = STRBUF_INIT;
9999
* i_tree is set to the index tree
100100
* u_tree is set to the untracked files tree
101101
*/
102-
103102
struct stash_info {
104103
struct object_id w_commit;
105104
struct object_id b_commit;
@@ -320,11 +319,7 @@ static void add_diff_to_buf(struct diff_queue_struct *q,
320319
for (i = 0; i < q->nr; i++) {
321320
strbuf_addstr(data, q->queue[i]->one->path);
322321

323-
/*
324-
* The reason we add "0" at the end of this strbuf
325-
* is because we will pass the output further to
326-
* "git update-index -z ...".
327-
*/
322+
/* NUL-terminate: will be fed to update-index -z */
328323
strbuf_addch(data, '\0');
329324
}
330325
}
@@ -579,9 +574,9 @@ static int do_drop_stash(const char *prefix, struct stash_info *info, int quiet)
579574
static void assert_stash_ref(struct stash_info *info)
580575
{
581576
if (!info->is_stash_ref) {
582-
free_stash_info(info);
583577
error(_("'%s' is not a stash reference"), info->revision.buf);
584-
exit(128);
578+
free_stash_info(info);
579+
exit(1);
585580
}
586581
}
587582

@@ -837,7 +832,7 @@ static void add_pathspecs(struct argv_array *args,
837832
int i;
838833

839834
for (i = 0; i < ps.nr; i++)
840-
argv_array_push(args, ps.items[i].match);
835+
argv_array_push(args, ps.items[i].original);
841836
}
842837

843838
/*
@@ -869,7 +864,7 @@ static int get_untracked_files(struct pathspec ps, int include_untracked,
869864
found++;
870865
strbuf_addstr(untracked_files, ent->name);
871866
/* NUL-terminate: will be fed to update-index -z */
872-
strbuf_addch(untracked_files, 0);
867+
strbuf_addch(untracked_files, '\0');
873868
}
874869
free(ent);
875870
}
@@ -888,7 +883,6 @@ static int get_untracked_files(struct pathspec ps, int include_untracked,
888883
* = 0 if there are no changes.
889884
* > 0 if there are changes.
890885
*/
891-
892886
static int check_changes_tracked_files(struct pathspec ps)
893887
{
894888
int result;
@@ -928,7 +922,6 @@ static int check_changes_tracked_files(struct pathspec ps)
928922
* The function will fill `untracked_files` with the names of untracked files
929923
* It will return 1 if there were any changes and 0 if there were not.
930924
*/
931-
932925
static int check_changes(struct pathspec ps, int include_untracked,
933926
struct strbuf *untracked_files)
934927
{
@@ -1238,7 +1231,9 @@ static int create_stash(int argc, const char **argv, const char *prefix)
12381231
if (!check_changes_tracked_files(ps))
12391232
return 0;
12401233

1241-
if (!(ret = do_create_stash(ps, &stash_msg_buf, 0, 0, &info, NULL, 0)))
1234+
ret = do_create_stash(ps, &stash_msg_buf, 0, 0, &info,
1235+
NULL, 0);
1236+
if (!ret)
12421237
printf_ln("%s", oid_to_hex(&info.w_commit));
12431238

12441239
strbuf_release(&stash_msg_buf);
@@ -1429,8 +1424,6 @@ static int do_push_stash(struct pathspec ps, const char *stash_msg, int quiet,
14291424
if (keep_index < 1) {
14301425
struct child_process cp = CHILD_PROCESS_INIT;
14311426

1432-
discard_cache();
1433-
14341427
cp.git_cmd = 1;
14351428
argv_array_pushl(&cp.args, "reset", "-q", "--", NULL);
14361429
add_pathspecs(&cp.args, ps);
@@ -1475,7 +1468,8 @@ static int push_stash(int argc, const char **argv, const char *prefix)
14751468
git_stash_push_usage,
14761469
0);
14771470

1478-
parse_pathspec(&ps, 0, PATHSPEC_PREFER_FULL, prefix, argv);
1471+
parse_pathspec(&ps, 0, PATHSPEC_PREFER_FULL | PATHSPEC_PREFIX_ORIGIN,
1472+
prefix, argv);
14791473
return do_push_stash(ps, stash_msg, quiet, keep_index, patch_mode,
14801474
include_untracked);
14811475
}

cache.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,6 +1518,9 @@ extern const char *git_sequence_editor(void);
15181518
extern const char *git_pager(int stdout_is_tty);
15191519
extern int is_terminal_dumb(void);
15201520
extern int git_ident_config(const char *, const char *, void *);
1521+
/*
1522+
* Prepare an ident to fall back on if the user didn't configure it.
1523+
*/
15211524
void prepare_fallback_ident(const char *name, const char *email);
15221525
extern void reset_ident_date(void);
15231526

git-legacy-stash.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,17 @@ maybe_quiet () {
8686
shift
8787
if test -n "$GIT_QUIET"
8888
then
89-
eval "$@" 2>/dev/null
89+
"$@" 2>/dev/null
9090
else
91-
eval "$@"
91+
"$@"
9292
fi
9393
;;
9494
*)
9595
if test -n "$GIT_QUIET"
9696
then
97-
eval "$@" >/dev/null 2>&1
97+
"$@" >/dev/null 2>&1
9898
else
99-
eval "$@"
99+
"$@"
100100
fi
101101
;;
102102
esac

t/t3903-stash.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,12 @@ test_expect_success 'stash -- <subdir> works with binary files' '
11641164
test_path_is_file subdir/untracked
11651165
'
11661166

1167+
test_expect_success 'stash with user.name and user.email set works' '
1168+
test_config user.name "A U Thor" &&
1169+
test_config user.email "a.u@thor" &&
1170+
git stash
1171+
'
1172+
11671173
test_expect_success 'stash works when user.name and user.email are not set' '
11681174
git reset &&
11691175
>1 &&

t/t3905-stash-include-untracked.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,4 +283,10 @@ test_expect_success 'stash -u -- <non-existant> shows no changes when there are
283283
test_i18ncmp expect actual
284284
'
285285

286+
test_expect_success 'stash -u with globs' '
287+
>untracked.txt &&
288+
git stash -u -- ":(glob)**/*.txt" &&
289+
test_path_is_missing untracked.txt
290+
'
291+
286292
test_done

0 commit comments

Comments
 (0)