Skip to content

Commit

Permalink
WIP: git add -p: allow stashing hunks
Browse files Browse the repository at this point in the history
In the default `git add -p` mode, users can selectively stash hunks.

In common work scenarios, I often encountered situations where I would
love to stash (or simply discard) hunks instead.

This idea has been brought up on the Git mailing list before, and it is
an idea worth putting effort behind.

This patch is utterly incomplete!

In particular, the reassemble-and-apply phase needs to be accompanied by
a preceding step that would reassemble the "to-stash" hunks and stash
them.

Signed-off-by: Johannes Schindelin <[email protected]>
  • Loading branch information
dscho committed Nov 14, 2024
1 parent 777489f commit b4b38a7
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions add-patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ static struct patch_mode patch_mode_add = {
"ones\n"
"a - stage this hunk and all later hunks in the file\n"
"d - do not stage this hunk or any of the later hunks in "
"the file\n")
"the file\n"
"t - stash this hunk instead of staging it\n")
};

static struct patch_mode patch_mode_stash = {
Expand Down Expand Up @@ -1215,7 +1216,7 @@ static int run_apply_check(struct add_p_state *s,
"apply", "--check", NULL);
strvec_pushv(&cp.args, s->mode->apply_check_args);
if (pipe_command(&cp, s->buf.buf, s->buf.len, NULL, 0, NULL, 0))
return error(_("'git apply --cached' failed"));
return error(_("'git apply --check' failed"));

return 0;
}
Expand Down Expand Up @@ -1697,6 +1698,8 @@ static int patch_update_file(struct add_p_state *s,
} else if (ch == 'p') {
rendered_hunk_index = -1;
use_pager = (s->answer.buf[0] == 'P') ? 1 : 0;
} else if (s->answer.buf[0] == 't') {
hunk->use = STASH_HUNK;

Check failure on line 1702 in add-patch.c

View workflow job for this annotation

GitHub Actions / fuzz smoke test

add-patch.c:1702:16: use of undeclared identifier 'STASH_HUNK'

Check failure on line 1702 in add-patch.c

View workflow job for this annotation

GitHub Actions / linux32 (i386/ubuntu:focal)

add-patch.c:1702:16: 'STASH_HUNK' undeclared (first use in this function); did you mean 'USE_HUNK'?

Check failure on line 1702 in add-patch.c

View workflow job for this annotation

GitHub Actions / linux-musl (alpine)

add-patch.c:1702:37: 'STASH_HUNK' undeclared (first use in this function); did you mean 'USE_HUNK'?

Check failure on line 1702 in add-patch.c

View workflow job for this annotation

GitHub Actions / pedantic (fedora)

add-patch.c:1702:37: 'STASH_HUNK' undeclared (first use in this function); did you mean 'USE_HUNK'?

Check failure on line 1702 in add-patch.c

View workflow job for this annotation

GitHub Actions / win build

add-patch.c:1702:37: 'STASH_HUNK' undeclared (first use in this function); did you mean 'USE_HUNK'?

Check failure on line 1702 in add-patch.c

View workflow job for this annotation

GitHub Actions / linux-asan-ubsan (ubuntu-latest)

add-patch.c:1702:16: use of undeclared identifier 'STASH_HUNK'

Check failure on line 1702 in add-patch.c

View workflow job for this annotation

GitHub Actions / linux-gcc (ubuntu-20.04)

add-patch.c:1702:16: ‘STASH_HUNK’ undeclared (first use in this function); did you mean ‘USE_HUNK’?

Check failure on line 1702 in add-patch.c

View workflow job for this annotation

GitHub Actions / linux-gcc-default (ubuntu-latest)

add-patch.c:1702:37: ‘STASH_HUNK’ undeclared (first use in this function); did you mean ‘USE_HUNK’?

Check failure on line 1702 in add-patch.c

View workflow job for this annotation

GitHub Actions / linux-leaks (ubuntu-latest)

add-patch.c:1702:37: ‘STASH_HUNK’ undeclared (first use in this function); did you mean ‘USE_HUNK’?

Check failure on line 1702 in add-patch.c

View workflow job for this annotation

GitHub Actions / linux-reftable-leaks (ubuntu-latest)

add-patch.c:1702:37: ‘STASH_HUNK’ undeclared (first use in this function); did you mean ‘USE_HUNK’?

Check failure on line 1702 in add-patch.c

View workflow job for this annotation

GitHub Actions / linux-reftable (ubuntu-latest)

add-patch.c:1702:16: use of undeclared identifier 'STASH_HUNK'

Check failure on line 1702 in add-patch.c

View workflow job for this annotation

GitHub Actions / linux-sha256 (ubuntu-latest)

add-patch.c:1702:16: use of undeclared identifier 'STASH_HUNK'

Check failure on line 1702 in add-patch.c

View workflow job for this annotation

GitHub Actions / linux-TEST-vars (ubuntu-20.04)

add-patch.c:1702:16: ‘STASH_HUNK’ undeclared (first use in this function); did you mean ‘USE_HUNK’?
} else if (s->answer.buf[0] == '?') {
const char *p = _(help_patch_remainder), *eol = p;

Expand Down

0 comments on commit b4b38a7

Please sign in to comment.