git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "David A. Greene" <greened@obbligato.org>
To: git@vger.kernel.org
Cc: James Nylen <jnylen@gmail.com>,
	"David A. Greene" <greened@obbligato.org>
Subject: [PATCH 3/7] contrib/subtree: Add --unannotate
Date: Tue,  8 Jan 2013 06:09:53 -0600	[thread overview]
Message-ID: <1357646997-28675-4-git-send-email-greened@obbligato.org> (raw)
In-Reply-To: <1357646997-28675-1-git-send-email-greened@obbligato.org>

From: James Nylen <jnylen@gmail.com>

Teach git-subtree about --unannotate.  This option strips a prefix
from a commit message when doing a subtree split.

Signed-off-by: James Nylen <jnylen@gmail.com>

Signed-off-by: David A. Greene <greened@obbligato.org>
---
 contrib/subtree/git-subtree.sh     |   11 +++++++++--
 contrib/subtree/git-subtree.txt    |   15 +++++++++++++++
 contrib/subtree/t/t7900-subtree.sh |   12 ++++++++++--
 3 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 5341b36..cac0680 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -21,6 +21,7 @@ P,prefix=     the name of the subdir to split out
 m,message=    use the given message as the commit message for the merge commit
  options for 'split'
 annotate=     add a prefix to commit message of new commits
+unannotate=   remove a prefix from new commit messages (supports bash globbing)
 b,branch=     create a new branch from the split subtree
 ignore-joins  ignore prior --rejoin commits
 onto=         try connecting new tree to an existing one
@@ -43,6 +44,7 @@ onto=
 rejoin=
 ignore_joins=
 annotate=
+unannotate=
 squash=
 message=
 
@@ -80,6 +82,8 @@ while [ $# -gt 0 ]; do
 		-d) debug=1 ;;
 		--annotate) annotate="$1"; shift ;;
 		--no-annotate) annotate= ;;
+		--unannotate) unannotate="$1"; shift ;;
+		--no-unannotate) unannotate= ;;
 		-b) branch="$1"; shift ;;
 		-P) prefix="$1"; shift ;;
 		-m) message="$1"; shift ;;
@@ -314,8 +318,11 @@ copy_commit()
 			GIT_COMMITTER_NAME \
 			GIT_COMMITTER_EMAIL \
 			GIT_COMMITTER_DATE
-		(echo -n "$annotate"; cat ) |
-		git commit-tree "$2" $3  # reads the rest of stdin
+		(
+			read FIRST_LINE
+			echo "$annotate${FIRST_LINE#$unannotate}"
+			cat  # reads the rest of stdin
+		) | git commit-tree "$2" $3
 	) || die "Can't copy commit $1"
 }
 
diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
index c5bce41..75aa690 100644
--- a/contrib/subtree/git-subtree.txt
+++ b/contrib/subtree/git-subtree.txt
@@ -198,6 +198,21 @@ OPTIONS FOR split
 	git subtree tries to make it work anyway, particularly
 	if you use --rejoin, but it may not always be effective.
 
+--unannotate=<annotation>::
+	This option is only valid for the split command.
+
+	When generating synthetic history, try to remove the prefix
+	<annotation> from each commit message (using bash's "strip
+	shortest match from beginning" command, which supports
+	globbing).  This makes sense if you format library commits
+	like "library: Change something or other" when you're working
+	in your project's repository, but you want to remove this
+	prefix when pushing back to the library's upstream repository.
+	(In this case --unannotate='*: ' would work well.)
+	
+	Like --annotate,  you need to use the same <annotation>
+	whenever you split, or you may run into problems.
+
 -b <branch>::
 --branch=<branch>::
 	This option is only valid for the split command.
diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index 3f17f55..de45e34 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -143,7 +143,7 @@ test_expect_success 'merge fetched subproj' '
 
 test_expect_success 'add main-sub5' '
         create subdir/main-sub5 &&
-        git commit -m "main-sub5"
+        git commit -m "subproj: main-sub5"
 '
 
 test_expect_success 'add main6' '
@@ -153,7 +153,7 @@ test_expect_success 'add main6' '
 
 test_expect_success 'add main-sub7' '
         create subdir/main-sub7 &&
-        git commit -m "main-sub7"
+        git commit -m "subproj: main-sub7"
 '
 
 test_expect_success 'fetch new subproj history' '
@@ -226,6 +226,14 @@ test_expect_success 'check hash of split' '
         check_equal ''"$new_hash"'' "$subdir_hash"
 '
 
+test_expect_success 'check --unannotate' '
+        spl1=$(git subtree split --unannotate='"subproj:"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin) &&
+        undo &&
+        git subtree split --unannotate='"subproj:"' --prefix subdir --onto FETCH_HEAD --branch splitunann &&
+        check_equal ''"$(git rev-parse splitunann)"'' "$spl1" &&
+        check_equal ''"$(git log splitunann | grep subproj)"'' ""
+'
+
 test_expect_success 'check split with --branch for an existing branch' '
         spl1=''"$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"'' &&
         undo &&
-- 
1.7.10.4

  parent reply	other threads:[~2013-01-08 12:11 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-08 12:09 Revised git-subtree Patches David A. Greene
2013-01-08 12:09 ` [PATCH 1/7] Remove Test Number Comments David A. Greene
2013-01-08 12:09 ` [PATCH 2/7] contrib/subtree: Use %B for Split Subject/Body David A. Greene
2013-01-08 18:29   ` Junio C Hamano
2013-01-16  3:14     ` greened
2013-01-08 23:21   ` 郑文辉(Techlive Zheng)
2013-01-09  0:41     ` Junio C Hamano
2013-01-16  3:18       ` greened
2013-01-16 15:43         ` Junio C Hamano
2013-01-22  8:39           ` greened
2013-01-08 12:09 ` David A. Greene [this message]
2013-01-08 18:45   ` [PATCH 3/7] contrib/subtree: Add --unannotate Junio C Hamano
2013-01-16  3:20     ` greened
2013-01-16  4:06       ` greened
2013-01-16  4:31         ` Junio C Hamano
2013-01-22  8:37           ` greened
2013-01-08 12:09 ` [PATCH 4/7] contrib/subtree: Better Error Handling for add David A. Greene
2013-01-08 18:45   ` Junio C Hamano
2013-01-16  3:21     ` greened
2013-01-08 12:09 ` [PATCH 5/7] contrib/subtree: Fix Synopsis David A. Greene
2013-01-08 12:09 ` [PATCH 6/7] contrib/subtree: Honor DESTDIR David A. Greene
2013-01-08 12:09 ` [PATCH 7/7] contrib/subtree: Make the Manual Directory if Needed David A. Greene

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=1357646997-28675-4-git-send-email-greened@obbligato.org \
    --to=greened@obbligato.org \
    --cc=git@vger.kernel.org \
    --cc=jnylen@gmail.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).