git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "SZEDER Gábor" <szeder@ira.uka.de>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org, "SZEDER Gábor" <szeder@ira.uka.de>
Subject: [PATCH 1/2] Add tests for git-sh-setup's require_clean_work_tree()
Date: Tue, 24 Nov 2015 15:45:44 +0100	[thread overview]
Message-ID: <1448376345-27339-1-git-send-email-szeder@ira.uka.de> (raw)

Add tests that check require_clean_work_tree() in the common cases,
i.e. on a branch with all combinations of clean and dirty index and
worktree, and also add tests that exercise it on an orphan branch.

require_clean_work_tree()'s behavior in the orphan branch cases is
questionable, as it exits with error on an orphan branch independently
from whether the index and worktree are clean or dirty (and it does so
because of the invalid HEAD, meaning that even when it should exit
with error, it does so for the wrong reason).  As scripts might rely
on the current behavior, we err on the side of compatibility and
safety, and expect the current behavior as success.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
 t/t2301-require-clean-work-tree.sh | 63 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)
 create mode 100755 t/t2301-require-clean-work-tree.sh

diff --git a/t/t2301-require-clean-work-tree.sh b/t/t2301-require-clean-work-tree.sh
new file mode 100755
index 0000000000..1bb41b59a5
--- /dev/null
+++ b/t/t2301-require-clean-work-tree.sh
@@ -0,0 +1,63 @@
+#!/bin/sh
+
+test_description='require_clean_work_tree'
+
+. ./test-lib.sh
+
+run_require_clean_work_tree () {
+	(
+		. "$(git --exec-path)"/git-sh-setup &&
+		require_clean_work_tree "do-something"
+	)
+}
+
+test_expect_success 'setup' '
+	test_commit initial file
+'
+
+test_expect_success 'success on clean index and worktree' '
+	run_require_clean_work_tree
+'
+
+test_expect_success 'error on dirty worktree' '
+	test_when_finished "git reset --hard" &&
+	echo dirty >file &&
+	test_must_fail run_require_clean_work_tree
+'
+
+test_expect_success 'error on dirty index' '
+	test_when_finished "git reset --hard" &&
+	echo dirty >file &&
+	git add file &&
+	test_must_fail run_require_clean_work_tree
+'
+
+test_expect_success 'error on dirty index and worktree' '
+	test_when_finished "git reset --hard" &&
+	echo dirty >file &&
+	git add file &&
+	echo dirtier >file &&
+	test_must_fail run_require_clean_work_tree
+'
+
+test_expect_success 'error on clean index and worktree while on orphan branch' '
+	test_when_finished "git checkout master" &&
+	git checkout --orphan orphan &&
+	git reset --hard &&
+	test_must_fail run_require_clean_work_tree
+'
+
+test_expect_success 'error on dirty index while on orphan branch' '
+	test_when_finished "git checkout master" &&
+	git checkout --orphan orphan &&
+	test_must_fail run_require_clean_work_tree
+'
+
+test_expect_success 'error on dirty index and work tree while on orphan branch' '
+	test_when_finished "git checkout master" &&
+	git checkout --orphan orphan &&
+	echo dirty >file &&
+	test_must_fail run_require_clean_work_tree
+'
+
+test_done
-- 
2.6.3.418.gc3b7987

             reply	other threads:[~2015-11-24 14:46 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-24 14:45 SZEDER Gábor [this message]
2015-11-24 14:45 ` [PATCH 2/2] sh-setup: make require_clean_work_tree() work on orphan branches SZEDER Gábor
2015-11-24 20:50   ` Jeff King
2015-11-30 12:37     ` SZEDER Gábor
2015-12-02 23:07     ` Junio C Hamano
2015-11-25  6:51   ` Johannes Sixt
2015-11-30 12:24     ` SZEDER Gábor
2016-01-21  0:06   ` Junio C Hamano
2016-01-20 23:59 ` [PATCH 1/2] Add tests for git-sh-setup's require_clean_work_tree() Junio C Hamano
2016-01-21  1:27   ` SZEDER Gábor
2016-01-21  4:52     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1448376345-27339-1-git-send-email-szeder@ira.uka.de \
    --to=szeder@ira.uka.de \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).