* [PATCH] git-am: teach git-am to apply a patch to an unborn branch
@ 2009-03-19 22:12 Nanako Shiraishi
2009-03-19 22:21 ` Junio C Hamano
2009-03-20 4:37 ` Jeff King
0 siblings, 2 replies; 5+ messages in thread
From: Nanako Shiraishi @ 2009-03-19 22:12 UTC (permalink / raw)
To: git
Signed-off-by: Nanako Shiraishi <nanako3@lavabit.com>
---
git-am.sh | 33 ++++++++++++++++++++++++++++-----
t/t4150-am.sh | 15 +++++++++++++++
2 files changed, 43 insertions(+), 5 deletions(-)
diff --git a/git-am.sh b/git-am.sh
index d339075..c21642b 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -36,6 +36,13 @@ cd_to_toplevel
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
@@ -290,16 +297,26 @@ else
: >"$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
+ if test -n "$HAS_HEAD"
+ then
+ files=$(git diff-index --cached --name-only HEAD --)
+ else
+ files=$(git ls-files)
+ fi || exit
if test "$files"
then
- : >"$dotest/dirtyindex"
+ test -n "$HAS_HEAD" && : >"$dotest/dirtyindex"
die "Dirty index: cannot apply patches (dirty: $files)"
fi
esac
@@ -541,7 +558,13 @@ do
fi
tree=$(git write-tree) &&
- parent=$(git rev-parse --verify HEAD) &&
+ if parent=$(git rev-parse --verify -q HEAD)
+ then
+ pparent="-p $parent"
+ else
+ echo >&2 "applying to an empty history"
+ parent= pparent=
+ fi &&
commit=$(
if test -n "$ignore_date"
then
@@ -552,7 +575,7 @@ do
GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
export GIT_COMMITTER_DATE
fi &&
- git commit-tree $tree -p $parent <"$dotest/final-commit"
+ git commit-tree $tree $pparent <"$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 5e65afa..b97d102 100755
--- a/t/t4150-am.sh
+++ b/t/t4150-am.sh
@@ -290,4 +290,19 @@ test_expect_success 'am --ignore-date' '
echo "$at" | grep "+0000"
'
+test_expect_success 'am in 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
--
1.6.2.1
--
Nanako Shiraishi
http://ivory.ap.teacup.com/nanako3/
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] git-am: teach git-am to apply a patch to an unborn branch
2009-03-19 22:12 [PATCH] git-am: teach git-am to apply a patch to an unborn branch Nanako Shiraishi
@ 2009-03-19 22:21 ` Junio C Hamano
2009-03-20 4:37 ` Jeff King
1 sibling, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2009-03-19 22:21 UTC (permalink / raw)
To: Nanako Shiraishi; +Cc: git
Nanako Shiraishi <nanako3@lavabit.com> writes:
> Signed-off-by: Nanako Shiraishi <nanako3@lavabit.com>
> ---
> git-am.sh | 33 ++++++++++++++++++++++++++++-----
> t/t4150-am.sh | 15 +++++++++++++++
> 2 files changed, 43 insertions(+), 5 deletions(-)
>
> diff --git a/git-am.sh b/git-am.sh
> index d339075..c21642b 100755
> --- a/git-am.sh
> +++ b/git-am.sh
> @@ -36,6 +36,13 @@ cd_to_toplevel
> 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
> +
Probably nicer this way than Peff's as I suspect we would need to special
case the unborn-branch case a lot more. Have you tried --skip and --abort
codepaths with your patch?
> sq () {
> for sqarg
> do
> @@ -290,16 +297,26 @@ else
> : >"$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
So is this part.
> fi
> fi
>
> case "$resolved" in
> '')
> - files=$(git diff-index --cached --name-only HEAD --) || exit
> + if test -n "$HAS_HEAD"
> + then
> + files=$(git diff-index --cached --name-only HEAD --)
> + else
> + files=$(git ls-files)
> + fi || exit
> if test "$files"
> then
> - : >"$dotest/dirtyindex"
> + test -n "$HAS_HEAD" && : >"$dotest/dirtyindex"
> die "Dirty index: cannot apply patches (dirty: $files)"
> fi
> esac
And here...
> @@ -541,7 +558,13 @@ do
> fi
>
> tree=$(git write-tree) &&
> - parent=$(git rev-parse --verify HEAD) &&
> + if parent=$(git rev-parse --verify -q HEAD)
> + then
> + pparent="-p $parent"
> + else
> + echo >&2 "applying to an empty history"
> + parent= pparent=
> + fi &&
> commit=$(
> if test -n "$ignore_date"
> then
> @@ -552,7 +575,7 @@ do
> GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
> export GIT_COMMITTER_DATE
> fi &&
> - git commit-tree $tree -p $parent <"$dotest/final-commit"
> + git commit-tree $tree $pparent <"$dotest/final-commit"
Peff's ${a+something $a} trick looks more "expert" here ;-).
> diff --git a/t/t4150-am.sh b/t/t4150-am.sh
> index 5e65afa..b97d102 100755
> --- a/t/t4150-am.sh
> +++ b/t/t4150-am.sh
> @@ -290,4 +290,19 @@ test_expect_success 'am --ignore-date' '
> echo "$at" | grep "+0000"
> '
>
> +test_expect_success 'am in 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})"
> +'
> +
Looks good.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] git-am: teach git-am to apply a patch to an unborn branch
2009-03-19 22:12 [PATCH] git-am: teach git-am to apply a patch to an unborn branch Nanako Shiraishi
2009-03-19 22:21 ` Junio C Hamano
@ 2009-03-20 4:37 ` Jeff King
1 sibling, 0 replies; 5+ messages in thread
From: Jeff King @ 2009-03-20 4:37 UTC (permalink / raw)
To: Nanako Shiraishi; +Cc: git
On Fri, Mar 20, 2009 at 07:12:31AM +0900, Nanako Shiraishi wrote:
> Signed-off-by: Nanako Shiraishi <nanako3@lavabit.com>
Thanks for picking up this topic. It looks sane overall.
> - parent=$(git rev-parse --verify HEAD) &&
> + if parent=$(git rev-parse --verify -q HEAD)
> + then
> + pparent="-p $parent"
> + else
> + echo >&2 "applying to an empty history"
> + parent= pparent=
> + fi &&
Note that the '&&' here is now pointless, since one side of the
conditional will always be true. We are losing the ability to detect
errors besides "HEAD does not point to a valid object", but I don't
think there is a way to tell the difference from the exit code of
rev-parse.
-Peff
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] git-am: teach git-am to apply a patch to an unborn branch
2009-04-10 0:34 Nanako Shiraishi
@ 2009-04-13 3:46 ` Junio C Hamano
0 siblings, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2009-04-13 3:46 UTC (permalink / raw)
To: Nanako Shiraishi; +Cc: git
Thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] git-am: teach git-am to apply a patch to an unborn branch
@ 2009-04-10 0:34 Nanako Shiraishi
2009-04-13 3:46 ` Junio C Hamano
0 siblings, 1 reply; 5+ messages in thread
From: Nanako Shiraishi @ 2009-04-10 0:34 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
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>
---
git-am.sh | 29 ++++++++++++++++++++++++-----
t/t4150-am.sh | 15 +++++++++++++++
2 files changed, 39 insertions(+), 5 deletions(-)
diff --git a/git-am.sh b/git-am.sh
index d339075..774383f 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -36,6 +36,13 @@ cd_to_toplevel
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
@@ -290,16 +297,26 @@ else
: >"$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
@@ -541,18 +558,20 @@ do
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 5e65afa..b97d102 100755
--- a/t/t4150-am.sh
+++ b/t/t4150-am.sh
@@ -290,4 +290,19 @@ test_expect_success 'am --ignore-date' '
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
--
1.6.2.2
--
Nanako Shiraishi
http://ivory.ap.teacup.com/nanako3/
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-04-13 3:48 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-19 22:12 [PATCH] git-am: teach git-am to apply a patch to an unborn branch Nanako Shiraishi
2009-03-19 22:21 ` Junio C Hamano
2009-03-20 4:37 ` Jeff King
2009-04-10 0:34 Nanako Shiraishi
2009-04-13 3:46 ` Junio C Hamano
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.