Skip to content

Update the built-in git stash to the latest version #2119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 63 commits into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
41fef97
fixup! stash: avoid unnecessary reset_tree() call
dscho Mar 11, 2019
c6f8916
fixup! stash: discard in-process cache after spawning index-changing …
dscho Mar 11, 2019
017b95d
fixup! strbuf_vinsertf: provide the correct buffer size to vsnprintf
dscho Mar 11, 2019
b95677f
fixup! stash: fix segmentation fault when files were added with intent
dscho Mar 11, 2019
1acb791
fixup! tests: add a special setup where stash.useBuiltin is off
dscho Mar 11, 2019
1a17912
fixup! stash: optionally use the scripted version again
dscho Mar 11, 2019
ab8c1b3
fixup! stash: add back the original, scripted `git stash`
dscho Mar 11, 2019
19ba7d4
fixup! stash: convert `stash--helper.c` into `stash.c`
dscho Mar 11, 2019
7f22408
fixup! stash: replace all `write-tree` child processes with API calls
dscho Mar 11, 2019
2b4813d
fixup! stash: optimize `get_untracked_files()` and `check_changes()`
dscho Mar 11, 2019
de27635
fixup! stash: convert save to builtin
dscho Mar 11, 2019
666ae6e
fixup! stash: make push -q quiet
dscho Mar 11, 2019
ca9031f
fixup! stash: convert push to builtin
dscho Mar 11, 2019
c341b4e
fixup! stash: convert create to builtin
dscho Mar 11, 2019
2b45b40
fixup! stash: convert store to builtin
dscho Mar 11, 2019
6f1ce35
fixup! stash: convert show to builtin
dscho Mar 11, 2019
fd928ad
fixup! stash: convert list to builtin
dscho Mar 11, 2019
566be3a
fixup! stash: convert pop to builtin
dscho Mar 11, 2019
35eac1e
fixup! stash: convert branch to builtin
dscho Mar 11, 2019
2b8b36b
fixup! stash: convert drop and clear to builtin
dscho Mar 11, 2019
f0adfd7
fixup! stash: convert apply to builtin
dscho Mar 11, 2019
82de2ce
fixup! stash: mention options in `show` synopsis
dscho Mar 11, 2019
e4e2dfd
fixup! stash: add tests for `git stash show` config
dscho Mar 11, 2019
0e1bf9f
fixup! stash: rename test cases to be more descriptive
dscho Mar 11, 2019
1acc1e9
fixup! t3903: modernize style
dscho Mar 11, 2019
6210c67
fixup! stash: improve option parsing test coverage
dscho Mar 11, 2019
9902b5e
fixup! ident: add the ability to provide a "fallback identity"
dscho Mar 11, 2019
dd1d9a5
fixup! strbuf.c: add `strbuf_insertf()` and `strbuf_vinsertf()`
dscho Mar 11, 2019
02f8005
fixup! strbuf.c: add `strbuf_join_argv()`
dscho Mar 11, 2019
61e921a
fixup! sha1-name.c: add `get_oidf()` which acts like `get_oid()`
dscho Mar 11, 2019
aaede5c
sha1-name.c: add `get_oidf()` which acts like `get_oid()`
ungps Feb 25, 2019
3422bdc
strbuf.c: add `strbuf_join_argv()`
ungps Feb 25, 2019
7cfbaa5
strbuf.c: add `strbuf_insertf()` and `strbuf_vinsertf()`
ungps Feb 25, 2019
d3dc2ab
ident: add the ability to provide a "fallback identity"
dscho Feb 25, 2019
5061ec1
ident: don't require calling prepare_fallback_ident first
tgummerer Mar 6, 2019
dca0c78
stash: improve option parsing test coverage
klusark Feb 25, 2019
f198a70
t3903: modernize style
ungps Feb 25, 2019
8ef273d
t3903: add test for --intent-to-add file
kraai Feb 25, 2019
18d0c35
stash: rename test cases to be more descriptive
ungps Feb 25, 2019
9346a09
stash: add tests for `git stash show` config
ungps Feb 25, 2019
58e1f63
stash: mention options in `show` synopsis
ungps Feb 25, 2019
4f6218c
stash: convert apply to builtin
klusark Feb 25, 2019
73f47ba
fixup: stash: convert apply to builtin
dscho Mar 11, 2019
c58e38d
fixup: stash: convert apply to builtin
dscho Mar 11, 2019
4d733c4
stash: convert drop and clear to builtin
klusark Feb 25, 2019
6fe783f
stash: convert branch to builtin
klusark Feb 25, 2019
c85d792
stash: convert pop to builtin
klusark Feb 25, 2019
1e3b9c2
stash: convert list to builtin
ungps Feb 25, 2019
bef7e56
stash: convert show to builtin
ungps Feb 25, 2019
06b5b8f
stash: convert store to builtin
ungps Feb 25, 2019
9b6e423
fixup: stash: convert store to builtin
dscho Mar 11, 2019
cad14d6
stash: convert create to builtin
ungps Feb 25, 2019
ef1b5f4
stash: convert push to builtin
ungps Feb 25, 2019
fa8ae45
stash: make push -q quiet
ungps Feb 25, 2019
b8fad7d
stash: convert save to builtin
ungps Feb 25, 2019
714dd72
stash: optimize `get_untracked_files()` and `check_changes()`
ungps Feb 25, 2019
b561b4a
stash: replace all `write-tree` child processes with API calls
ungps Feb 25, 2019
fade169
stash: convert `stash--helper.c` into `stash.c`
ungps Feb 25, 2019
68c524a
stash: add back the original, scripted `git stash`
dscho Feb 25, 2019
5de5454
stash: optionally use the scripted version again
dscho Feb 25, 2019
a373469
tests: add a special setup where stash.useBuiltin is off
dscho Feb 25, 2019
ab15e05
legacy stash: fix "rudimentary backport of -q"
dscho Mar 7, 2019
66af0b6
built-in stash: handle :(glob) pathspecs again
dscho Mar 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions builtin/stash.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ static struct strbuf stash_index_path = STRBUF_INIT;
* i_tree is set to the index tree
* u_tree is set to the untracked files tree
*/

struct stash_info {
struct object_id w_commit;
struct object_id b_commit;
Expand Down Expand Up @@ -320,11 +319,7 @@ static void add_diff_to_buf(struct diff_queue_struct *q,
for (i = 0; i < q->nr; i++) {
strbuf_addstr(data, q->queue[i]->one->path);

/*
* The reason we add "0" at the end of this strbuf
* is because we will pass the output further to
* "git update-index -z ...".
*/
/* NUL-terminate: will be fed to update-index -z */
strbuf_addch(data, '\0');
}
}
Expand Down Expand Up @@ -579,9 +574,9 @@ static int do_drop_stash(const char *prefix, struct stash_info *info, int quiet)
static void assert_stash_ref(struct stash_info *info)
{
if (!info->is_stash_ref) {
free_stash_info(info);
error(_("'%s' is not a stash reference"), info->revision.buf);
exit(128);
free_stash_info(info);
exit(1);
}
}

Expand Down Expand Up @@ -837,7 +832,7 @@ static void add_pathspecs(struct argv_array *args,
int i;

for (i = 0; i < ps.nr; i++)
argv_array_push(args, ps.items[i].match);
argv_array_push(args, ps.items[i].original);
}

/*
Expand Down Expand Up @@ -869,7 +864,7 @@ static int get_untracked_files(struct pathspec ps, int include_untracked,
found++;
strbuf_addstr(untracked_files, ent->name);
/* NUL-terminate: will be fed to update-index -z */
strbuf_addch(untracked_files, 0);
strbuf_addch(untracked_files, '\0');
}
free(ent);
}
Expand All @@ -888,7 +883,6 @@ static int get_untracked_files(struct pathspec ps, int include_untracked,
* = 0 if there are no changes.
* > 0 if there are changes.
*/

static int check_changes_tracked_files(struct pathspec ps)
{
int result;
Expand Down Expand Up @@ -928,7 +922,6 @@ static int check_changes_tracked_files(struct pathspec ps)
* The function will fill `untracked_files` with the names of untracked files
* It will return 1 if there were any changes and 0 if there were not.
*/

static int check_changes(struct pathspec ps, int include_untracked,
struct strbuf *untracked_files)
{
Expand Down Expand Up @@ -1238,7 +1231,9 @@ static int create_stash(int argc, const char **argv, const char *prefix)
if (!check_changes_tracked_files(ps))
return 0;

if (!(ret = do_create_stash(ps, &stash_msg_buf, 0, 0, &info, NULL, 0)))
ret = do_create_stash(ps, &stash_msg_buf, 0, 0, &info,
NULL, 0);
if (!ret)
printf_ln("%s", oid_to_hex(&info.w_commit));

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

discard_cache();

cp.git_cmd = 1;
argv_array_pushl(&cp.args, "reset", "-q", "--", NULL);
add_pathspecs(&cp.args, ps);
Expand Down Expand Up @@ -1475,7 +1468,8 @@ static int push_stash(int argc, const char **argv, const char *prefix)
git_stash_push_usage,
0);

parse_pathspec(&ps, 0, PATHSPEC_PREFER_FULL, prefix, argv);
parse_pathspec(&ps, 0, PATHSPEC_PREFER_FULL | PATHSPEC_PREFIX_ORIGIN,
prefix, argv);
return do_push_stash(ps, stash_msg, quiet, keep_index, patch_mode,
include_untracked);
}
Expand Down
3 changes: 3 additions & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -1518,6 +1518,9 @@ extern const char *git_sequence_editor(void);
extern const char *git_pager(int stdout_is_tty);
extern int is_terminal_dumb(void);
extern int git_ident_config(const char *, const char *, void *);
/*
* Prepare an ident to fall back on if the user didn't configure it.
*/
void prepare_fallback_ident(const char *name, const char *email);
extern void reset_ident_date(void);

Expand Down
8 changes: 4 additions & 4 deletions git-legacy-stash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,17 @@ maybe_quiet () {
shift
if test -n "$GIT_QUIET"
then
eval "$@" 2>/dev/null
"$@" 2>/dev/null
else
eval "$@"
"$@"
fi
;;
*)
if test -n "$GIT_QUIET"
then
eval "$@" >/dev/null 2>&1
"$@" >/dev/null 2>&1
else
eval "$@"
"$@"
fi
;;
esac
Expand Down
6 changes: 6 additions & 0 deletions t/t3903-stash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,12 @@ test_expect_success 'stash -- <subdir> works with binary files' '
test_path_is_file subdir/untracked
'

test_expect_success 'stash with user.name and user.email set works' '
test_config user.name "A U Thor" &&
test_config user.email "a.u@thor" &&
git stash
'

test_expect_success 'stash works when user.name and user.email are not set' '
git reset &&
>1 &&
Expand Down
6 changes: 6 additions & 0 deletions t/t3905-stash-include-untracked.sh
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,10 @@ test_expect_success 'stash -u -- <non-existant> shows no changes when there are
test_i18ncmp expect actual
'

test_expect_success 'stash -u with globs' '
>untracked.txt &&
git stash -u -- ":(glob)**/*.txt" &&
test_path_is_missing untracked.txt
'

test_done