From: Techlive Zheng <techlivezheng@gmail.com>
To: git@vger.kernel.org
Cc: apenwarr@gmail.com, greened@obbligato.org,
Techlive Zheng <techlivezheng@gmail.com>
Subject: [PATCH/RFC v2 7/8] contrib/subtree: Use %B for the split commit message
Date: Mon, 14 Jan 2013 11:52:20 +0800 [thread overview]
Message-ID: <1358135541-10349-8-git-send-email-techlivezheng@gmail.com> (raw)
In-Reply-To: <1358135541-10349-1-git-send-email-techlivezheng@gmail.com>
Use %B rather than %s%n%n%b to handle the special case of a commit that
only has a subject line. We don't want to introduce a newline after the
subject, causing generation of a new hash.
After this commit, the newly split branch might differ from the previous
one. If this is the case, --fallback option could help.
Signed-off-by: Techlive Zheng <techlivezheng@gmail.com>
Signed-off-by: David A. Greene <greened@obbligato.org>
---
contrib/subtree/git-subtree.sh | 13 ++++++++++-
contrib/subtree/git-subtree.txt | 13 +++++++++++
contrib/subtree/t/t7900-subtree.sh | 47 ++++++++++++++++++++++++++++++++++++++
3 files changed, 72 insertions(+), 1 deletion(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 88903c0..d529a76 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -25,6 +25,7 @@ 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
rejoin merge the new branch back into HEAD
+fallback fallback to the obsolete commit generating mechanism
options for 'add', 'merge', 'pull' and 'push'
squash merge subtree changes as a single commit
"
@@ -45,6 +46,7 @@ ignore_joins=
annotate=
squash=
message=
+fallback=
debug()
{
@@ -92,6 +94,8 @@ while [ $# -gt 0 ]; do
--no-ignore-joins) ignore_joins= ;;
--squash) squash=1 ;;
--no-squash) squash= ;;
+ --fallback) fallback=1 ;;
+ --no-fallback) fallback= ;;
--) break ;;
*) die "Unexpected option: $opt" ;;
esac
@@ -296,7 +300,14 @@ copy_commit()
# We're going to set some environment vars here, so
# do it in a subshell to get rid of them safely later
debug copy_commit "{$1}" "{$2}" "{$3}"
- git log -1 --pretty=format:'%an%n%ae%n%ad%n%cn%n%ce%n%cd%n%s%n%n%b' "$1" |
+
+ if [ -z "$fallback" ]; then
+ log_format='%an%n%ae%n%ad%n%cn%n%ce%n%cd%n%B'
+ else
+ log_format='%an%n%ae%n%ad%n%cn%n%ce%n%cd%n%s%n%n%b'
+ fi
+
+ git log -1 --pretty=format:"$log_format" "$1" |
(
read GIT_AUTHOR_NAME
read GIT_AUTHOR_EMAIL
diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
index 72be8e4..55d0575 100644
--- a/contrib/subtree/git-subtree.txt
+++ b/contrib/subtree/git-subtree.txt
@@ -254,6 +254,19 @@ OPTIONS FOR split
'--rejoin' when you split, because you don't want the
subproject's history to be part of your project anyway.
+--fallback::
+ Previously, git subtree would introduce an extra new line for
+ the commits whose commit message contains only one line.
+ This behavior has been correct. Unfortunately, for those whose
+ current split branch contains these kind of commits, git subtree
+ will generate a new split branch which differs from the existing
+ split branch in these commits. It is better to use this new
+ split branch, because its commits stay intact within the mainline.
+
+ Otherwise, the previous fault behavior could still be used with
+ this option. This option is only for a compatible purpose, newly
+ split branch should never use this option.
+
EXAMPLE 1. Add command
----------------------
diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index ef83f31..232ed89 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -399,6 +399,53 @@ test_expect_success 'split subdir/ with --branch for an incompatible branch' '
)
'
+test_expect_success 'make sure commits with one line message stay intact after split' '
+ test_create_repo $test_count &&
+ test_create_repo $test_count/subproj &&
+ test_create_commit $test_count main1 &&
+ test_create_commit $test_count/subproj sub1 &&
+ (
+ cd $test_count &&
+ git fetch ./subproj master &&
+ ori_hash=$(git rev-parse FETCH_HEAD) &&
+ git branch subori FETCH_HEAD &&
+ git filter-branch --index-filter '\''git ls-files -s | sed "s-\t-&subdir/-" | GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info && mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"'\'' subori
+ git merge -m "Merge B project as our subdirectory" subori &&
+ git subtree split --prefix subdir --branch splitbr1 &&
+ new_hash_1=$(git rev-parse splitbr1) &&
+ test_equal "$ori_hash" "$new_hash_1" &&
+ git subtree split --prefix subdir --branch splitbr2 --fallback &&
+ new_hash_2=$(git rev-parse splitbr2) &&
+ test_must_fail test_equal "$ori_hash" "$new_hash_2"
+ )
+'
+
+test_expect_success 'make sure --fallback option works correctly for the existing split branch' '
+ test_create_repo "$test_count" &&
+ test_create_repo "$test_count"/subproj &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count"/subproj sub1 &&
+ (
+ cd $test_count &&
+ git fetch ./subproj master &&
+ ori_hash=$(git rev-parse FETCH_HEAD) &&
+ git subtree add --prefix=subdir FETCH_HEAD
+ ) &&
+ test_create_commit "$test_count" subdir/main-sub1 &&
+ (
+ cd $test_count &&
+ git subtree split --prefix subdir --branch splitbr1 &&
+ git subtree split --prefix subdir --branch splitbr2 --fallback &&
+ test_must_fail test_equal "$(git rev-parse splitbr1)" "$(git rev-parse splitbr2)"
+ ) &&
+ test_create_commit "$test_count" subdir/main-sub2 &&
+ (
+ cd $test_count &&
+ test_must_fail git subtree split --prefix subdir --branch splitbr2 &&
+ git subtree split --prefix subdir --branch splitbr2 --fallback
+ )
+'
+
#
# Validity checking
#
--
1.8.1
next prev parent reply other threads:[~2013-01-14 3:59 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-13 1:52 [PATCH/RFC 0/7] mutiple improvements Techlive Zheng
2013-01-13 1:52 ` [PATCH/RFC 1/7] contrib/subtree: Add vim modeline Techlive Zheng
2013-01-13 1:52 ` [PATCH/RFC 2/7] contrib/subtree: Ignore testing directory Techlive Zheng
2013-01-13 1:52 ` [PATCH/RFC 3/7] contrib/subtree: Remove test number comments Techlive Zheng
2013-01-13 1:52 ` [PATCH/RFC 4/7] contrib/subtree: Code cleaning and refactoring Techlive Zheng
2013-01-14 3:30 ` 郑文辉(Techlive Zheng)
2013-01-13 1:52 ` [PATCH/RFC 5/7] contrib/subtree: Make each test self-contained Techlive Zheng
2013-01-13 1:52 ` [PATCH/RFC 6/7] contrib/subtree: Use %B for the split commit message Techlive Zheng
2013-01-13 1:52 ` [PATCH/RFC 7/7] contrib/subtree: Handle '--prefix' argument with a slash appended Techlive Zheng
2013-01-14 3:52 ` [PATCH/RFC v2 0/8] contrib/subtree: Reroll to follow Git's whitespace policy Techlive Zheng
2013-01-14 3:52 ` [PATCH/RFC v2 1/8] contrib/subtree: Fix whitespaces Techlive Zheng
2013-01-14 3:52 ` [PATCH/RFC v2 2/8] contrib/subtree: Add vim modeline Techlive Zheng
2013-01-14 3:52 ` [PATCH/RFC v2 3/8] contrib/subtree: Ignore testing directory Techlive Zheng
2013-01-14 3:52 ` [PATCH/RFC v2 4/8] contrib/subtree: Remove test number comments Techlive Zheng
2013-01-14 3:52 ` [PATCH/RFC v2 5/8] contrib/subtree: Code cleaning and refactoring Techlive Zheng
2013-01-14 3:52 ` [PATCH/RFC v2 6/8] contrib/subtree: Make each test self-contained Techlive Zheng
2013-01-14 3:52 ` Techlive Zheng [this message]
2013-01-14 3:52 ` [PATCH/RFC v2 8/8] contrib/subtree: Handle '--prefix' argument with a slash appended Techlive Zheng
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=1358135541-10349-8-git-send-email-techlivezheng@gmail.com \
--to=techlivezheng@gmail.com \
--cc=apenwarr@gmail.com \
--cc=git@vger.kernel.org \
--cc=greened@obbligato.org \
/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).