@matheusbsbs / matheus-bagliano / commits / daf7a0c000
Fork 0

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>

Jon Seymour committed Aug 21, 2010 at 14:09 UTC daf7a0c00039ace8ec965316a0bf8354eb973795
1 file changed +112
t/t3903-stash.sh
+112
@@ -378,4 +378,116 @@ test_expect_failure 'stash file to directory' '
378 test foo = "$(cat file/file)"
379 '
380
381 +test_expect_success 'stash branch - no stashes on stack, stash-like argument' '
382 + git stash clear &&
383 + test_when_finished "git reset --hard HEAD" &&
384 + git reset --hard &&
385 + echo foo >> file &&
386 + STASH_ID=$(git stash create) &&
387 + git reset --hard &&
388 + git stash branch stash-branch ${STASH_ID} &&
389 + test_when_finished "git reset --hard HEAD && git checkout master && git branch -D stash-branch" &&
390 + test $(git ls-files --modified | wc -l) -eq 1
391 +'
392 +
393 +test_expect_success 'stash branch - stashes on stack, stash-like argument' '
394 + git stash clear &&
395 + test_when_finished "git reset --hard HEAD" &&
396 + git reset --hard &&
397 + echo foo >> file &&
398 + git stash &&
399 + test_when_finished "git stash drop" &&
400 + echo bar >> file &&
401 + STASH_ID=$(git stash create) &&
402 + git reset --hard &&
403 + git stash branch stash-branch ${STASH_ID} &&
404 + test_when_finished "git reset --hard HEAD && git checkout master && git branch -D stash-branch" &&
405 + test $(git ls-files --modified | wc -l) -eq 1
406 +'
407 +
408 +test_expect_success 'stash show - stashes on stack, stash-like argument' '
409 + git stash clear &&
410 + test_when_finished "git reset --hard HEAD" &&
411 + git reset --hard &&
412 + echo foo >> file &&
413 + git stash &&
414 + test_when_finished "git stash drop" &&
415 + echo bar >> file &&
416 + STASH_ID=$(git stash create) &&
417 + git reset --hard &&
418 + git stash show ${STASH_ID}
419 +'
420 +test_expect_success 'stash show - no stashes on stack, stash-like argument' '
421 + git stash clear &&
422 + test_when_finished "git reset --hard HEAD" &&
423 + git reset --hard &&
424 + echo foo >> file &&
425 + STASH_ID=$(git stash create) &&
426 + git reset --hard &&
427 + git stash show ${STASH_ID}
428 +'
429 +
430 +test_expect_success 'stash drop - fail early if specified stash is not a stash reference' '
431 + git stash clear &&
432 + test_when_finished "git reset --hard HEAD && git stash clear" &&
433 + git reset --hard &&
434 + echo foo > file &&
435 + git stash &&
436 + echo bar > file &&
437 + git stash &&
438 + test_must_fail "git stash drop $(git rev-parse stash@{0})" &&
439 + git stash pop &&
440 + test bar = "$(cat file)" &&
441 + git reset --hard HEAD
442 +'
443 +
444 +test_expect_success 'stash pop - fail early if specified stash is not a stash reference' '
445 + git stash clear &&
446 + test_when_finished "git reset --hard HEAD && git stash clear" &&
447 + git reset --hard &&
448 + echo foo > file &&
449 + git stash &&
450 + echo bar > file &&
451 + git stash &&
452 + test_must_fail "git stash pop $(git rev-parse stash@{0})" &&
453 + git stash pop &&
454 + test bar = "$(cat file)" &&
455 + git reset --hard HEAD
456 +'
457 +
458 +test_expect_success 'ref with non-existant reflog' '
459 + git stash clear &&
460 + echo bar5 > file &&
461 + echo bar6 > file2 &&
462 + git add file2 &&
463 + git stash &&
464 + ! "git rev-parse --quiet --verify does-not-exist" &&
465 + test_must_fail "git stash drop does-not-exist" &&
466 + test_must_fail "git stash drop does-not-exist@{0}" &&
467 + test_must_fail "git stash pop does-not-exist" &&
468 + test_must_fail "git stash pop does-not-exist@{0}" &&
469 + test_must_fail "git stash apply does-not-exist" &&
470 + test_must_fail "git stash apply does-not-exist@{0}" &&
471 + test_must_fail "git stash show does-not-exist" &&
472 + test_must_fail "git stash show does-not-exist@{0}" &&
473 + test_must_fail "git stash branch tmp does-not-exist" &&
474 + test_must_fail "git stash branch tmp does-not-exist@{0}" &&
475 + git stash drop
476 +'
477 +
478 +test_expect_success 'invalid ref of the form stash@{n}, n >= N' '
479 + git stash clear &&
480 + test_must_fail "git stash drop stash@{0}" &&
481 + echo bar5 > file &&
482 + echo bar6 > file2 &&
483 + git add file2 &&
484 + git stash &&
485 + test_must_fail "git drop stash@{1}" &&
486 + test_must_fail "git pop stash@{1}" &&
487 + test_must_fail "git apply stash@{1}" &&
488 + test_must_fail "git show stash@{1}" &&
489 + test_must_fail "git branch tmp stash@{1}" &&
490 + git stash drop
491 +'
492 +
493 test_done