git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] test-lib: Allow to be used by contrib projects
@ 2008-06-12 19:13 Santi Béjar
  2008-06-12 19:13 ` [PATCH] contrib/what: "git status" for am/bisect/cherry-pick/merge/rebase/revert Santi Béjar
  0 siblings, 1 reply; 2+ messages in thread
From: Santi Béjar @ 2008-06-12 19:13 UTC (permalink / raw)
  To: git; +Cc: Santi Béjar

The contrib project can have test scripts like the ones in git.git.

They only need a test-lib.sh and a Makefile like the following:

[test-lib.sh]

GIT_TEST_DIR=$(pwd)/../../../t
PATH=$(pwd)/..:$PATH
. ../../../t/test-lib.sh

[end of test-lib.sh]

[Makefile]
include ../../../t/Makefile

Signed-off-by: Santi Béjar <sbejar@gmail.com>
---
 t/test-lib.sh |   15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/t/test-lib.sh b/t/test-lib.sh
index 7a8bd27..62976da 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -387,28 +387,29 @@ test_done () {
 
 # Test the binaries we have just built.  The tests are kept in
 # t/ subdirectory and are run in trash subdirectory.
-PATH=$(pwd)/..:$PATH
-GIT_EXEC_PATH=$(pwd)/..
-GIT_TEMPLATE_DIR=$(pwd)/../templates/blt
+[ -z "$GIT_TEST_DIR" ] && GIT_TEST_DIR=$(pwd)
+PATH=$GIT_TEST_DIR/..:$PATH
+GIT_EXEC_PATH=$GIT_TEST_DIR/..
+GIT_TEMPLATE_DIR=$GIT_TEST_DIR/../templates/blt
 unset GIT_CONFIG
 unset GIT_CONFIG_LOCAL
 GIT_CONFIG_NOSYSTEM=1
 GIT_CONFIG_NOGLOBAL=1
 export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_CONFIG_NOGLOBAL
 
-GITPERLLIB=$(pwd)/../perl/blib/lib:$(pwd)/../perl/blib/arch/auto/Git
+GITPERLLIB=$GIT_TEST_DIR/../perl/blib/lib:$GIT_TEST_DIR/../perl/blib/arch/auto/Git
 export GITPERLLIB
-test -d ../templates/blt || {
+test -d "$GIT_TEMPLATE_DIR" || {
 	error "You haven't built things yet, have you?"
 }
 
-if ! test -x ../test-chmtime; then
+if ! test -x $GIT_TEST_DIR/../test-chmtime; then
 	echo >&2 'You need to build test-chmtime:'
 	echo >&2 'Run "make test-chmtime" in the source (toplevel) directory'
 	exit 1
 fi
 
-. ../GIT-BUILD-OPTIONS
+. $GIT_TEST_DIR/../GIT-BUILD-OPTIONS
 
 # Test repository
 test="trash directory"
-- 
1.5.5.3

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

* [PATCH] contrib/what: "git status" for am/bisect/cherry-pick/merge/rebase/revert
  2008-06-12 19:13 [PATCH] test-lib: Allow to be used by contrib projects Santi Béjar
@ 2008-06-12 19:13 ` Santi Béjar
  0 siblings, 0 replies; 2+ messages in thread
From: Santi Béjar @ 2008-06-12 19:13 UTC (permalink / raw)
  To: git; +Cc: Santi Béjar


Signed-off-by: Santi Béjar <sbejar@gmail.com>
---
Hi *,

  for now, hoping the git-sequencer allows this, I've convert my git-what script
  to a single script.

  Also I've added some test that can be run thanks to my other path

[PATCH] test-lib: Allow to be used by contrib projects

 But they can also be run if they are copied to the toplevel t/ directory. 

 contrib/what/git-what                    |   86 ++++++++++++++++
 contrib/what/t/Makefile                  |    4 +
 contrib/what/t/t7800-what.sh             |  159 ++++++++++++++++++++++++++++++
 contrib/what/t/t7800/expect_am           |    3 +
 contrib/what/t/t7800/expect_bisect       |    3 +
 contrib/what/t/t7800/expect_cherry_pick  |    2 +
 contrib/what/t/t7800/expect_merge        |    2 +
 contrib/what/t/t7800/expect_merge_squash |    2 +
 contrib/what/t/t7800/expect_rebase       |    6 +
 contrib/what/t/t7800/expect_rebase_edit  |    9 ++
 contrib/what/t/t7800/expect_rebase_i     |    4 +
 contrib/what/t/t7800/expect_revert       |    2 +
 contrib/what/t/test-lib.sh               |    6 +
 13 files changed, 288 insertions(+), 0 deletions(-)
 create mode 100755 contrib/what/git-what
 create mode 100644 contrib/what/t/Makefile
 create mode 100755 contrib/what/t/t7800-what.sh
 create mode 100644 contrib/what/t/t7800/expect_am
 create mode 100644 contrib/what/t/t7800/expect_bisect
 create mode 100644 contrib/what/t/t7800/expect_cherry_pick
 create mode 100644 contrib/what/t/t7800/expect_merge
 create mode 100644 contrib/what/t/t7800/expect_merge_squash
 create mode 100644 contrib/what/t/t7800/expect_rebase
 create mode 100644 contrib/what/t/t7800/expect_rebase_edit
 create mode 100644 contrib/what/t/t7800/expect_rebase_i
 create mode 100644 contrib/what/t/t7800/expect_revert
 create mode 100644 contrib/what/t/test-lib.sh

diff --git a/contrib/what/git-what b/contrib/what/git-what
new file mode 100755
index 0000000..5ea13b3
--- /dev/null
+++ b/contrib/what/git-what
@@ -0,0 +1,86 @@
+#!/bin/sh
+
+gitdir="$(git rev-parse --git-dir 2>/dev/null)"
+
+test -z "$gitdir" && exit
+
+dotest="$gitdir/../.dotest"
+dotestint="$gitdir/.dotest-merge"
+
+if [ -d "$dotest" ] ; then
+    what="AM"
+    test -f "$dotest/rebasing" && what="REBASE"
+elif test -f "$dotestint/interactive" ; then
+    what="REBASE-I"
+    test -f "$dotestint/amend" && what="REBASE-AMEND"
+elif test -f "$gitdir/SQUASH_MSG" ; then
+    what="MERGE-SQUASH"
+elif test -f "$gitdir/MERGE_HEAD" ; then
+    what="MERGE"
+elif test -f "$gitdir/MERGE_MSG" ; then
+    what="PICK"
+elif test -f "$gitdir/BISECT_LOG" ; then
+    what="BISECT"
+else
+    exit 1
+fi
+
+case $what in
+    REBASE)
+	cmd=rebase
+	HELP="
+When you have resolved this problem run \"git rebase --continue\".
+If you would prefer to skip this patch, instead run \"git rebase --skip\".
+To restore the original branch and stop rebasing run \"git rebase --abort\".
+"
+	;;
+    REBASE-AMEND)
+	cmd="rebase (edit)"
+	HELP="
+You can amend the commit now, with
+
+	git commit --amend
+
+Once you are satisfied with your changes, run
+
+	git rebase --continue"
+	;;
+    REBASE-AM)
+	cmd=rebase
+	HELP="  After resolving the conflicts,
+mark the corrected paths with 'git add <paths>', and
+run 'git rebase --continue'"
+	;;
+    REBASE-I)
+	cmd="rebase -i"
+	HELP="  After resolving the conflicts,
+mark the corrected paths with 'git add <paths>', and
+run 'git rebase --continue'"
+	;;
+    AM)
+	cmd="\"git am\""
+	cmdline="git am"
+	HELP="When you have resolved this problem run \"$cmdline --resolved\".
+If you would prefer to skip this patch, instead run \"$cmdline --skip\"."
+	;;
+    MERGE)
+	cmd=merge
+	HELP="Fix conflicts and then commit the result."
+	;;
+    MERGE-SQUASH)
+	cmd="merge --squash"
+	HELP="Fix conflicts and then commit the result."
+	;;
+    PICK)
+	cmd="prepared commit"
+	HELP="Fix conflicts and then commit the result."
+	;;
+    BISECT)
+	cmd=bisect
+	HELP='You need to give me at least one good and one bad revisions.
+(You can use "git bisect bad" and "git bisect good" for that.)'
+	;;
+esac
+
+echo "You are in the middle of a $cmd:"
+echo "$HELP"
diff --git a/contrib/what/t/Makefile b/contrib/what/t/Makefile
new file mode 100644
index 0000000..790c81c
--- /dev/null
+++ b/contrib/what/t/Makefile
@@ -0,0 +1,4 @@
+# Run tests
+#
+
+include ../../../t/Makefile
diff --git a/contrib/what/t/t7800-what.sh b/contrib/what/t/t7800-what.sh
new file mode 100755
index 0000000..93c5f60
--- /dev/null
+++ b/contrib/what/t/t7800-what.sh
@@ -0,0 +1,159 @@
+#!/bin/sh
+#
+# Copyright (c) 2007 Santi Béjar, based on t4013 by Junio C Hamano
+#
+#
+
+test_description='What next?'
+
+. ./test-lib.sh
+
+LF='
+'
+
+test_expect_success setup '
+	GIT_AUTHOR_DATE="2006-06-26 00:00:00 +0000" &&
+	GIT_COMMITTER_DATE="2006-06-26 00:00:00 +0000" &&
+	export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
+
+	echo 1 >file &&
+	git add file &&
+	git commit -a -m 1 &&
+	git tag tag-1 &&
+	git branch 1 &&
+
+	echo 1a >> file &&
+	git commit -a -m 1a &&
+	git tag tag-1a &&
+	git branch 1a &&
+
+	echo 1a1 >> file &&
+	git commit -a -m 1a1 &&
+	git tag tag-1a1 &&
+	git branch 1a1 &&
+
+        git reset --hard tag-1 &&
+	echo 1b >> file &&
+	git commit -a -m 1b &&
+	git tag tag-1b &&
+	git branch 1b
+'
+
+test_output() {
+    if test -f "$1"
+    then
+	test_cmp "$1" "$2" &&
+	rm -f "$2"
+    else
+	# this is to help developing new tests.
+	cp "$2" "$1"
+	false
+    fi
+}
+
+echo "#!$SHELL_PATH" >fake-editor.sh
+cat >> fake-editor.sh <<\EOF
+case "$1" in
+*/COMMIT_EDITMSG)
+	test -z "$FAKE_COMMIT_MESSAGE" || echo "$FAKE_COMMIT_MESSAGE" > "$1"
+	test -z "$FAKE_COMMIT_AMEND" || echo "$FAKE_COMMIT_AMEND" >> "$1"
+	exit
+	;;
+esac
+test -z "$EXPECT_COUNT" ||
+	test "$EXPECT_COUNT" = $(sed -e '/^#/d' -e '/^$/d' < "$1" | wc -l) ||
+	exit
+test -z "$FAKE_LINES" && exit
+grep -v '^#' < "$1" > "$1".tmp
+rm -f "$1"
+cat "$1".tmp
+action=pick
+for line in $FAKE_LINES; do
+	case $line in
+	squash|edit)
+		action="$line";;
+	*)
+		echo sed -n "${line}s/^pick/$action/p"
+		sed -n "${line}p" < "$1".tmp
+		sed -n "${line}s/^pick/$action/p" < "$1".tmp >> "$1"
+		action=pick;;
+	esac
+done
+EOF
+
+test_set_editor "$(pwd)/fake-editor.sh"
+chmod a+x fake-editor.sh
+
+test_expect_success "what: nothing" '
+	! git what
+'
+
+test_expect_success "what: bisect" '
+	git bisect start &&
+	git what > output &&
+	git bisect reset &&
+	test_output ../t7800/expect_bisect output
+'
+
+test_expect_success "what: merge" '
+	git checkout master &&
+	git reset --hard tag-1a &&
+	! git merge tag-1b &&
+	git what > output &&
+	test_output ../t7800/expect_merge output
+'
+
+test_expect_success "what: merge --squash" '
+	git reset --hard tag-1a &&
+	! git merge --squash tag-1b &&
+	git what > output &&
+	test_output ../t7800/expect_merge_squash output
+'
+
+test_expect_success "what: rebase" '
+	git reset --hard tag-1b &&
+	! git rebase tag-1a1 &&
+	git what > output &&
+	git rebase --abort &&
+	test_output ../t7800/expect_rebase output
+'
+
+test_expect_success 'what: rebase -i' '
+	git reset --hard tag-1b &&
+	! git rebase -i tag-1a1 &&
+	git what > output &&
+	git rebase --abort &&
+	test_output ../t7800/expect_rebase_i output
+'
+
+test_expect_success 'what: rebase (amend)' '
+	git reset --hard tag-1b &&
+	FAKE_LINES="edit 1" git rebase -i HEAD^ &&
+	git what > output &&
+	git rebase --abort &&
+	test_output ../t7800/expect_rebase_edit output
+'
+
+test_expect_success "what: cherry-pick" '
+	git reset --hard tag-1b &&
+	! git cherry-pick tag-1a &&
+	git what > output &&
+	test_output ../t7800/expect_cherry_pick output
+'
+
+test_expect_success "what: revert" '
+	git reset --hard tag-1a1 &&
+	! git revert tag-1a &&
+	git what > output &&
+	test_output ../t7800/expect_revert output
+'
+
+test_expect_success "what: am" '
+	git reset --hard tag-1b &&
+	git format-patch --stdout tag-1..tag-1a1 > mbox &&
+	! git am mbox &&
+	git what > output &&
+	test_output ../t7800/expect_am output
+'
+
+test_done
diff --git a/contrib/what/t/t7800/expect_am b/contrib/what/t/t7800/expect_am
new file mode 100644
index 0000000..618d93e
--- /dev/null
+++ b/contrib/what/t/t7800/expect_am
@@ -0,0 +1,3 @@
+You are in the middle of a "git am":
+When you have resolved this problem run "git am --resolved".
+If you would prefer to skip this patch, instead run "git am --skip".
diff --git a/contrib/what/t/t7800/expect_bisect b/contrib/what/t/t7800/expect_bisect
new file mode 100644
index 0000000..923396b
--- /dev/null
+++ b/contrib/what/t/t7800/expect_bisect
@@ -0,0 +1,3 @@
+You are in the middle of a bisect:
+You need to give me at least one good and one bad revisions.
+(You can use "git bisect bad" and "git bisect good" for that.)
diff --git a/contrib/what/t/t7800/expect_cherry_pick b/contrib/what/t/t7800/expect_cherry_pick
new file mode 100644
index 0000000..60e733e
--- /dev/null
+++ b/contrib/what/t/t7800/expect_cherry_pick
@@ -0,0 +1,2 @@
+You are in the middle of a prepared commit:
+Fix conflicts and then commit the result.
diff --git a/contrib/what/t/t7800/expect_merge b/contrib/what/t/t7800/expect_merge
new file mode 100644
index 0000000..2c9b821
--- /dev/null
+++ b/contrib/what/t/t7800/expect_merge
@@ -0,0 +1,2 @@
+You are in the middle of a merge:
+Fix conflicts and then commit the result.
diff --git a/contrib/what/t/t7800/expect_merge_squash b/contrib/what/t/t7800/expect_merge_squash
new file mode 100644
index 0000000..3cdd4fa
--- /dev/null
+++ b/contrib/what/t/t7800/expect_merge_squash
@@ -0,0 +1,2 @@
+You are in the middle of a merge --squash:
+Fix conflicts and then commit the result.
diff --git a/contrib/what/t/t7800/expect_rebase b/contrib/what/t/t7800/expect_rebase
new file mode 100644
index 0000000..3975cc0
--- /dev/null
+++ b/contrib/what/t/t7800/expect_rebase
@@ -0,0 +1,6 @@
+You are in the middle of a rebase:
+
+When you have resolved this problem run "git rebase --continue".
+If you would prefer to skip this patch, instead run "git rebase --skip".
+To restore the original branch and stop rebasing run "git rebase --abort".
+
diff --git a/contrib/what/t/t7800/expect_rebase_edit b/contrib/what/t/t7800/expect_rebase_edit
new file mode 100644
index 0000000..e4d76c2
--- /dev/null
+++ b/contrib/what/t/t7800/expect_rebase_edit
@@ -0,0 +1,9 @@
+You are in the middle of a rebase (edit):
+
+You can amend the commit now, with
+
+	git commit --amend
+
+Once you are satisfied with your changes, run
+
+	git rebase --continue
diff --git a/contrib/what/t/t7800/expect_rebase_i b/contrib/what/t/t7800/expect_rebase_i
new file mode 100644
index 0000000..e17f5a7
--- /dev/null
+++ b/contrib/what/t/t7800/expect_rebase_i
@@ -0,0 +1,4 @@
+You are in the middle of a rebase -i:
+  After resolving the conflicts,
+mark the corrected paths with 'git add <paths>', and
+run 'git rebase --continue'
diff --git a/contrib/what/t/t7800/expect_revert b/contrib/what/t/t7800/expect_revert
new file mode 100644
index 0000000..60e733e
--- /dev/null
+++ b/contrib/what/t/t7800/expect_revert
@@ -0,0 +1,2 @@
+You are in the middle of a prepared commit:
+Fix conflicts and then commit the result.
diff --git a/contrib/what/t/test-lib.sh b/contrib/what/t/test-lib.sh
new file mode 100644
index 0000000..1ce596a
--- /dev/null
+++ b/contrib/what/t/test-lib.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+GIT_TEST_DIR=$(pwd)/../../../t
+PATH=$(pwd)/..:$PATH
+. ../../../t/test-lib.sh
+
-- 
1.5.5.3

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

end of thread, other threads:[~2008-06-12 19:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-12 19:13 [PATCH] test-lib: Allow to be used by contrib projects Santi Béjar
2008-06-12 19:13 ` [PATCH] contrib/what: "git status" for am/bisect/cherry-pick/merge/rebase/revert Santi Béjar

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).