PageRenderTime 57ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/libexec/git-core/git-am

https://bitbucket.org/tgunr/usr
Shell | 777 lines | 656 code | 58 blank | 63 comment | 80 complexity | b8e3d7311c28901cc395e120bb392487 MD5 | raw file
Possible License(s): GPL-3.0, CC-BY-SA-3.0, Apache-2.0, BSD-3-Clause, AGPL-1.0, GPL-2.0
  1. #!/bin/sh
  2. #
  3. # Copyright (c) 2005, 2006 Junio C Hamano
  4. SUBDIRECTORY_OK=Yes
  5. OPTIONS_KEEPDASHDASH=
  6. OPTIONS_SPEC="\
  7. git am [options] [<mbox>|<Maildir>...]
  8. git am [options] (--resolved | --skip | --abort)
  9. --
  10. i,interactive run interactively
  11. b,binary* (historical option -- no-op)
  12. 3,3way allow fall back on 3way merging if needed
  13. q,quiet be quiet
  14. s,signoff add a Signed-off-by line to the commit message
  15. u,utf8 recode into utf8 (default)
  16. k,keep pass -k flag to git-mailinfo
  17. c,scissors strip everything before a scissors line
  18. whitespace= pass it through git-apply
  19. ignore-space-change pass it through git-apply
  20. ignore-whitespace pass it through git-apply
  21. directory= pass it through git-apply
  22. C= pass it through git-apply
  23. p= pass it through git-apply
  24. patch-format= format the patch(es) are in
  25. reject pass it through git-apply
  26. resolvemsg= override error message when patch failure occurs
  27. continue continue applying patches after resolving a conflict
  28. r,resolved synonyms for --continue
  29. skip skip the current patch
  30. abort restore the original branch and abort the patching operation.
  31. committer-date-is-author-date lie about committer date
  32. ignore-date use current timestamp for author date
  33. rerere-autoupdate update the index with reused conflict resolution if possible
  34. rebasing* (internal use for git-rebase)"
  35. . git-sh-setup
  36. prefix=$(git rev-parse --show-prefix)
  37. set_reflog_action am
  38. require_work_tree
  39. cd_to_toplevel
  40. git var GIT_COMMITTER_IDENT >/dev/null ||
  41. die "You need to set your committer info first"
  42. if git rev-parse --verify -q HEAD >/dev/null
  43. then
  44. HAS_HEAD=yes
  45. else
  46. HAS_HEAD=
  47. fi
  48. sq () {
  49. git rev-parse --sq-quote "$@"
  50. }
  51. stop_here () {
  52. echo "$1" >"$dotest/next"
  53. exit 1
  54. }
  55. stop_here_user_resolve () {
  56. if [ -n "$resolvemsg" ]; then
  57. printf '%s\n' "$resolvemsg"
  58. stop_here $1
  59. fi
  60. cmdline="git am"
  61. if test '' != "$interactive"
  62. then
  63. cmdline="$cmdline -i"
  64. fi
  65. if test '' != "$threeway"
  66. then
  67. cmdline="$cmdline -3"
  68. fi
  69. echo "When you have resolved this problem run \"$cmdline --resolved\"."
  70. echo "If you would prefer to skip this patch, instead run \"$cmdline --skip\"."
  71. echo "To restore the original branch and stop patching run \"$cmdline --abort\"."
  72. stop_here $1
  73. }
  74. go_next () {
  75. rm -f "$dotest/$msgnum" "$dotest/msg" "$dotest/msg-clean" \
  76. "$dotest/patch" "$dotest/info"
  77. echo "$next" >"$dotest/next"
  78. this=$next
  79. }
  80. cannot_fallback () {
  81. echo "$1"
  82. echo "Cannot fall back to three-way merge."
  83. exit 1
  84. }
  85. fall_back_3way () {
  86. O_OBJECT=`cd "$GIT_OBJECT_DIRECTORY" && pwd`
  87. rm -fr "$dotest"/patch-merge-*
  88. mkdir "$dotest/patch-merge-tmp-dir"
  89. # First see if the patch records the index info that we can use.
  90. git apply --build-fake-ancestor "$dotest/patch-merge-tmp-index" \
  91. "$dotest/patch" &&
  92. GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \
  93. git write-tree >"$dotest/patch-merge-base+" ||
  94. cannot_fallback "Repository lacks necessary blobs to fall back on 3-way merge."
  95. say Using index info to reconstruct a base tree...
  96. if GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \
  97. git apply --cached <"$dotest/patch"
  98. then
  99. mv "$dotest/patch-merge-base+" "$dotest/patch-merge-base"
  100. mv "$dotest/patch-merge-tmp-index" "$dotest/patch-merge-index"
  101. else
  102. cannot_fallback "Did you hand edit your patch?
  103. It does not apply to blobs recorded in its index."
  104. fi
  105. test -f "$dotest/patch-merge-index" &&
  106. his_tree=$(GIT_INDEX_FILE="$dotest/patch-merge-index" git write-tree) &&
  107. orig_tree=$(cat "$dotest/patch-merge-base") &&
  108. rm -fr "$dotest"/patch-merge-* || exit 1
  109. say Falling back to patching base and 3-way merge...
  110. # This is not so wrong. Depending on which base we picked,
  111. # orig_tree may be wildly different from ours, but his_tree
  112. # has the same set of wildly different changes in parts the
  113. # patch did not touch, so recursive ends up canceling them,
  114. # saying that we reverted all those changes.
  115. eval GITHEAD_$his_tree='"$FIRSTLINE"'
  116. export GITHEAD_$his_tree
  117. if test -n "$GIT_QUIET"
  118. then
  119. export GIT_MERGE_VERBOSITY=0
  120. fi
  121. git-merge-recursive $orig_tree -- HEAD $his_tree || {
  122. git rerere $allow_rerere_autoupdate
  123. echo Failed to merge in the changes.
  124. exit 1
  125. }
  126. unset GITHEAD_$his_tree
  127. }
  128. clean_abort () {
  129. test $# = 0 || echo >&2 "$@"
  130. rm -fr "$dotest"
  131. exit 1
  132. }
  133. patch_format=
  134. check_patch_format () {
  135. # early return if patch_format was set from the command line
  136. if test -n "$patch_format"
  137. then
  138. return 0
  139. fi
  140. # we default to mbox format if input is from stdin and for
  141. # directories
  142. if test $# = 0 || test "x$1" = "x-" || test -d "$1"
  143. then
  144. patch_format=mbox
  145. return 0
  146. fi
  147. # otherwise, check the first few lines of the first patch to try
  148. # to detect its format
  149. {
  150. read l1
  151. read l2
  152. read l3
  153. case "$l1" in
  154. "From "* | "From: "*)
  155. patch_format=mbox
  156. ;;
  157. '# This series applies on GIT commit'*)
  158. patch_format=stgit-series
  159. ;;
  160. "# HG changeset patch")
  161. patch_format=hg
  162. ;;
  163. *)
  164. # if the second line is empty and the third is
  165. # a From, Author or Date entry, this is very
  166. # likely an StGIT patch
  167. case "$l2,$l3" in
  168. ,"From: "* | ,"Author: "* | ,"Date: "*)
  169. patch_format=stgit
  170. ;;
  171. *)
  172. ;;
  173. esac
  174. ;;
  175. esac
  176. if test -z "$patch_format" &&
  177. test -n "$l1" &&
  178. test -n "$l2" &&
  179. test -n "$l3"
  180. then
  181. # This begins with three non-empty lines. Is this a
  182. # piece of e-mail a-la RFC2822? Grab all the headers,
  183. # discarding the indented remainder of folded lines,
  184. # and see if it looks like that they all begin with the
  185. # header field names...
  186. tr -d '\015' <"$1" |
  187. sed -n -e '/^$/q' -e '/^[ ]/d' -e p |
  188. sane_egrep -v '^[!-9;-~]+:' >/dev/null ||
  189. patch_format=mbox
  190. fi
  191. } < "$1" || clean_abort
  192. }
  193. split_patches () {
  194. case "$patch_format" in
  195. mbox)
  196. case "$rebasing" in
  197. '')
  198. keep_cr= ;;
  199. ?*)
  200. keep_cr=--keep-cr ;;
  201. esac
  202. git mailsplit -d"$prec" -o"$dotest" -b $keep_cr -- "$@" > "$dotest/last" ||
  203. clean_abort
  204. ;;
  205. stgit-series)
  206. if test $# -ne 1
  207. then
  208. clean_abort "Only one StGIT patch series can be applied at once"
  209. fi
  210. series_dir=`dirname "$1"`
  211. series_file="$1"
  212. shift
  213. {
  214. set x
  215. while read filename
  216. do
  217. set "$@" "$series_dir/$filename"
  218. done
  219. # remove the safety x
  220. shift
  221. # remove the arg coming from the first-line comment
  222. shift
  223. } < "$series_file" || clean_abort
  224. # set the patch format appropriately
  225. patch_format=stgit
  226. # now handle the actual StGIT patches
  227. split_patches "$@"
  228. ;;
  229. stgit)
  230. this=0
  231. for stgit in "$@"
  232. do
  233. this=`expr "$this" + 1`
  234. msgnum=`printf "%0${prec}d" $this`
  235. # Perl version of StGIT parse_patch. The first nonemptyline
  236. # not starting with Author, From or Date is the
  237. # subject, and the body starts with the next nonempty
  238. # line not starting with Author, From or Date
  239. perl -ne 'BEGIN { $subject = 0 }
  240. if ($subject > 1) { print ; }
  241. elsif (/^\s+$/) { next ; }
  242. elsif (/^Author:/) { print s/Author/From/ ; }
  243. elsif (/^(From|Date)/) { print ; }
  244. elsif ($subject) {
  245. $subject = 2 ;
  246. print "\n" ;
  247. print ;
  248. } else {
  249. print "Subject: ", $_ ;
  250. $subject = 1;
  251. }
  252. ' < "$stgit" > "$dotest/$msgnum" || clean_abort
  253. done
  254. echo "$this" > "$dotest/last"
  255. this=
  256. msgnum=
  257. ;;
  258. *)
  259. if test -n "$parse_patch" ; then
  260. clean_abort "Patch format $patch_format is not supported."
  261. else
  262. clean_abort "Patch format detection failed."
  263. fi
  264. ;;
  265. esac
  266. }
  267. prec=4
  268. dotest="$GIT_DIR/rebase-apply"
  269. sign= utf8=t keep= skip= interactive= resolved= rebasing= abort=
  270. resolvemsg= resume= scissors= no_inbody_headers=
  271. git_apply_opt=
  272. committer_date_is_author_date=
  273. ignore_date=
  274. allow_rerere_autoupdate=
  275. while test $# != 0
  276. do
  277. case "$1" in
  278. -i|--interactive)
  279. interactive=t ;;
  280. -b|--binary)
  281. : ;;
  282. -3|--3way)
  283. threeway=t ;;
  284. -s|--signoff)
  285. sign=t ;;
  286. -u|--utf8)
  287. utf8=t ;; # this is now default
  288. --no-utf8)
  289. utf8= ;;
  290. -k|--keep)
  291. keep=t ;;
  292. -c|--scissors)
  293. scissors=t ;;
  294. --no-scissors)
  295. scissors=f ;;
  296. -r|--resolved|--continue)
  297. resolved=t ;;
  298. --skip)
  299. skip=t ;;
  300. --abort)
  301. abort=t ;;
  302. --rebasing)
  303. rebasing=t threeway=t keep=t scissors=f no_inbody_headers=t ;;
  304. -d|--dotest)
  305. die "-d option is no longer supported. Do not use."
  306. ;;
  307. --resolvemsg)
  308. shift; resolvemsg=$1 ;;
  309. --whitespace|--directory)
  310. git_apply_opt="$git_apply_opt $(sq "$1=$2")"; shift ;;
  311. -C|-p)
  312. git_apply_opt="$git_apply_opt $(sq "$1$2")"; shift ;;
  313. --patch-format)
  314. shift ; patch_format="$1" ;;
  315. --reject|--ignore-whitespace|--ignore-space-change)
  316. git_apply_opt="$git_apply_opt $1" ;;
  317. --committer-date-is-author-date)
  318. committer_date_is_author_date=t ;;
  319. --ignore-date)
  320. ignore_date=t ;;
  321. --rerere-autoupdate|--no-rerere-autoupdate)
  322. allow_rerere_autoupdate="$1" ;;
  323. -q|--quiet)
  324. GIT_QUIET=t ;;
  325. --)
  326. shift; break ;;
  327. *)
  328. usage ;;
  329. esac
  330. shift
  331. done
  332. # If the dotest directory exists, but we have finished applying all the
  333. # patches in them, clear it out.
  334. if test -d "$dotest" &&
  335. last=$(cat "$dotest/last") &&
  336. next=$(cat "$dotest/next") &&
  337. test $# != 0 &&
  338. test "$next" -gt "$last"
  339. then
  340. rm -fr "$dotest"
  341. fi
  342. if test -d "$dotest"
  343. then
  344. case "$#,$skip$resolved$abort" in
  345. 0,*t*)
  346. # Explicit resume command and we do not have file, so
  347. # we are happy.
  348. : ;;
  349. 0,)
  350. # No file input but without resume parameters; catch
  351. # user error to feed us a patch from standard input
  352. # when there is already $dotest. This is somewhat
  353. # unreliable -- stdin could be /dev/null for example
  354. # and the caller did not intend to feed us a patch but
  355. # wanted to continue unattended.
  356. test -t 0
  357. ;;
  358. *)
  359. false
  360. ;;
  361. esac ||
  362. die "previous rebase directory $dotest still exists but mbox given."
  363. resume=yes
  364. case "$skip,$abort" in
  365. t,t)
  366. die "Please make up your mind. --skip or --abort?"
  367. ;;
  368. t,)
  369. git rerere clear
  370. git read-tree --reset -u HEAD HEAD
  371. orig_head=$(cat "$GIT_DIR/ORIG_HEAD")
  372. git reset HEAD
  373. git update-ref ORIG_HEAD $orig_head
  374. ;;
  375. ,t)
  376. if test -f "$dotest/rebasing"
  377. then
  378. exec git rebase --abort
  379. fi
  380. git rerere clear
  381. test -f "$dotest/dirtyindex" || {
  382. git read-tree --reset -u HEAD ORIG_HEAD
  383. git reset ORIG_HEAD
  384. }
  385. rm -fr "$dotest"
  386. exit ;;
  387. esac
  388. rm -f "$dotest/dirtyindex"
  389. else
  390. # Make sure we are not given --skip, --resolved, nor --abort
  391. test "$skip$resolved$abort" = "" ||
  392. die "Resolve operation not in progress, we are not resuming."
  393. # Start afresh.
  394. mkdir -p "$dotest" || exit
  395. if test -n "$prefix" && test $# != 0
  396. then
  397. first=t
  398. for arg
  399. do
  400. test -n "$first" && {
  401. set x
  402. first=
  403. }
  404. case "$arg" in
  405. /*)
  406. set "$@" "$arg" ;;
  407. *)
  408. set "$@" "$prefix$arg" ;;
  409. esac
  410. done
  411. shift
  412. fi
  413. check_patch_format "$@"
  414. split_patches "$@"
  415. # -i can and must be given when resuming; everything
  416. # else is kept
  417. echo " $git_apply_opt" >"$dotest/apply-opt"
  418. echo "$threeway" >"$dotest/threeway"
  419. echo "$sign" >"$dotest/sign"
  420. echo "$utf8" >"$dotest/utf8"
  421. echo "$keep" >"$dotest/keep"
  422. echo "$scissors" >"$dotest/scissors"
  423. echo "$no_inbody_headers" >"$dotest/no_inbody_headers"
  424. echo "$GIT_QUIET" >"$dotest/quiet"
  425. echo 1 >"$dotest/next"
  426. if test -n "$rebasing"
  427. then
  428. : >"$dotest/rebasing"
  429. else
  430. : >"$dotest/applying"
  431. if test -n "$HAS_HEAD"
  432. then
  433. git update-ref ORIG_HEAD HEAD
  434. else
  435. git update-ref -d ORIG_HEAD >/dev/null 2>&1
  436. fi
  437. fi
  438. fi
  439. case "$resolved" in
  440. '')
  441. case "$HAS_HEAD" in
  442. '')
  443. files=$(git ls-files) ;;
  444. ?*)
  445. files=$(git diff-index --cached --name-only HEAD --) ;;
  446. esac || exit
  447. if test "$files"
  448. then
  449. test -n "$HAS_HEAD" && : >"$dotest/dirtyindex"
  450. die "Dirty index: cannot apply patches (dirty: $files)"
  451. fi
  452. esac
  453. if test "$(cat "$dotest/utf8")" = t
  454. then
  455. utf8=-u
  456. else
  457. utf8=-n
  458. fi
  459. if test "$(cat "$dotest/keep")" = t
  460. then
  461. keep=-k
  462. fi
  463. case "$(cat "$dotest/scissors")" in
  464. t)
  465. scissors=--scissors ;;
  466. f)
  467. scissors=--no-scissors ;;
  468. esac
  469. if test "$(cat "$dotest/no_inbody_headers")" = t
  470. then
  471. no_inbody_headers=--no-inbody-headers
  472. else
  473. no_inbody_headers=
  474. fi
  475. if test "$(cat "$dotest/quiet")" = t
  476. then
  477. GIT_QUIET=t
  478. fi
  479. if test "$(cat "$dotest/threeway")" = t
  480. then
  481. threeway=t
  482. fi
  483. git_apply_opt=$(cat "$dotest/apply-opt")
  484. if test "$(cat "$dotest/sign")" = t
  485. then
  486. SIGNOFF=`git var GIT_COMMITTER_IDENT | sed -e '
  487. s/>.*/>/
  488. s/^/Signed-off-by: /'
  489. `
  490. else
  491. SIGNOFF=
  492. fi
  493. last=`cat "$dotest/last"`
  494. this=`cat "$dotest/next"`
  495. if test "$skip" = t
  496. then
  497. this=`expr "$this" + 1`
  498. resume=
  499. fi
  500. if test "$this" -gt "$last"
  501. then
  502. say Nothing to do.
  503. rm -fr "$dotest"
  504. exit
  505. fi
  506. while test "$this" -le "$last"
  507. do
  508. msgnum=`printf "%0${prec}d" $this`
  509. next=`expr "$this" + 1`
  510. test -f "$dotest/$msgnum" || {
  511. resume=
  512. go_next
  513. continue
  514. }
  515. # If we are not resuming, parse and extract the patch information
  516. # into separate files:
  517. # - info records the authorship and title
  518. # - msg is the rest of commit log message
  519. # - patch is the patch body.
  520. #
  521. # When we are resuming, these files are either already prepared
  522. # by the user, or the user can tell us to do so by --resolved flag.
  523. case "$resume" in
  524. '')
  525. git mailinfo $keep $no_inbody_headers $scissors $utf8 "$dotest/msg" "$dotest/patch" \
  526. <"$dotest/$msgnum" >"$dotest/info" ||
  527. stop_here $this
  528. # skip pine's internal folder data
  529. sane_grep '^Author: Mail System Internal Data$' \
  530. <"$dotest"/info >/dev/null &&
  531. go_next && continue
  532. test -s "$dotest/patch" || {
  533. echo "Patch is empty. Was it split wrong?"
  534. stop_here $this
  535. }
  536. if test -f "$dotest/rebasing" &&
  537. commit=$(sed -e 's/^From \([0-9a-f]*\) .*/\1/' \
  538. -e q "$dotest/$msgnum") &&
  539. test "$(git cat-file -t "$commit")" = commit
  540. then
  541. git cat-file commit "$commit" |
  542. sed -e '1,/^$/d' >"$dotest/msg-clean"
  543. else
  544. {
  545. sed -n '/^Subject/ s/Subject: //p' "$dotest/info"
  546. echo
  547. cat "$dotest/msg"
  548. } |
  549. git stripspace > "$dotest/msg-clean"
  550. fi
  551. ;;
  552. esac
  553. GIT_AUTHOR_NAME="$(sed -n '/^Author/ s/Author: //p' "$dotest/info")"
  554. GIT_AUTHOR_EMAIL="$(sed -n '/^Email/ s/Email: //p' "$dotest/info")"
  555. GIT_AUTHOR_DATE="$(sed -n '/^Date/ s/Date: //p' "$dotest/info")"
  556. if test -z "$GIT_AUTHOR_EMAIL"
  557. then
  558. echo "Patch does not have a valid e-mail address."
  559. stop_here $this
  560. fi
  561. export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE
  562. case "$resume" in
  563. '')
  564. if test '' != "$SIGNOFF"
  565. then
  566. LAST_SIGNED_OFF_BY=`
  567. sed -ne '/^Signed-off-by: /p' \
  568. "$dotest/msg-clean" |
  569. sed -ne '$p'
  570. `
  571. ADD_SIGNOFF=`
  572. test "$LAST_SIGNED_OFF_BY" = "$SIGNOFF" || {
  573. test '' = "$LAST_SIGNED_OFF_BY" && echo
  574. echo "$SIGNOFF"
  575. }`
  576. else
  577. ADD_SIGNOFF=
  578. fi
  579. {
  580. if test -s "$dotest/msg-clean"
  581. then
  582. cat "$dotest/msg-clean"
  583. fi
  584. if test '' != "$ADD_SIGNOFF"
  585. then
  586. echo "$ADD_SIGNOFF"
  587. fi
  588. } >"$dotest/final-commit"
  589. ;;
  590. *)
  591. case "$resolved$interactive" in
  592. tt)
  593. # This is used only for interactive view option.
  594. git diff-index -p --cached HEAD -- >"$dotest/patch"
  595. ;;
  596. esac
  597. esac
  598. resume=
  599. if test "$interactive" = t
  600. then
  601. test -t 0 ||
  602. die "cannot be interactive without stdin connected to a terminal."
  603. action=again
  604. while test "$action" = again
  605. do
  606. echo "Commit Body is:"
  607. echo "--------------------------"
  608. cat "$dotest/final-commit"
  609. echo "--------------------------"
  610. printf "Apply? [y]es/[n]o/[e]dit/[v]iew patch/[a]ccept all "
  611. read reply
  612. case "$reply" in
  613. [yY]*) action=yes ;;
  614. [aA]*) action=yes interactive= ;;
  615. [nN]*) action=skip ;;
  616. [eE]*) git_editor "$dotest/final-commit"
  617. action=again ;;
  618. [vV]*) action=again
  619. git_pager "$dotest/patch" ;;
  620. *) action=again ;;
  621. esac
  622. done
  623. else
  624. action=yes
  625. fi
  626. FIRSTLINE=$(sed 1q "$dotest/final-commit")
  627. if test $action = skip
  628. then
  629. go_next
  630. continue
  631. fi
  632. if test -x "$GIT_DIR"/hooks/applypatch-msg
  633. then
  634. "$GIT_DIR"/hooks/applypatch-msg "$dotest/final-commit" ||
  635. stop_here $this
  636. fi
  637. say "Applying: $FIRSTLINE"
  638. case "$resolved" in
  639. '')
  640. # When we are allowed to fall back to 3-way later, don't give
  641. # false errors during the initial attempt.
  642. squelch=
  643. if test "$threeway" = t
  644. then
  645. squelch='>/dev/null 2>&1 '
  646. fi
  647. eval "git apply $squelch$git_apply_opt"' --index "$dotest/patch"'
  648. apply_status=$?
  649. ;;
  650. t)
  651. # Resolved means the user did all the hard work, and
  652. # we do not have to do any patch application. Just
  653. # trust what the user has in the index file and the
  654. # working tree.
  655. resolved=
  656. git diff-index --quiet --cached HEAD -- && {
  657. echo "No changes - did you forget to use 'git add'?"
  658. stop_here_user_resolve $this
  659. }
  660. unmerged=$(git ls-files -u)
  661. if test -n "$unmerged"
  662. then
  663. echo "You still have unmerged paths in your index"
  664. echo "did you forget to use 'git add'?"
  665. stop_here_user_resolve $this
  666. fi
  667. apply_status=0
  668. git rerere
  669. ;;
  670. esac
  671. if test $apply_status = 1 && test "$threeway" = t
  672. then
  673. if (fall_back_3way)
  674. then
  675. # Applying the patch to an earlier tree and merging the
  676. # result may have produced the same tree as ours.
  677. git diff-index --quiet --cached HEAD -- && {
  678. say No changes -- Patch already applied.
  679. go_next
  680. continue
  681. }
  682. # clear apply_status -- we have successfully merged.
  683. apply_status=0
  684. fi
  685. fi
  686. if test $apply_status != 0
  687. then
  688. printf 'Patch failed at %s %s\n' "$msgnum" "$FIRSTLINE"
  689. stop_here_user_resolve $this
  690. fi
  691. if test -x "$GIT_DIR"/hooks/pre-applypatch
  692. then
  693. "$GIT_DIR"/hooks/pre-applypatch || stop_here $this
  694. fi
  695. tree=$(git write-tree) &&
  696. commit=$(
  697. if test -n "$ignore_date"
  698. then
  699. GIT_AUTHOR_DATE=
  700. fi
  701. parent=$(git rev-parse --verify -q HEAD) ||
  702. say >&2 "applying to an empty history"
  703. if test -n "$committer_date_is_author_date"
  704. then
  705. GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
  706. export GIT_COMMITTER_DATE
  707. fi &&
  708. git commit-tree $tree ${parent:+-p} $parent <"$dotest/final-commit"
  709. ) &&
  710. git update-ref -m "$GIT_REFLOG_ACTION: $FIRSTLINE" HEAD $commit $parent ||
  711. stop_here $this
  712. if test -x "$GIT_DIR"/hooks/post-applypatch
  713. then
  714. "$GIT_DIR"/hooks/post-applypatch
  715. fi
  716. go_next
  717. done
  718. rm -fr "$dotest"
  719. git gc --auto