~ubuntu-branches/ubuntu/intrepid/git-core/intrepid-updates

« back to all changes in this revision

Viewing changes to git-am.sh

  • Committer: Package Import Robot
  • Author(s): Gerrit Pape
  • Date: 2007-04-22 13:31:05 UTC
  • mto: This revision was merged to the branch mainline in revision 20.
  • Revision ID: package-import@ubuntu.com-20070422133105-xg8fnm18r2cxcbg1
Tags: upstream-1.5.1.2
ImportĀ upstreamĀ versionĀ 1.5.1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#
3
3
# Copyright (c) 2005, 2006 Junio C Hamano
4
4
 
5
 
USAGE='[--signoff] [--dotest=<dir>] [--utf8] [--binary] [--3way]
6
 
  [--interactive] [--whitespace=<option>] <mbox>...
 
5
USAGE='[--signoff] [--dotest=<dir>] [--utf8 | --no-utf8] [--binary] [--3way]
 
6
  [--interactive] [--whitespace=<option>] [-C<n>] [-p<n>] <mbox>...
7
7
  or, when resuming [--skip | --resolved]'
8
8
. git-sh-setup
 
9
set_reflog_action am
 
10
require_work_tree
9
11
 
10
12
git var GIT_COMMITTER_IDENT >/dev/null || exit
11
13
 
64
66
    git-update-index -z --index-info <"$dotest/patch-merge-index-info" &&
65
67
    GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \
66
68
    git-write-tree >"$dotest/patch-merge-base+" ||
67
 
    cannot_fallback "Patch does not record usable index information."
 
69
    cannot_fallback "Repository lacks necessary blobs to fall back on 3-way merge."
68
70
 
69
71
    echo Using index info to reconstruct a base tree...
70
72
    if GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \
87
89
    # This is not so wrong.  Depending on which base we picked,
88
90
    # orig_tree may be wildly different from ours, but his_tree
89
91
    # has the same set of wildly different changes in parts the
90
 
    # patch did not touch, so resolve ends up canceling them,
 
92
    # patch did not touch, so recursive ends up canceling them,
91
93
    # saying that we reverted all those changes.
92
94
 
93
 
    git-merge-resolve $orig_tree -- HEAD $his_tree || {
 
95
    eval GITHEAD_$his_tree='"$SUBJECT"'
 
96
    export GITHEAD_$his_tree
 
97
    git-merge-recursive $orig_tree -- HEAD $his_tree || {
94
98
            if test -d "$GIT_DIR/rr-cache"
95
99
            then
96
100
                git-rerere
98
102
            echo Failed to merge in the changes.
99
103
            exit 1
100
104
    }
 
105
    unset GITHEAD_$his_tree
101
106
}
102
107
 
103
108
prec=4
104
 
rloga=am
105
 
dotest=.dotest sign= utf8= keep= skip= interactive= resolved= binary= ws= resolvemsg=
 
109
dotest=.dotest sign= utf8=t keep= skip= interactive= resolved= binary= resolvemsg=
 
110
git_apply_opt=
106
111
 
107
112
while case "$#" in 0) break;; esac
108
113
do
125
130
        -s|--s|--si|--sig|--sign|--signo|--signof|--signoff)
126
131
        sign=t; shift ;;
127
132
        -u|--u|--ut|--utf|--utf8)
128
 
        utf8=t; shift ;;
 
133
        utf8=t; shift ;; # this is now default
 
134
        --no-u|--no-ut|--no-utf|--no-utf8)
 
135
        utf8=; shift ;;
129
136
        -k|--k|--ke|--kee|--keep)
130
137
        keep=t; shift ;;
131
138
 
135
142
        --sk|--ski|--skip)
136
143
        skip=t; shift ;;
137
144
 
138
 
        --whitespace=*)
139
 
        ws=$1; shift ;;
 
145
        --whitespace=*|-C*|-p*)
 
146
        git_apply_opt="$git_apply_opt $1"; shift ;;
140
147
 
141
148
        --resolvemsg=*)
142
149
        resolvemsg=$(echo "$1" | sed -e "s/^--resolvemsg=//"); shift ;;
143
150
 
144
 
        --reflog-action=*)
145
 
        rloga=`expr "z$1" : 'z-[^=]*=\(.*\)'`; shift ;;
146
 
 
147
151
        --)
148
152
        shift; break ;;
149
153
        -*)
226
230
if test "$(cat "$dotest/utf8")" = t
227
231
then
228
232
        utf8=-u
 
233
else
 
234
        utf8=-n
229
235
fi
230
236
if test "$(cat "$dotest/keep")" = t
231
237
then
246
252
this=`cat "$dotest/next"`
247
253
if test "$skip" = t
248
254
then
 
255
        if test -d "$GIT_DIR/rr-cache"
 
256
        then
 
257
                git-rerere clear
 
258
        fi
249
259
        this=`expr "$this" + 1`
250
260
        resume=
251
261
fi
280
290
                git-mailinfo $keep $utf8 "$dotest/msg" "$dotest/patch" \
281
291
                        <"$dotest/$msgnum" >"$dotest/info" ||
282
292
                        stop_here $this
 
293
                test -s $dotest/patch || {
 
294
                        echo "Patch is empty.  Was is split wrong?"
 
295
                        stop_here $this
 
296
                }
283
297
                git-stripspace < "$dotest/msg" > "$dotest/msg-clean"
284
298
                ;;
285
299
        esac
385
399
 
386
400
        case "$resolved" in
387
401
        '')
388
 
                git-apply $binary --index $ws "$dotest/patch"
 
402
                git-apply $git_apply_opt $binary --index "$dotest/patch"
389
403
                apply_status=$?
390
404
                ;;
391
405
        t)
394
408
                # trust what the user has in the index file and the
395
409
                # working tree.
396
410
                resolved=
397
 
                changed="$(git-diff-index --cached --name-only HEAD)"
398
 
                if test '' = "$changed"
399
 
                then
400
 
                        echo "No changes - did you forget update-index?"
 
411
                git-diff-index --quiet --cached HEAD && {
 
412
                        echo "No changes - did you forget to use 'git add'?"
401
413
                        stop_here_user_resolve $this
402
 
                fi
 
414
                }
403
415
                unmerged=$(git-ls-files -u)
404
416
                if test -n "$unmerged"
405
417
                then
406
418
                        echo "You still have unmerged paths in your index"
407
 
                        echo "did you forget update-index?"
 
419
                        echo "did you forget to use 'git add'?"
408
420
                        stop_here_user_resolve $this
409
421
                fi
410
422
                apply_status=0
 
423
                if test -d "$GIT_DIR/rr-cache"
 
424
                then
 
425
                        git rerere
 
426
                fi
411
427
                ;;
412
428
        esac
413
429
 
417
433
                then
418
434
                    # Applying the patch to an earlier tree and merging the
419
435
                    # result may have produced the same tree as ours.
420
 
                    changed="$(git-diff-index --cached --name-only HEAD)"
421
 
                    if test '' = "$changed"
422
 
                    then
423
 
                            echo No changes -- Patch already applied.
424
 
                            go_next
425
 
                            continue
426
 
                    fi
 
436
                    git-diff-index --quiet --cached HEAD && {
 
437
                        echo No changes -- Patch already applied.
 
438
                        go_next
 
439
                        continue
 
440
                    }
427
441
                    # clear apply_status -- we have successfully merged.
428
442
                    apply_status=0
429
443
                fi
444
458
        parent=$(git-rev-parse --verify HEAD) &&
445
459
        commit=$(git-commit-tree $tree -p $parent <"$dotest/final-commit") &&
446
460
        echo Committed: $commit &&
447
 
        git-update-ref -m "$rloga: $SUBJECT" HEAD $commit $parent ||
 
461
        git-update-ref -m "$GIT_REFLOG_ACTION: $SUBJECT" HEAD $commit $parent ||
448
462
        stop_here $this
449
463
 
450
464
        if test -x "$GIT_DIR"/hooks/post-applypatch