Merge branch 'ns/am-to-empty'

* ns/am-to-empty:
  git-am: teach git-am to apply a patch to an unborn branch
maint
Junio C Hamano 2009-04-17 21:42:12 -07:00
commit 1ee28e58d5
2 changed files with 39 additions and 5 deletions

View File

@ -36,6 +36,13 @@ cd_to_toplevel
git var GIT_COMMITTER_IDENT >/dev/null || git var GIT_COMMITTER_IDENT >/dev/null ||
die "You need to set your committer info first" die "You need to set your committer info first"


if git rev-parse --verify -q HEAD >/dev/null
then
HAS_HEAD=yes
else
HAS_HEAD=
fi

sq () { sq () {
for sqarg for sqarg
do do
@ -290,16 +297,26 @@ else
: >"$dotest/rebasing" : >"$dotest/rebasing"
else else
: >"$dotest/applying" : >"$dotest/applying"
git update-ref ORIG_HEAD HEAD if test -n "$HAS_HEAD"
then
git update-ref ORIG_HEAD HEAD
else
git update-ref -d ORIG_HEAD >/dev/null 2>&1
fi
fi fi
fi fi


case "$resolved" in case "$resolved" in
'') '')
files=$(git diff-index --cached --name-only HEAD --) || exit case "$HAS_HEAD" in
'')
files=$(git ls-files) ;;
?*)
files=$(git diff-index --cached --name-only HEAD --) ;;
esac || exit
if test "$files" if test "$files"
then then
: >"$dotest/dirtyindex" test -n "$HAS_HEAD" && : >"$dotest/dirtyindex"
die "Dirty index: cannot apply patches (dirty: $files)" die "Dirty index: cannot apply patches (dirty: $files)"
fi fi
esac esac
@ -541,18 +558,20 @@ do
fi fi


tree=$(git write-tree) && tree=$(git write-tree) &&
parent=$(git rev-parse --verify HEAD) &&
commit=$( commit=$(
if test -n "$ignore_date" if test -n "$ignore_date"
then then
GIT_AUTHOR_DATE= GIT_AUTHOR_DATE=
fi fi
parent=$(git rev-parse --verify -q HEAD) ||
echo >&2 "applying to an empty history"

if test -n "$committer_date_is_author_date" if test -n "$committer_date_is_author_date"
then then
GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE" GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
export GIT_COMMITTER_DATE export GIT_COMMITTER_DATE
fi && fi &&
git commit-tree $tree -p $parent <"$dotest/final-commit" git commit-tree $tree ${parent:+-p $parent} <"$dotest/final-commit"
) && ) &&
git update-ref -m "$GIT_REFLOG_ACTION: $FIRSTLINE" HEAD $commit $parent || git update-ref -m "$GIT_REFLOG_ACTION: $FIRSTLINE" HEAD $commit $parent ||
stop_here $this stop_here $this

View File

@ -290,4 +290,19 @@ test_expect_success 'am --ignore-date' '
echo "$at" | grep "+0000" echo "$at" | grep "+0000"
' '


test_expect_success 'am into an unborn branch' '
rm -fr subdir &&
mkdir -p subdir &&
git format-patch --numbered-files -o subdir -1 first &&
(
cd subdir &&
git init &&
git am 1
) &&
result=$(
cd subdir && git rev-parse HEAD^{tree}
) &&
test "z$result" = "z$(git rev-parse first^{tree})"
'

test_done test_done