summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ee7ec2f)
raw | patch | inline | side by side (parent: ee7ec2f)
author | Nanako Shiraishi <nanako3@lavabit.com> | |
Fri, 10 Apr 2009 00:34:42 +0000 (09:34 +0900) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 13 Apr 2009 01:42:15 +0000 (18:42 -0700) |
People sometimes wonder why they cannot apply a patch that only
creates new files to an unborn branch.
Signed-off-by: Nanako Shiraishi <nanako3@lavabit.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
creates new files to an unborn branch.
Signed-off-by: Nanako Shiraishi <nanako3@lavabit.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-am.sh | patch | blob | history | |
t/t4150-am.sh | patch | blob | history |
diff --git a/git-am.sh b/git-am.sh
index d3390755fc687a611e89320a7bbfb4ead512c863..774383fb6893776fcd9454b080b7a8346e6b034d 100755 (executable)
--- a/git-am.sh
+++ b/git-am.sh
git var GIT_COMMITTER_IDENT >/dev/null ||
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 () {
for sqarg
do
: >"$dotest/rebasing"
else
: >"$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
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"
then
- : >"$dotest/dirtyindex"
+ test -n "$HAS_HEAD" && : >"$dotest/dirtyindex"
die "Dirty index: cannot apply patches (dirty: $files)"
fi
esac
fi
tree=$(git write-tree) &&
- parent=$(git rev-parse --verify HEAD) &&
commit=$(
if test -n "$ignore_date"
then
GIT_AUTHOR_DATE=
fi
+ parent=$(git rev-parse --verify -q HEAD) ||
+ echo >&2 "applying to an empty history"
+
if test -n "$committer_date_is_author_date"
then
GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
export GIT_COMMITTER_DATE
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 ||
stop_here $this
diff --git a/t/t4150-am.sh b/t/t4150-am.sh
index 5e65afa0c10d02e50c79b550a3c142d8ff1f0674..d6ebbaebe2c258a4694cfb709809e13d24084231 100755 (executable)
--- a/t/t4150-am.sh
+++ b/t/t4150-am.sh
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