Skip to content

Commit

Permalink
Merge branch 'pt/am-foreign' into next
Browse files Browse the repository at this point in the history
Various enhancements around "git am" reading patches generated by
foreign SCM.

* pt/am-foreign:
  am: teach mercurial patch parser how to read from stdin
  am: use gmtime() to parse mercurial patch date
  t4150: test applying StGit series
  am: teach StGit patch parser how to read from stdin
  t4150: test applying StGit patch
  • Loading branch information
gitster committed Jun 24, 2015
2 parents 162e134 + 9f0aa6e commit 838c702
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 5 deletions.
12 changes: 7 additions & 5 deletions git-am.sh
Expand Up @@ -300,6 +300,7 @@ split_patches () {
;;
stgit)
this=0
test 0 -eq "$#" && set -- -
for stgit in "$@"
do
this=$(expr "$this" + 1)
Expand All @@ -321,14 +322,15 @@ split_patches () {
print "Subject: ", $_ ;
$subject = 1;
}
' < "$stgit" > "$dotest/$msgnum" || clean_abort
' -- "$stgit" >"$dotest/$msgnum" || clean_abort
done
echo "$this" > "$dotest/last"
this=
msgnum=
;;
hg)
this=0
test 0 -eq "$#" && set -- -
for hg in "$@"
do
this=$(( $this + 1 ))
Expand All @@ -345,17 +347,17 @@ split_patches () {
elsif (/^\# User /) { s/\# User/From:/ ; print ; }
elsif (/^\# Date /) {
my ($hashsign, $str, $time, $tz) = split ;
$tz = sprintf "%+05d", (0-$tz)/36;
$tz_str = sprintf "%+05d", (0-$tz)/36;
print "Date: " .
strftime("%a, %d %b %Y %H:%M:%S ",
localtime($time))
. "$tz\n";
gmtime($time-$tz))
. "$tz_str\n";
} elsif (/^\# /) { next ; }
else {
print "\n", $_ ;
$subject = 1;
}
' <"$hg" >"$dotest/$msgnum" || clean_abort
' -- "$hg" >"$dotest/$msgnum" || clean_abort
done
echo "$this" >"$dotest/last"
this=
Expand Down
82 changes: 82 additions & 0 deletions t/t4150-am.sh
Expand Up @@ -104,6 +104,38 @@ test_expect_success setup '
echo "X-Fake-Field: Line Three" &&
git format-patch --stdout first | sed -e "1d"
} > patch1-ws.eml &&
{
sed -ne "1p" msg &&
echo &&
echo "From: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" &&
echo "Date: $GIT_AUTHOR_DATE" &&
echo &&
sed -e "1,2d" msg &&
echo &&
echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" &&
echo "---" &&
git diff-tree --no-commit-id --stat -p second
} >patch1-stgit.eml &&
mkdir stgit-series &&
cp patch1-stgit.eml stgit-series/patch &&
{
echo "# This series applies on GIT commit $(git rev-parse first)" &&
echo "patch"
} >stgit-series/series &&
{
echo "# HG changeset patch" &&
echo "# User $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" &&
echo "# Date $test_tick 25200" &&
echo "# $(git show --pretty="%aD" -s second)" &&
echo "# Node ID $_z40" &&
echo "# Parent $_z40" &&
cat msg &&
echo &&
echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" &&
echo &&
git diff-tree --no-commit-id -p second
} >patch1-hg.eml &&
sed -n -e "3,\$p" msg >file &&
git add file &&
Expand Down Expand Up @@ -187,6 +219,56 @@ test_expect_success 'am applies patch e-mail with preceding whitespace' '
test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
'

test_expect_success 'am applies stgit patch' '
rm -fr .git/rebase-apply &&
git checkout -f first &&
git am patch1-stgit.eml &&
test_path_is_missing .git/rebase-apply &&
git diff --exit-code second &&
test_cmp_rev second HEAD &&
test_cmp_rev second^ HEAD^
'

test_expect_success 'am --patch-format=stgit applies stgit patch' '
rm -fr .git/rebase-apply &&
git checkout -f first &&
git am --patch-format=stgit <patch1-stgit.eml &&
test_path_is_missing .git/rebase-apply &&
git diff --exit-code second &&
test_cmp_rev second HEAD &&
test_cmp_rev second^ HEAD^
'

test_expect_success 'am applies stgit series' '
rm -fr .git/rebase-apply &&
git checkout -f first &&
git am stgit-series/series &&
test_path_is_missing .git/rebase-apply &&
git diff --exit-code second &&
test_cmp_rev second HEAD &&
test_cmp_rev second^ HEAD^
'

test_expect_success 'am applies hg patch' '
rm -fr .git/rebase-apply &&
git checkout -f first &&
git am patch1-hg.eml &&
test_path_is_missing .git/rebase-apply &&
git diff --exit-code second &&
test_cmp_rev second HEAD &&
test_cmp_rev second^ HEAD^
'

test_expect_success 'am --patch-format=hg applies hg patch' '
rm -fr .git/rebase-apply &&
git checkout -f first &&
git am --patch-format=hg <patch1-hg.eml &&
test_path_is_missing .git/rebase-apply &&
git diff --exit-code second &&
test_cmp_rev second HEAD &&
test_cmp_rev second^ HEAD^
'

test_expect_success 'setup: new author and committer' '
GIT_AUTHOR_NAME="Another Thor" &&
GIT_AUTHOR_EMAIL="a.thor@example.com" &&
Expand Down

0 comments on commit 838c702

Please sign in to comment.