1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-06-23 18:57:29 +02:00
Commit Graph

57 Commits

Author SHA1 Message Date
Junio C Hamano 351d06df51 Merge branch 'jk/stash-require-clean-index' into maint
A hotfix for the topic already in 'master'.

* jk/stash-require-clean-index:
  Revert "stash: require a clean index to apply"
2015-06-25 23:03:27 -07:00
Junio C Hamano 659d4c8fb2 Merge branch 'jk/stash-options' into maint
Make "git stash something --help" error out, so that users can
safely say "git stash drop --help".

* jk/stash-options:
  stash: recognize "--help" for subcommands
  stash: complain about unknown flags
2015-06-16 14:33:43 -07:00
Jeff King 19376104a8 Revert "stash: require a clean index to apply"
This reverts commit ed178ef13a.

That commit was an attempt to improve the safety of applying
a stash, because the application process may create
conflicted index entries, after which it is hard to restore
the original index state.

Unfortunately, this hurts some common workflows around "git
stash -k", like:

    git add -p       ;# (1) stage set of proposed changes
    git stash -k     ;# (2) get rid of everything else
    make test        ;# (3) make sure proposal is reasonable
    git stash apply  ;# (4) restore original working tree

If you "git commit" between steps (3) and (4), then this
just works. However, if these steps are part of a pre-commit
hook, you don't have that opportunity (you have to restore
the original state regardless of whether the tests passed or
failed).

It's possible that we could provide better tools for this
sort of workflow. In particular, even before ed178ef, it
could fail with a conflict if there were conflicting hunks
in the working tree and index (since the "stash -k" puts the
index version into the working tree, and we then attempt to
apply the differences between HEAD and the old working tree
on top of that). But the fact remains that people have been
using it happily for a while, and the safety provided by
ed178ef is simply not that great. Let's revert it for now.
In the long run, people can work on improving stash for this
sort of workflow, but the safety tradeoff is not worth it in
the meantime.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-06-15 13:11:17 -07:00
Jeff King d6cc2df5c8 stash: complain about unknown flags
The option parser for git-stash stuffs unknown flags into
the $FLAGS variable, where they can be accessed by the
individual commands. However, most commands do not even look
at these extra flags, leading to unexpected results like
this:

  $ git stash drop --help
  Dropped refs/stash@{0} (e6cf6d80faf92bb7828f7b60c47fc61c03bd30a1)

We should notice the extra flags and bail. Rather than
annotate each command to reject a non-empty $FLAGS variable,
we can notice that "stash show" is the only command that
actually _wants_ arbitrary flags. So we switch the default
mode to reject unknown flags, and let stash_show() opt into
the feature.

Reported-by: Vincent Legoll <vincent.legoll@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-05-20 13:47:30 -07:00
Jeff King ed178ef13a stash: require a clean index to apply
If you have staged contents in your index and run "stash
apply", we may hit a conflict and put new entries into the
index. Recovering to your original state is difficult at
that point, because tools like "git reset --keep" will blow
away anything staged.  We can make this safer by refusing to
apply when there are staged changes.

It's possible we could provide better tooling here, as "git
stash apply" should be writing only conflicts to the index
(so we know that any stage-0 entries are potentially
precious). But it is the odd duck; most "mergy" commands
will update the index for cleanly merged entries, and it is
not worth updating our tooling to support this use case
which is unlikely to be of interest (besides which, we would
still need to block a dirty index for "stash apply --index",
since that case _would_ be ambiguous).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-04-22 13:38:58 -07:00
Jeff King 88bab59c5b t3903: avoid applying onto dirty index
One of the tests in t3903 wants to make sure that applying a
stash that touches only "file" can still happen even if there
are working tree changes to "other-file". To do so, it adds
"other-file" to the index (since otherwise it is an
untracked file, voiding the purpose of the test).

But as we are about to refactor the dirty-index handling,
and as this test does not actually care about having a dirty
index (only a dirty working tree), let's bump the tracking
of "other-file" into the setup phase, so we can have _just_
a dirty working tree here.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-04-22 13:38:58 -07:00
Jeff King f2f3fc9547 t3903: stop hard-coding commit sha1s
When testing the diff output of "git stash list", we look
for the stash's subject of "WIP on master: $sha1", even
though it's not relevant to the diff output. This makes the
test brittle to refactoring, as any changes to earlier tests
may impact the commit sha1.

Since we don't care about the commit subject here, we can
simply ask stash not to print it.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-04-22 13:38:58 -07:00
Jeff King 288c67caf6 stash: default listing to working-tree diff
When you list stashes, you can provide arbitrary git-log
options to change the display. However, adding just "-p"
does nothing, because each stash is actually a merge commit.

This implementation detail is easy to forget, leading to
confused users who think "-p" is not working. We can make
this easier by defaulting to "--first-parent -m", which will
show the diff against the working tree. This omits the
index portion of the stash entirely, but it's simple and it
matches what "git stash show" provides.

People who are more clueful about stash's true form can use
"--cc" to override the "-m", and the "--first-parent" will
then do nothing. For diffs, it only affects non-combined
diffs, so "--cc" overrides it. And for the traversal, we are
walking the linear reflog anyway, so we do not even care
about the parents.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-08-07 14:37:28 -07:00
Øystein Walle 2a07e4374c stash: handle specifying stashes with $IFS
When trying to pop/apply a stash specified with an argument
containing IFS whitespace, git-stash will throw an error:

    $ git stash pop 'stash@{two hours ago}'
    Too many revisions specified: stash@{two hours ago}

This happens because word splitting is used to count non-option
arguments. Make use of rev-parse's --sq option to quote the arguments
for us to ensure a correct count. Add quotes where necessary.

Also add a test that verifies correct behaviour.

Helped-by: Thomas Rast <tr@thomasrast.ch>
Signed-off-by: Øystein Walle <oystwa@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-01-07 10:51:04 -08:00
Junio C Hamano c1ebd90c83 Revert "git stash: avoid data loss when "git stash save" kills a directory"
This reverts commit a73653130e, as it
has been reported that "ls-files --killed" is too time-consuming in
a deep directory with too many untracked crufts (e.g. $HOME/.git
tracking only a few files).

We'd need to revisit it later but "ls-files --killed" needs to be
optimized before it happens.
2013-08-14 09:53:43 -07:00
Petr Baudis a73653130e git stash: avoid data loss when "git stash save" kills a directory
"stash save" is about saving the local change to the working tree,
but also about restoring the state of the last commit to the working
tree.  When a local change is to turn a non-directory to a directory,
in order to restore the non-directory, everything in the directory
needs to be removed.

Which is fine when running "git stash save --include-untracked",
but without that option, untracked, newly created files in the
directory will have to be discarded, if the state you are restoring
to has a non-directory at the same path as the directory.

Introduce a safety valve to fail the operation in such case, using
the "ls-files --killed" which was designed for this exact purpose.

The "stash save" is stopped when untracked files need to be
discarded because their leading path ceased to be a directory, and
the user is required to pass --force to really have the data
removed.

Signed-off-by: Petr Baudis <pasky@ucw.cz>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-01 14:23:24 -07:00
Junio C Hamano fa4bf9edb9 Merge branch 'rr/rebase-stash-store'
Finishing touches for the "git rebase --autostash" feature
introduced earlier.

* rr/rebase-stash-store:
  rebase: use 'git stash store' to simplify logic
  stash: introduce 'git stash store'
  stash: simplify option parser for create
  stash doc: document short form -p in synopsis
  stash doc: add a warning about using create
2013-06-27 14:29:41 -07:00
Junio C Hamano 01c0615dce Merge branch 'fc/show-non-empty-errors-in-test'
* fc/show-non-empty-errors-in-test:
  test: test_must_be_empty helper
2013-06-20 16:02:24 -07:00
Ramkumar Ramachandra bd514cada4 stash: introduce 'git stash store'
save_stash() contains the logic for doing two potentially independent
operations; the first is preparing the stash merge commit, and the
second is updating the stash ref/ reflog accordingly.  While the first
operation is abstracted out into a create_stash() for callers to access
via 'git stash create', the second one is not.  Fix this by factoring
out the logic for storing the stash into a store_stash() that callers
can access via 'git stash store'.

Like create, store is not intended for end user interactive use, but for
callers in other scripts.  We can simplify the logic in the
rebase.autostash feature using this new subcommand.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-06-17 11:43:13 -07:00
Junio C Hamano ca8d148daf test: test_must_be_empty helper
There are quite a lot places where an output file is expected to be
empty, and we fail the test when it is not.  The output from running
the test script with -i -v can be helped if we showed the unexpected
contents at that point.

We could of course do

    >expected.empty && test_cmp expected.empty actual

but this is commmon enough to be done with a dedicated helper.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-06-09 16:45:14 -07:00
Johannes Sixt 889c6f0e4d tests: use test_ln_s_add to remove SYMLINKS prerequisite (trivial cases)
There are many instances where the treatment of symbolic links in the
object model and the algorithms are tested, but where it is not
necessary to actually have a symbolic link in the worktree. Make
adjustments to the tests and remove the SYMLINKS prerequisite when
appropriate in trivial cases, where "trivial" means:

- merely a replacement of 'ln -s a b && git add b' by test_ln_s_add
  is needed;

- a test for symbolic link on the file system can be split off (and
  remains protected by SYMLINKS);

- existing code is equivalent to test_ln_s_add.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-06-07 15:01:45 -07:00
Jiang Xin 2878568847 Fix tests under GETTEXT_POISON on git-stash
Use i18n-specific test functions in test scripts for git-stash.
This issue was was introduced in v1.7.4.1-119-g355ec:

    355ec i18n: git-status basic messages

and been broken under GETTEXT_POISON=YesPlease since.

Signed-off-by: Jiang Xin <worldhello.net@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-08-27 09:26:29 -07:00
Zbigniew Jędrzejewski-Szmek dc801e71a7 diff --stat: use less columns for change counts
Number of columns required for change counts is now computed based on
the maximum number of changed lines instead of being fixed. This means
that usually a few more columns will be available for the filenames
and the graph.

The graph width logic is also modified to include enough space for
"Bin XXX -> YYY bytes".

If changes to binary files are mixed with changes to text files,
change counts are padded to take at least three columns. And the other
way around, if change counts require more than three columns, then
"Bin"s are padded to align with the change count. This way, the +-
part starts in the same column as "XXX -> YYY" part for binary files.
This makes the graph easier to parse visually thanks to the empty
column. This mimics the layout of diff --stat before this change.

Tests and the tutorial are updated to reflect the new --stat output.
This means either the removal of extra padding and/or the addition of
up to three extra characters to truncated filenames. One test is added
to check the graph alignment when a binary file change and text file
change of more than 999 lines are committed together.

Signed-off-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-04-30 14:17:26 -07:00
Jonathan Nieder 1145211456 test: use --numstat instead of --stat in "git stash show" tests
git's diff --stat output is intended for human consumption and
since v1.7.9.2~13 (2012-02-01) varies by locale.  Add a test checking
that git stash show defaults to --stat and tweak the rest of the
"stash show" tests that showed a diffstat to use numstat.

This way, there are fewer tests to tweak if the diffstat format
changes again.  This also improves test coverage when running tests
with git configured not to write its output in the C locale (e.g.,
via GETTEXT_POISON=Yes).

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-03-13 14:26:32 -07:00
Jonathan Nieder fc5877a623 test: use test_i18ncmp when checking --stat output
Ever since v1.7.9.2~13 (2012-02-01), git's diffstat-style summary line
produced by "git apply --stat", "git diff --stat", and "git commit"
varies by locale, producing test failures when GETTEXT_POISON is set.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-03-13 14:26:27 -07:00
Nguyễn Thái Ngọc Duy 7f814632f5 Use correct grammar in diffstat summary line
"git diff --stat" and "git apply --stat" now learn to print the line
"%d files changed, %d insertions(+), %d deletions(-)" in singular form
whenever applicable. "0 insertions" and "0 deletions" are also omitted
unless they are both zero.

This matches how versions of "diffstat" that are not prehistoric produced
their output, and also makes this line translatable.

[jc: with help from Thomas Dickey in archaeology of "diffstat"]
[jc: squashed Jonathan's updates to illustrations in tutorials and a test]

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-02-03 23:19:42 -08:00
Jonathon Mah 44df2e2970 stash: Don't fail if work dir contains file named 'HEAD'
When performing a plain "git stash" (without --patch), git-diff would fail
with "fatal: ambiguous argument 'HEAD': both revision and filename". The
output was piped into git-update-index, masking the failed exit status.
The output is now sent to a temporary file (which is cleaned up by
existing code), and the exit status is checked. The "HEAD" arg to the
git-diff invocation has been disambiguated too, of course.

In patch mode, "git stash -p" would fail harmlessly, leaving the working
dir untouched. Interactive adding is fine, but the resulting tree was
diffed with an ambiguous 'HEAD' argument.

Use >foo (no space) when redirecting output.

In t3904, checks and operations on each file are in the order they'll
appear when interactively staging.

In t3905, fix a bug in "stash save --include-untracked -q is quiet": The
redirected stdout file was considered untracked, and so was removed from
the working directory. Use test path helper functions where appropriate.

Signed-off-by: Jonathon Mah <me@JonathonMah.com>
Acked-by: Thomas Rast <trast@student.ethz.ch>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-01-01 01:11:56 -08:00
Junio C Hamano 57c081046c Merge branch 'tr/maint-t3903-misquoted-command'
* tr/maint-t3903-misquoted-command:
  t3903: fix misquoted rev-parse invocation
2011-09-02 13:18:39 -07:00
Thomas Rast 1ae9644410 t3903: fix misquoted rev-parse invocation
!"git ..." hopefully always succeeds because "git ..." is not the name
of any executable.  However, that's not what was intended.  Unquote
it, and while we're at it, also replace ! with test_must_fail since it
is a call to git.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
Acked-by: Jon Seymour <jon.seymour@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-08-30 10:06:19 -07:00
Dmitry Ivankov 7be8b3baba Fix typo: existant->existent
refs.c had a error message "Trying to write ref with nonexistant object".
And no tests relied on the wrong spelling.
Also typo was present in some test scripts internals, these tests still pass.

Signed-off-by: Dmitry Ivankov <divanorama@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-06-16 10:33:50 -07:00
Junio C Hamano 65bc83d704 Merge branch 'dm/stash-k-i-p'
* dm/stash-k-i-p:
  stash: ensure --no-keep-index and --patch can be used in any order
  stash: add two more tests for --no-keep-index
2011-04-27 11:36:42 -07:00
Junio C Hamano fcbf164fcb Merge branch 'jk/maint-stash-oob'
* jk/maint-stash-oob:
  stash: fix false positive in the invalid ref test.
  stash: fix accidental apply of non-existent stashes

Conflicts:
	t/t3903-stash.sh
2011-04-27 11:36:42 -07:00
Dan McGee 21ec98a75d stash: add two more tests for --no-keep-index
One of these passes just fine; the other one exposes a problem where
command line flag order matters for --no-keep-index and --patch
interaction.

Signed-off-by: Dan McGee <dpmcgee@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-04-07 15:53:02 -07:00
Jeff King e0e2a9cbfa stash: drop dirty worktree check on apply
Before we apply a stash, we make sure there are no changes
in the worktree that are not in the index. This check dates
back to the original git-stash.sh, and is presumably
intended to prevent changes in the working tree from being
accidentally lost during the merge.

However, this check has two problems:

  1. It is overly restrictive. If my stash changes only file
     "foo", but "bar" is dirty in the working tree, it will
     prevent us from applying the stash.

  2. It is redundant. We don't touch the working tree at all
     until we actually call merge-recursive. But it has its
     own (much more accurate) checks to avoid losing working
     tree data, and will abort the merge with a nicer
     message telling us which paths were problems.

So we can simply drop the check entirely.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-04-06 09:41:22 -07:00
Jon Seymour 9355fc9c35 stash: fix false positive in the invalid ref test.
Jeff King reported a problem with git stash apply incorrectly
applying an invalid stash reference.

There is an existing test that should have caught this, but
the test itself was broken, resulting in a false positive.

Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-04-05 20:01:52 -07:00
Jeff King 59d418fe10 stash: fix accidental apply of non-existent stashes
Once upon a time, "git rev-parse ref@{9999999}" did not
generate an error. Therefore when we got an invalid stash
reference in "stash apply", we could end up not noticing
until quite late.  Commit b0f0ecd (detached-stash: work
around git rev-parse failure to detect bad log refs,
2010-08-21) handled this by checking for the "Log for stash
has only %d entries" warning on stderr when we validated the
ref.

A few days later, e6eedc3 (rev-parse: exit with non-zero
status if ref@{n} is not valid., 2010-08-24) fixed the
original issue. That made the extra stderr test superfluous,
but also introduced a new bug. Now the early call to:

  git rev-parse --symbolic "$@"

fails, but we don't notice the exit code. Worse, its empty
output means we think the user didn't provide us a ref, and
we try to apply stash@{0}.

This patch checks the rev-parse exit code and fails early in
the revision parsing process. We can also get rid of the
stderr test; as a bonus, this means that "stash apply" can
now run under GIT_TRACE=1 properly.

Signed-off-by: Jeff King <peff@peff.net>
Acked-by: Jon Seymour <jon.seymour@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-04-05 20:01:37 -07:00
Piotr Krukowiecki 6eaf92f3d0 Add test: git stash shows status relative to current dir
[jc: moved "cd subdir" inside subshell and fixed comparison with expected]

Signed-off-by: Piotr Krukowiecki <piotr.krukowiecki@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-03-20 21:45:11 -07:00
Jonathan Nieder a48fcd8369 tests: add missing &&
Breaks in a test assertion's && chain can potentially hide
failures from earlier commands in the chain.

Commands intended to fail should be marked with !, test_must_fail, or
test_might_fail.  The examples in this patch do not require that.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-09 11:59:49 -08:00
Jon Seymour 57693d03db stash: fix git stash branch regression when branch creation fails
"git stash branch <branch> <stash>" started discarding the stash
when the branch creation fails.  It should have kept the stash
intact when aborting.

Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-09-29 10:07:09 -07:00
Tomas Carnecky 835d6a1f9f stash drops the stash even if creating the branch fails because it already exists
This bug was disovered by someone on IRC when he tried to

    $ git stash branch <branch> <stash>

while <branch> already existed. In that case the stash is dropped even
though it isn't applied on any branch, so the stash is effectively lost.

Signed-off-by: Tomas Carnecky <tom@dbservice.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-09-29 09:59:42 -07:00
Brian Gernhardt 9027fa9eb7 git-stash: fix flag parsing
Currently git-stash uses `git rev-parse --no-revs -- "$@"` to set its
FLAGS variable.  This is the same as `FLAGS="-- $@"`.  It should use
`git rev-parse --no-revs --flags "$@"`, but that eats any "-q" or
"--quiet" argument.  So move the check for quiet before rev-parse.

Signed-off-by: Brian Gernhardt <brian@gernhardtsoftware.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-09-26 21:27:37 -07:00
Brandon Casey 3fcb88785d t/t3903-stash: improve testing of git-stash show
Recently, the 'stash show' functionality was broken for the case when a
stash-like argument was supplied.  Since, commit 9bf09e, 'stash show' when
supplied a stash-like argument prints nothing and still exists with a zero
status.  Unfortunately, the flaw slipped through the test suite cracks
since the output of 'stash show' was not verified to be correct.

Improve and expand on the existing tests so that this flaws is detected.

Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-09-26 21:25:40 -07:00
Jonathan Nieder 18a8269242 tests: subshell indentation stylefix
Format the subshells introduced by the previous patch (Several tests:
cd inside subshell instead of around, 2010-09-06) like so:

	(
		cd subdir &&
		...
	) &&

This is generally easier to read and has the nice side-effect that
this patch will show what commands are used in the subshell, making
it easier to check for lost environment variables and similar
behavior changes.

Cc: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-09-09 15:56:20 -07:00
Junio C Hamano 347c47e61e Merge branch 'jl/maint-fix-test'
* jl/maint-fix-test:
  Several tests: cd inside subshell instead of around

Conflicts:
	t/t9600-cvsimport.sh
2010-09-06 16:46:36 -07:00
Jens Lehmann fd4ec4f2bb Several tests: cd inside subshell instead of around
Fixed all places where it was a straightforward change from cd'ing into a
directory and back via "cd .." to a cd inside a subshell.

Found these places with "git grep -w "cd \.\.".

Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-09-06 14:30:53 -07:00
Jon Seymour 8d66bb0587 t3903: fix broken test_must_fail calls
Some tests in detached-stash are calling test_must_fail
in such a way that the arguments to test_must_fail do, indeed, fail
but not in the manner expected by the test.

This patch removes the unnecessary and unhelpful double quotes.

Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-08-31 09:50:07 -07:00
Jon Seymour daf7a0c000 detached-stash: tests of git stash with stash-like arguments
Adds new tests which check that:
* git stash branch handles a stash-like argument when there is a stash stack
* git stash branch handles a stash-like argument when there is not a stash stack
* git stash show handles a stash-like argument when there is a stash stack
* git stash show handles a stash-like argument when there is not a stash stack
* git stash drop fails early if the specified argument is not a stash reference
* git stash pop fails early if the specified argument is not a stash reference
* git stash * fails early if the reference supplied is bogus
* git stash fails early with stash@{n} where n >= length of stash log

Helped-by: Johannes Sixt
Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-08-21 23:51:22 -07:00
Junio C Hamano 8d676d85f7 Merge branch 'gv/portable'
* gv/portable:
  test-lib: use DIFF definition from GIT-BUILD-OPTIONS
  build: propagate $DIFF to scripts
  Makefile: Tru64 portability fix
  Makefile: HP-UX 10.20 portability fixes
  Makefile: HPUX11 portability fixes
  Makefile: SunOS 5.6 portability fix
  inline declaration does not work on AIX
  Allow disabling "inline"
  Some platforms lack socklen_t type
  Make NO_{INET_NTOP,INET_PTON} configured independently
  Makefile: some platforms do not have hstrerror anywhere
  git-compat-util.h: some platforms with mmap() lack MAP_FAILED definition
  test_cmp: do not use "diff -u" on platforms that lack one
  fixup: do not unconditionally disable "diff -u"
  tests: use "test_cmp", not "diff", when verifying the result
  Do not use "diff" found on PATH while building and installing
  enums: omit trailing comma for portability
  Makefile: -lpthread may still be necessary when libc has only pthread stubs
  Rewrite dynamic structure initializations to runtime assignment
  Makefile: pass CPPFLAGS through to fllow customization

Conflicts:
	Makefile
	wt-status.h
2010-06-21 06:02:44 -07:00
Gary V. Vaughan 4fdf71be1c tests: use "test_cmp", not "diff", when verifying the result
In tests, call test_cmp rather than raw diff where possible (i.e. if
the output does not go to a pipe), to allow the use of, say, 'cmp'
when the default 'diff -u' is not compatible with a vendor diff.

When that is not possible, use $DIFF, as set in GIT-BUILD-OPTIONS.

Signed-off-by: Gary V. Vaughan <gary@thewrittenword.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-05-31 16:59:27 -07:00
Charles Bailey 2ba2fe292c stash tests: stash can lose data in a file removed from the index
If a file is removed from the index and then modified in the working
tree then stash will discard the working tree file with no way to
recover the changes.

This can might be done in one of a number of ways.

git rm file
vi file              # edit a new version
git stash

or with git mv

git mv file newfile
vi file              # make a new file with the old name
git stash

Signed-off-by: Charles Bailey <charles@hashpling.org>
2010-04-20 10:03:10 -07:00
Thomas Rast 460ccd0e19 stash pop: remove 'apply' options during 'drop' invocation
The 'git stash pop' option parsing used to remove the first argument
in --index mode.  At the time this was implemented, this first
argument was always --index.  However, since the invention of the -q
option in fcdd0e9 (stash: teach quiet option, 2009-06-17) you can
cause an internal invocation of

  git stash drop --index

by running

  git stash pop -q --index

which then of course fails because drop doesn't know --index.

To handle this, instead let 'git stash apply' decide what the future
argument to 'drop' should be.

Warning: this means that 'git stash apply' must parse all options that
'drop' can take, and deal with them in the same way.  This is
currently true for its only option -q.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
Acked-by: Stephen Boyd <bebarino@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-02-15 21:46:27 -08:00
Matthieu Moy 3c2eb80fe3 stash: simplify defaulting to "save" and reject unknown options
With the earlier DWIM patches, certain combination of options defaulted
to the "save" command correctly while certain equally valid combination
did not.  For example, "git stash -k" were Ok but "git stash -q -k" did
not work.

This makes the logic of defaulting to "save" much simpler. If there are no
non-flag arguments, it is clear that there is no command word, and we
default to "save" subcommand.  This rule prevents "git stash -q apply"
from quietly creating a stash with "apply" as the message.

This also teaches "git stash save" to reject an unknown option.  This is
to keep a mistyped "git stash save --quite" from creating a stash with a
message "--quite", and this safety is more important with the new logic
to default to "save" with any option-looking argument without an explicit
comand word.

[jc: this is based on Matthieu's 3-patch series, and a follow-up
discussion, and he and Peff take all the credit; if I have introduced bugs
while reworking, they are mine.]

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-09-01 22:03:11 -07:00
Johannes Schindelin ea41cfc4f5 Make 'git stash -k' a short form for 'git stash save --keep-index'
To save me from the carpal tunnel syndrome, make 'git stash' accept
the short option '-k' instead of '--keep-index', and for even more
convenience, let's DWIM when this developer forgot to type the 'save'
command.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-07-31 07:33:06 -07:00
Stephen Boyd fcdd0e92d9 stash: teach quiet option
Teach stash pop, apply, save, and drop to be quiet when told. By using
the quiet option (-q), these actions will be silent unless errors are
encountered.

Signed-off-by: Stephen Boyd <bebarino@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-06-18 11:54:57 -07:00
Nanako Shiraishi 0cb0e143ff tests: use "git xyzzy" form (t0000 - t3599)
Converts tests between t0050-t3903.

Signed-off-by: Nanako Shiraishi <nanako3@lavabit.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-09-03 12:41:46 -07:00