[PATCH] contrib/what: "git status" for am/bisect/cherry-pick/merge/rebase/revert

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Santi Béjar <sbejar@xxxxxxxxx>
---
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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux