All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] Add tests for git-sh-setup's require_clean_work_tree()
@ 2015-11-24 14:45 SZEDER Gábor
  2015-11-24 14:45 ` [PATCH 2/2] sh-setup: make require_clean_work_tree() work on orphan branches SZEDER Gábor
  2016-01-20 23:59 ` [PATCH 1/2] Add tests for git-sh-setup's require_clean_work_tree() Junio C Hamano
  0 siblings, 2 replies; 11+ messages in thread
From: SZEDER Gábor @ 2015-11-24 14:45 UTC (permalink / raw)
  To: Jeff King; +Cc: git, SZEDER Gábor

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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2016-01-21  4:52 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-24 14:45 [PATCH 1/2] Add tests for git-sh-setup's require_clean_work_tree() SZEDER Gábor
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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.