Remove contrib/examples/*
There were some side discussions at Git Merge this year about how we should just update the README to tell users they can dig these up from the history if the need them, do that. Looking at the "git log" for this directory we get quite a bit more patch churn than we should here, mainly from things fixing various tree-wide issues. There's also confusion on the list occasionally about how these should be treated, "Re: [PATCH 1/4] stash: convert apply to builtin" (<CA+CzEk9QpmHK_TSBwQfEedNqrcVSBp3xY7bdv1YA_KxePiFeXw@mail.gmail.com>) being the latest example of that. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
Mar 25, 2018 at 20:46 UTC
49eb8d39c78f161231e63293df60f343d208f409
27 files changed
+20
-8137
contrib/examples/README
+20
-3
@@ -1,3 +1,20 @@
1
-These are original scripted implementations, kept primarily for their
2
-reference value to any aspiring plumbing users who want to learn how
3
-pieces can be fit together.
1
+This directory used to contain scripted implementations of builtins
2
+that have since been rewritten in C.
3
+
4
+They have now been removed, but can be retrieved from an older commit
5
+that removed them from this directory.
6
+
7
+They're interesting for their reference value to any aspiring plumbing
8
+users who want to learn how pieces can be fit together, but in many
9
+cases have drifted enough from the actual implementations Git uses to
10
+be instructive.
11
+
12
+Other things that can be useful:
13
+
14
+ * Some commands such as git-gc wrap other commands, and what they're
15
+ doing behind the scenes can be seen by running them under
16
+ GIT_TRACE=1
17
+
18
+ * Doing `git log` on paths matching '*--helper.c' will show
19
+ incremental effort in the direction of moving existing shell
20
+ scripts to C.
contrib/examples/builtin-fetch--tool.c
deleted
-575
@@ -1,575 +0,0 @@
1
-#include "builtin.h"
2
-#include "cache.h"
3
-#include "refs.h"
4
-#include "commit.h"
5
-#include "sigchain.h"
6
-
7
-static char *get_stdin(void)
8
-{
9
- struct strbuf buf = STRBUF_INIT;
10
- if (strbuf_read(&buf, 0, 1024) < 0) {
11
- die_errno("error reading standard input");
12
- }
13
- return strbuf_detach(&buf, NULL);
14
-}
15
-
16
-static void show_new(enum object_type type, unsigned char *sha1_new)
17
-{
18
- fprintf(stderr, " %s: %s\n", type_name(type),
19
- find_unique_abbrev(sha1_new, DEFAULT_ABBREV));
20
-}
21
-
22
-static int update_ref_env(const char *action,
23
- const char *refname,
24
- unsigned char *sha1,
25
- unsigned char *oldval)
26
-{
27
- char msg[1024];
28
- const char *rla = getenv("GIT_REFLOG_ACTION");
29
-
30
- if (!rla)
31
- rla = "(reflog update)";
32
- if (snprintf(msg, sizeof(msg), "%s: %s", rla, action) >= sizeof(msg))
33
- warning("reflog message too long: %.*s...", 50, msg);
34
- return update_ref(msg, refname, sha1, oldval, 0,
35
- UPDATE_REFS_QUIET_ON_ERR);
36
-}
37
-
38
-static int update_local_ref(const char *name,
39
- const char *new_head,
40
- const char *note,
41
- int verbose, int force)
42
-{
43
- unsigned char sha1_old[20], sha1_new[20];
44
- char oldh[41], newh[41];
45
- struct commit *current, *updated;
46
- enum object_type type;
47
-
48
- if (get_sha1_hex(new_head, sha1_new))
49
- die("malformed object name %s", new_head);
50
-
51
- type = sha1_object_info(sha1_new, NULL);
52
- if (type < 0)
53
- die("object %s not found", new_head);
54
-
55
- if (!*name) {
56
- /* Not storing */
57
- if (verbose) {
58
- fprintf(stderr, "* fetched %s\n", note);
59
- show_new(type, sha1_new);
60
- }
61
- return 0;
62
- }
63
-
64
- if (get_sha1(name, sha1_old)) {
65
- const char *msg;
66
- just_store:
67
- /* new ref */
68
- if (!strncmp(name, "refs/tags/", 10))
69
- msg = "storing tag";
70
- else
71
- msg = "storing head";
72
- fprintf(stderr, "* %s: storing %s\n",
73
- name, note);
74
- show_new(type, sha1_new);
75
- return update_ref_env(msg, name, sha1_new, NULL);
76
- }
77
-
78
- if (!hashcmp(sha1_old, sha1_new)) {
79
- if (verbose) {
80
- fprintf(stderr, "* %s: same as %s\n", name, note);
81
- show_new(type, sha1_new);
82
- }
83
- return 0;
84
- }
85
-
86
- if (!strncmp(name, "refs/tags/", 10)) {
87
- fprintf(stderr, "* %s: updating with %s\n", name, note);
88
- show_new(type, sha1_new);
89
- return update_ref_env("updating tag", name, sha1_new, NULL);
90
- }
91
-
92
- current = lookup_commit_reference(sha1_old);
93
- updated = lookup_commit_reference(sha1_new);
94
- if (!current || !updated)
95
- goto just_store;
96
-
97
- strcpy(oldh, find_unique_abbrev(current->object.sha1, DEFAULT_ABBREV));
98
- strcpy(newh, find_unique_abbrev(sha1_new, DEFAULT_ABBREV));
99
-
100
- if (in_merge_bases(current, updated)) {
101
- fprintf(stderr, "* %s: fast-forward to %s\n",
102
- name, note);
103
- fprintf(stderr, " old..new: %s..%s\n", oldh, newh);
104
- return update_ref_env("fast-forward", name, sha1_new, sha1_old);
105
- }
106
- if (!force) {
107
- fprintf(stderr,
108
- "* %s: not updating to non-fast-forward %s\n",
109
- name, note);
110
- fprintf(stderr,
111
- " old...new: %s...%s\n", oldh, newh);
112
- return 1;
113
- }
114
- fprintf(stderr,
115
- "* %s: forcing update to non-fast-forward %s\n",
116
- name, note);
117
- fprintf(stderr, " old...new: %s...%s\n", oldh, newh);
118
- return update_ref_env("forced-update", name, sha1_new, sha1_old);
119
-}
120
-
121
-static int append_fetch_head(FILE *fp,
122
- const char *head, const char *remote,
123
- const char *remote_name, const char *remote_nick,
124
- const char *local_name, int not_for_merge,
125
- int verbose, int force)
126
-{
127
- struct commit *commit;
128
- int remote_len, i, note_len;
129
- unsigned char sha1[20];
130
- char note[1024];
131
- const char *what, *kind;
132
-
133
- if (get_sha1(head, sha1))
134
- return error("Not a valid object name: %s", head);
135
- commit = lookup_commit_reference_gently(sha1, 1);
136
- if (!commit)
137
- not_for_merge = 1;
138
-
139
- if (!strcmp(remote_name, "HEAD")) {
140
- kind = "";
141
- what = "";
142
- }
143
- else if (!strncmp(remote_name, "refs/heads/", 11)) {
144
- kind = "branch";
145
- what = remote_name + 11;
146
- }
147
- else if (!strncmp(remote_name, "refs/tags/", 10)) {
148
- kind = "tag";
149
- what = remote_name + 10;
150
- }
151
- else if (!strncmp(remote_name, "refs/remotes/", 13)) {
152
- kind = "remote-tracking branch";
153
- what = remote_name + 13;
154
- }
155
- else {
156
- kind = "";
157
- what = remote_name;
158
- }
159
-
160
- remote_len = strlen(remote);
161
- for (i = remote_len - 1; remote[i] == '/' && 0 <= i; i--)
162
- ;
163
- remote_len = i + 1;
164
- if (4 < i && !strncmp(".git", remote + i - 3, 4))
165
- remote_len = i - 3;
166
-
167
- note_len = 0;
168
- if (*what) {
169
- if (*kind)
170
- note_len += sprintf(note + note_len, "%s ", kind);
171
- note_len += sprintf(note + note_len, "'%s' of ", what);
172
- }
173
- note_len += sprintf(note + note_len, "%.*s", remote_len, remote);
174
- fprintf(fp, "%s\t%s\t%s\n",
175
- sha1_to_hex(commit ? commit->object.sha1 : sha1),
176
- not_for_merge ? "not-for-merge" : "",
177
- note);
178
- return update_local_ref(local_name, head, note, verbose, force);
179
-}
180
-
181
-static char *keep;
182
-static void remove_keep(void)
183
-{
184
- if (keep && *keep)
185
- unlink(keep);
186
-}
187
-
188
-static void remove_keep_on_signal(int signo)
189
-{
190
- remove_keep();
191
- sigchain_pop(signo);
192
- raise(signo);
193
-}
194
-
195
-static char *find_local_name(const char *remote_name, const char *refs,
196
- int *force_p, int *not_for_merge_p)
197
-{
198
- const char *ref = refs;
199
- int len = strlen(remote_name);
200
-
201
- while (ref) {
202
- const char *next;
203
- int single_force, not_for_merge;
204
-
205
- while (*ref == '\n')
206
- ref++;
207
- if (!*ref)
208
- break;
209
- next = strchr(ref, '\n');
210
-
211
- single_force = not_for_merge = 0;
212
- if (*ref == '+') {
213
- single_force = 1;
214
- ref++;
215
- }
216
- if (*ref == '.') {
217
- not_for_merge = 1;
218
- ref++;
219
- if (*ref == '+') {
220
- single_force = 1;
221
- ref++;
222
- }
223
- }
224
- if (!strncmp(remote_name, ref, len) && ref[len] == ':') {
225
- const char *local_part = ref + len + 1;
226
- int retlen;
227
-
228
- if (!next)
229
- retlen = strlen(local_part);
230
- else
231
- retlen = next - local_part;
232
- *force_p = single_force;
233
- *not_for_merge_p = not_for_merge;
234
- return xmemdupz(local_part, retlen);
235
- }
236
- ref = next;
237
- }
238
- return NULL;
239
-}
240
-
241
-static int fetch_native_store(FILE *fp,
242
- const char *remote,
243
- const char *remote_nick,
244
- const char *refs,
245
- int verbose, int force)
246
-{
247
- char buffer[1024];
248
- int err = 0;
249
-
250
- sigchain_push_common(remove_keep_on_signal);
251
- atexit(remove_keep);
252
-
253
- while (fgets(buffer, sizeof(buffer), stdin)) {
254
- int len;
255
- char *cp;
256
- char *local_name;
257
- int single_force, not_for_merge;
258
-
259
- for (cp = buffer; *cp && !isspace(*cp); cp++)
260
- ;
261
- if (*cp)
262
- *cp++ = 0;
263
- len = strlen(cp);
264
- if (len && cp[len-1] == '\n')
265
- cp[--len] = 0;
266
- if (!strcmp(buffer, "failed"))
267
- die("Fetch failure: %s", remote);
268
- if (!strcmp(buffer, "pack"))
269
- continue;
270
- if (!strcmp(buffer, "keep")) {
271
- char *od = get_object_directory();
272
- int len = strlen(od) + strlen(cp) + 50;
273
- keep = xmalloc(len);
274
- sprintf(keep, "%s/pack/pack-%s.keep", od, cp);
275
- continue;
276
- }
277
-
278
- local_name = find_local_name(cp, refs,
279
- &single_force, ¬_for_merge);
280
- if (!local_name)
281
- continue;
282
- err |= append_fetch_head(fp,
283
- buffer, remote, cp, remote_nick,
284
- local_name, not_for_merge,
285
- verbose, force || single_force);
286
- }
287
- return err;
288
-}
289
-
290
-static int parse_reflist(const char *reflist)
291
-{
292
- const char *ref;
293
-
294
- printf("refs='");
295
- for (ref = reflist; ref; ) {
296
- const char *next;
297
- while (*ref && isspace(*ref))
298
- ref++;
299
- if (!*ref)
300
- break;
301
- for (next = ref; *next && !isspace(*next); next++)
302
- ;
303
- printf("\n%.*s", (int)(next - ref), ref);
304
- ref = next;
305
- }
306
- printf("'\n");
307
-
308
- printf("rref='");
309
- for (ref = reflist; ref; ) {
310
- const char *next, *colon;
311
- while (*ref && isspace(*ref))
312
- ref++;
313
- if (!*ref)
314
- break;
315
- for (next = ref; *next && !isspace(*next); next++)
316
- ;
317
- if (*ref == '.')
318
- ref++;
319
- if (*ref == '+')
320
- ref++;
321
- colon = strchr(ref, ':');
322
- putchar('\n');
323
- printf("%.*s", (int)((colon ? colon : next) - ref), ref);
324
- ref = next;
325
- }
326
- printf("'\n");
327
- return 0;
328
-}
329
-
330
-static int expand_refs_wildcard(const char *ls_remote_result, int numrefs,
331
- const char **refs)
332
-{
333
- int i, matchlen, replacelen;
334
- int found_one = 0;
335
- const char *remote = *refs++;
336
- numrefs--;
337
-
338
- if (numrefs == 0) {
339
- fprintf(stderr, "Nothing specified for fetching with remote.%s.fetch\n",
340
- remote);
341
- printf("empty\n");
342
- }
343
-
344
- for (i = 0; i < numrefs; i++) {
345
- const char *ref = refs[i];
346
- const char *lref = ref;
347
- const char *colon;
348
- const char *tail;
349
- const char *ls;
350
- const char *next;
351
-
352
- if (*lref == '+')
353
- lref++;
354
- colon = strchr(lref, ':');
355
- tail = lref + strlen(lref);
356
- if (!(colon &&
357
- 2 < colon - lref &&
358
- colon[-1] == '*' &&
359
- colon[-2] == '/' &&
360
- 2 < tail - (colon + 1) &&
361
- tail[-1] == '*' &&
362
- tail[-2] == '/')) {
363
- /* not a glob */
364
- if (!found_one++)
365
- printf("explicit\n");
366
- printf("%s\n", ref);
367
- continue;
368
- }
369
-
370
- /* glob */
371
- if (!found_one++)
372
- printf("glob\n");
373
-
374
- /* lref to colon-2 is remote hierarchy name;
375
- * colon+1 to tail-2 is local.
376
- */
377
- matchlen = (colon-1) - lref;
378
- replacelen = (tail-1) - (colon+1);
379
- for (ls = ls_remote_result; ls; ls = next) {
380
- const char *eol;
381
- unsigned char sha1[20];
382
- int namelen;
383
-
384
- while (*ls && isspace(*ls))
385
- ls++;
386
- next = strchr(ls, '\n');
387
- eol = !next ? (ls + strlen(ls)) : next;
388
- if (!memcmp("^{}", eol-3, 3))
389
- continue;
390
- if (eol - ls < 40)
391
- continue;
392
- if (get_sha1_hex(ls, sha1))
393
- continue;
394
- ls += 40;
395
- while (ls < eol && isspace(*ls))
396
- ls++;
397
- /* ls to next (or eol) is the name.
398
- * is it identical to lref to colon-2?
399
- */
400
- if ((eol - ls) <= matchlen ||
401
- strncmp(ls, lref, matchlen))
402
- continue;
403
-
404
- /* Yes, it is a match */
405
- namelen = eol - ls;
406
- if (lref != ref)
407
- putchar('+');
408
- printf("%.*s:%.*s%.*s\n",
409
- namelen, ls,
410
- replacelen, colon + 1,
411
- namelen - matchlen, ls + matchlen);
412
- }
413
- }
414
- return 0;
415
-}
416
-
417
-static int pick_rref(int sha1_only, const char *rref, const char *ls_remote_result)
418
-{
419
- int err = 0;
420
- int lrr_count = lrr_count, i, pass;
421
- const char *cp;
422
- struct lrr {
423
- const char *line;
424
- const char *name;
425
- int namelen;
426
- int shown;
427
- } *lrr_list = lrr_list;
428
-
429
- for (pass = 0; pass < 2; pass++) {
430
- /* pass 0 counts and allocates, pass 1 fills... */
431
- cp = ls_remote_result;
432
- i = 0;
433
- while (1) {
434
- const char *np;
435
- while (*cp && isspace(*cp))
436
- cp++;
437
- if (!*cp)
438
- break;
439
- np = strchrnul(cp, '\n');
440
- if (pass) {
441
- lrr_list[i].line = cp;
442
- lrr_list[i].name = cp + 41;
443
- lrr_list[i].namelen = np - (cp + 41);
444
- }
445
- i++;
446
- cp = np;
447
- }
448
- if (!pass) {
449
- lrr_count = i;
450
- lrr_list = xcalloc(lrr_count, sizeof(*lrr_list));
451
- }
452
- }
453
-
454
- while (1) {
455
- const char *next;
456
- int rreflen;
457
- int i;
458
-
459
- while (*rref && isspace(*rref))
460
- rref++;
461
- if (!*rref)
462
- break;
463
- next = strchrnul(rref, '\n');
464
- rreflen = next - rref;
465
-
466
- for (i = 0; i < lrr_count; i++) {
467
- struct lrr *lrr = &(lrr_list[i]);
468
-
469
- if (rreflen == lrr->namelen &&
470
- !memcmp(lrr->name, rref, rreflen)) {
471
- if (!lrr->shown)
472
- printf("%.*s\n",
473
- sha1_only ? 40 : lrr->namelen + 41,
474
- lrr->line);
475
- lrr->shown = 1;
476
- break;
477
- }
478
- }
479
- if (lrr_count <= i) {
480
- error("pick-rref: %.*s not found", rreflen, rref);
481
- err = 1;
482
- }
483
- rref = next;
484
- }
485
- free(lrr_list);
486
- return err;
487
-}
488
-
489
-int cmd_fetch__tool(int argc, const char **argv, const char *prefix)
490
-{
491
- int verbose = 0;
492
- int force = 0;
493
- int sopt = 0;
494
-
495
- while (1 < argc) {
496
- const char *arg = argv[1];
497
- if (!strcmp("-v", arg))
498
- verbose = 1;
499
- else if (!strcmp("-f", arg))
500
- force = 1;
501
- else if (!strcmp("-s", arg))
502
- sopt = 1;
503
- else
504
- break;
505
- argc--;
506
- argv++;
507
- }
508
-
509
- if (argc <= 1)
510
- return error("Missing subcommand");
511
-
512
- if (!strcmp("append-fetch-head", argv[1])) {
513
- int result;
514
- FILE *fp;
515
- char *filename;
516
-
517
- if (argc != 8)
518
- return error("append-fetch-head takes 6 args");
519
- filename = git_path_fetch_head();
520
- fp = fopen(filename, "a");
521
- if (!fp)
522
- return error("cannot open %s: %s", filename, strerror(errno));
523
- result = append_fetch_head(fp, argv[2], argv[3],
524
- argv[4], argv[5],
525
- argv[6], !!argv[7][0],
526
- verbose, force);
527
- fclose(fp);
528
- return result;
529
- }
530
- if (!strcmp("native-store", argv[1])) {
531
- int result;
532
- FILE *fp;
533
- char *filename;
534
-
535
- if (argc != 5)
536
- return error("fetch-native-store takes 3 args");
537
- filename = git_path_fetch_head();
538
- fp = fopen(filename, "a");
539
- if (!fp)
540
- return error("cannot open %s: %s", filename, strerror(errno));
541
- result = fetch_native_store(fp, argv[2], argv[3], argv[4],
542
- verbose, force);
543
- fclose(fp);
544
- return result;
545
- }
546
- if (!strcmp("parse-reflist", argv[1])) {
547
- const char *reflist;
548
- if (argc != 3)
549
- return error("parse-reflist takes 1 arg");
550
- reflist = argv[2];
551
- if (!strcmp(reflist, "-"))
552
- reflist = get_stdin();
553
- return parse_reflist(reflist);
554
- }
555
- if (!strcmp("pick-rref", argv[1])) {
556
- const char *ls_remote_result;
557
- if (argc != 4)
558
- return error("pick-rref takes 2 args");
559
- ls_remote_result = argv[3];
560
- if (!strcmp(ls_remote_result, "-"))
561
- ls_remote_result = get_stdin();
562
- return pick_rref(sopt, argv[2], ls_remote_result);
563
- }
564
- if (!strcmp("expand-refs-wildcard", argv[1])) {
565
- const char *reflist;
566
- if (argc < 4)
567
- return error("expand-refs-wildcard takes at least 2 args");
568
- reflist = argv[2];
569
- if (!strcmp(reflist, "-"))
570
- reflist = get_stdin();
571
- return expand_refs_wildcard(reflist, argc - 3, argv + 3);
572
- }
573
-
574
- return error("Unknown subcommand: %s", argv[1]);
575
-}
contrib/examples/git-am.sh
deleted
-975
@@ -1,975 +0,0 @@
1
-#!/bin/sh
2
-#
3
-# Copyright (c) 2005, 2006 Junio C Hamano
4
-
5
-SUBDIRECTORY_OK=Yes
6
-OPTIONS_KEEPDASHDASH=
7
-OPTIONS_STUCKLONG=t
8
-OPTIONS_SPEC="\
9
-git am [options] [(<mbox>|<Maildir>)...]
10
-git am [options] (--continue | --skip | --abort)
11
---
12
-i,interactive run interactively
13
-b,binary* (historical option -- no-op)
14
-3,3way allow fall back on 3way merging if needed
15
-q,quiet be quiet
16
-s,signoff add a Signed-off-by line to the commit message
17
-u,utf8 recode into utf8 (default)
18
-k,keep pass -k flag to git-mailinfo
19
-keep-non-patch pass -b flag to git-mailinfo
20
-m,message-id pass -m flag to git-mailinfo
21
-keep-cr pass --keep-cr flag to git-mailsplit for mbox format
22
-no-keep-cr do not pass --keep-cr flag to git-mailsplit independent of am.keepcr
23
-c,scissors strip everything before a scissors line
24
-whitespace= pass it through git-apply
25
-ignore-space-change pass it through git-apply
26
-ignore-whitespace pass it through git-apply
27
-directory= pass it through git-apply
28
-exclude= pass it through git-apply
29
-include= pass it through git-apply
30
-C= pass it through git-apply
31
-p= pass it through git-apply
32
-patch-format= format the patch(es) are in
33
-reject pass it through git-apply
34
-resolvemsg= override error message when patch failure occurs
35
-continue continue applying patches after resolving a conflict
36
-r,resolved synonyms for --continue
37
-skip skip the current patch
38
-abort restore the original branch and abort the patching operation.
39
-committer-date-is-author-date lie about committer date
40
-ignore-date use current timestamp for author date
41
-rerere-autoupdate update the index with reused conflict resolution if possible
42
-S,gpg-sign? GPG-sign commits
43
-rebasing* (internal use for git-rebase)"
44
-
45
-. git-sh-setup
46
-. git-sh-i18n
47
-prefix=$(git rev-parse --show-prefix)
48
-set_reflog_action am
49
-require_work_tree
50
-cd_to_toplevel
51
-
52
-git var GIT_COMMITTER_IDENT >/dev/null ||
53
- die "$(gettext "You need to set your committer info first")"
54
-
55
-if git rev-parse --verify -q HEAD >/dev/null
56
-then
57
- HAS_HEAD=yes
58
-else
59
- HAS_HEAD=
60
-fi
61
-
62
-cmdline="git am"
63
-if test '' != "$interactive"
64
-then
65
- cmdline="$cmdline -i"
66
-fi
67
-if test '' != "$threeway"
68
-then
69
- cmdline="$cmdline -3"
70
-fi
71
-
72
-empty_tree=4b825dc642cb6eb9a060e54bf8d69288fbee4904
73
-
74
-sq () {
75
- git rev-parse --sq-quote "$@"
76
-}
77
-
78
-stop_here () {
79
- echo "$1" >"$dotest/next"
80
- git rev-parse --verify -q HEAD >"$dotest/abort-safety"
81
- exit 1
82
-}
83
-
84
-safe_to_abort () {
85
- if test -f "$dotest/dirtyindex"
86
- then
87
- return 1
88
- fi
89
-
90
- if ! test -f "$dotest/abort-safety"
91
- then
92
- return 0
93
- fi
94
-
95
- abort_safety=$(cat "$dotest/abort-safety")
96
- if test "z$(git rev-parse --verify -q HEAD)" = "z$abort_safety"
97
- then
98
- return 0
99
- fi
100
- gettextln "You seem to have moved HEAD since the last 'am' failure.
101
-Not rewinding to ORIG_HEAD" >&2
102
- return 1
103
-}
104
-
105
-stop_here_user_resolve () {
106
- if [ -n "$resolvemsg" ]; then
107
- printf '%s\n' "$resolvemsg"
108
- stop_here $1
109
- fi
110
- eval_gettextln "When you have resolved this problem, run \"\$cmdline --continue\".
111
-If you prefer to skip this patch, run \"\$cmdline --skip\" instead.
112
-To restore the original branch and stop patching, run \"\$cmdline --abort\"."
113
-
114
- stop_here $1
115
-}
116
-
117
-go_next () {
118
- rm -f "$dotest/$msgnum" "$dotest/msg" "$dotest/msg-clean" \
119
- "$dotest/patch" "$dotest/info"
120
- echo "$next" >"$dotest/next"
121
- this=$next
122
-}
123
-
124
-cannot_fallback () {
125
- echo "$1"
126
- gettextln "Cannot fall back to three-way merge."
127
- exit 1
128
-}
129
-
130
-fall_back_3way () {
131
- O_OBJECT=$(cd "$GIT_OBJECT_DIRECTORY" && pwd)
132
-
133
- rm -fr "$dotest"/patch-merge-*
134
- mkdir "$dotest/patch-merge-tmp-dir"
135
-
136
- # First see if the patch records the index info that we can use.
137
- cmd="git apply $git_apply_opt --build-fake-ancestor" &&
138
- cmd="$cmd "'"$dotest/patch-merge-tmp-index" "$dotest/patch"' &&
139
- eval "$cmd" &&
140
- GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \
141
- git write-tree >"$dotest/patch-merge-base+" ||
142
- cannot_fallback "$(gettext "Repository lacks necessary blobs to fall back on 3-way merge.")"
143
-
144
- say "$(gettext "Using index info to reconstruct a base tree...")"
145
-
146
- cmd='GIT_INDEX_FILE="$dotest/patch-merge-tmp-index"'
147
-
148
- if test -z "$GIT_QUIET"
149
- then
150
- eval "$cmd git diff-index --cached --diff-filter=AM --name-status HEAD"
151
- fi
152
-
153
- cmd="$cmd git apply --cached $git_apply_opt"' <"$dotest/patch"'
154
- if eval "$cmd"
155
- then
156
- mv "$dotest/patch-merge-base+" "$dotest/patch-merge-base"
157
- mv "$dotest/patch-merge-tmp-index" "$dotest/patch-merge-index"
158
- else
159
- cannot_fallback "$(gettext "Did you hand edit your patch?
160
-It does not apply to blobs recorded in its index.")"
161
- fi
162
-
163
- test -f "$dotest/patch-merge-index" &&
164
- his_tree=$(GIT_INDEX_FILE="$dotest/patch-merge-index" git write-tree) &&
165
- orig_tree=$(cat "$dotest/patch-merge-base") &&
166
- rm -fr "$dotest"/patch-merge-* || exit 1
167
-
168
- say "$(gettext "Falling back to patching base and 3-way merge...")"
169
-
170
- # This is not so wrong. Depending on which base we picked,
171
- # orig_tree may be wildly different from ours, but his_tree
172
- # has the same set of wildly different changes in parts the
173
- # patch did not touch, so recursive ends up canceling them,
174
- # saying that we reverted all those changes.
175
-
176
- eval GITHEAD_$his_tree='"$FIRSTLINE"'
177
- export GITHEAD_$his_tree
178
- if test -n "$GIT_QUIET"
179
- then
180
- GIT_MERGE_VERBOSITY=0 && export GIT_MERGE_VERBOSITY
181
- fi
182
- our_tree=$(git rev-parse --verify -q HEAD || echo $empty_tree)
183
- git-merge-recursive $orig_tree -- $our_tree $his_tree || {
184
- git rerere $allow_rerere_autoupdate
185
- die "$(gettext "Failed to merge in the changes.")"
186
- }
187
- unset GITHEAD_$his_tree
188
-}
189
-
190
-clean_abort () {
191
- test $# = 0 || echo >&2 "$@"
192
- rm -fr "$dotest"
193
- exit 1
194
-}
195
-
196
-patch_format=
197
-
198
-check_patch_format () {
199
- # early return if patch_format was set from the command line
200
- if test -n "$patch_format"
201
- then
202
- return 0
203
- fi
204
-
205
- # we default to mbox format if input is from stdin and for
206
- # directories
207
- if test $# = 0 || test "x$1" = "x-" || test -d "$1"
208
- then
209
- patch_format=mbox
210
- return 0
211
- fi
212
-
213
- # otherwise, check the first few non-blank lines of the first
214
- # patch to try to detect its format
215
- {
216
- # Start from first line containing non-whitespace
217
- l1=
218
- while test -z "$l1"
219
- do
220
- read l1 || break
221
- done
222
- read l2
223
- read l3
224
- case "$l1" in
225
- "From "* | "From: "*)
226
- patch_format=mbox
227
- ;;
228
- '# This series applies on GIT commit'*)
229
- patch_format=stgit-series
230
- ;;
231
- "# HG changeset patch")
232
- patch_format=hg
233
- ;;
234
- *)
235
- # if the second line is empty and the third is
236
- # a From, Author or Date entry, this is very
237
- # likely an StGIT patch
238
- case "$l2,$l3" in
239
- ,"From: "* | ,"Author: "* | ,"Date: "*)
240
- patch_format=stgit
241
- ;;
242
- *)
243
- ;;
244
- esac
245
- ;;
246
- esac
247
- if test -z "$patch_format" &&
248
- test -n "$l1" &&
249
- test -n "$l2" &&
250
- test -n "$l3"
251
- then
252
- # This begins with three non-empty lines. Is this a
253
- # piece of e-mail a-la RFC2822? Grab all the headers,
254
- # discarding the indented remainder of folded lines,
255
- # and see if it looks like that they all begin with the
256
- # header field names...
257
- tr -d '\015' <"$1" |
258
- sed -n -e '/^$/q' -e '/^[ ]/d' -e p |
259
- sane_egrep -v '^[!-9;-~]+:' >/dev/null ||
260
- patch_format=mbox
261
- fi
262
- } < "$1" || clean_abort
263
-}
264
-
265
-split_patches () {
266
- case "$patch_format" in
267
- mbox)
268
- if test t = "$keepcr"
269
- then
270
- keep_cr=--keep-cr
271
- else
272
- keep_cr=
273
- fi
274
- git mailsplit -d"$prec" -o"$dotest" -b $keep_cr -- "$@" > "$dotest/last" ||
275
- clean_abort
276
- ;;
277
- stgit-series)
278
- if test $# -ne 1
279
- then
280
- clean_abort "$(gettext "Only one StGIT patch series can be applied at once")"
281
- fi
282
- series_dir=$(dirname "$1")
283
- series_file="$1"
284
- shift
285
- {
286
- set x
287
- while read filename
288
- do
289
- set "$@" "$series_dir/$filename"
290
- done
291
- # remove the safety x
292
- shift
293
- # remove the arg coming from the first-line comment
294
- shift
295
- } < "$series_file" || clean_abort
296
- # set the patch format appropriately
297
- patch_format=stgit
298
- # now handle the actual StGIT patches
299
- split_patches "$@"
300
- ;;
301
- stgit)
302
- this=0
303
- test 0 -eq "$#" && set -- -
304
- for stgit in "$@"
305
- do
306
- this=$(expr "$this" + 1)
307
- msgnum=$(printf "%0${prec}d" $this)
308
- # Perl version of StGIT parse_patch. The first nonemptyline
309
- # not starting with Author, From or Date is the
310
- # subject, and the body starts with the next nonempty
311
- # line not starting with Author, From or Date
312
- @@PERL@@ -ne 'BEGIN { $subject = 0 }
313
- if ($subject > 1) { print ; }
314
- elsif (/^\s+$/) { next ; }
315
- elsif (/^Author:/) { s/Author/From/ ; print ;}
316
- elsif (/^(From|Date)/) { print ; }
317
- elsif ($subject) {
318
- $subject = 2 ;
319
- print "\n" ;
320
- print ;
321
- } else {
322
- print "Subject: ", $_ ;
323
- $subject = 1;
324
- }
325
- ' -- "$stgit" >"$dotest/$msgnum" || clean_abort
326
- done
327
- echo "$this" > "$dotest/last"
328
- this=
329
- msgnum=
330
- ;;
331
- hg)
332
- this=0
333
- test 0 -eq "$#" && set -- -
334
- for hg in "$@"
335
- do
336
- this=$(( $this + 1 ))
337
- msgnum=$(printf "%0${prec}d" $this)
338
- # hg stores changeset metadata in #-commented lines preceding
339
- # the commit message and diff(s). The only metadata we care about
340
- # are the User and Date (Node ID and Parent are hashes which are
341
- # only relevant to the hg repository and thus not useful to us)
342
- # Since we cannot guarantee that the commit message is in
343
- # git-friendly format, we put no Subject: line and just consume
344
- # all of the message as the body
345
- LANG=C LC_ALL=C @@PERL@@ -M'POSIX qw(strftime)' -ne 'BEGIN { $subject = 0 }
346
- if ($subject) { print ; }
347
- elsif (/^\# User /) { s/\# User/From:/ ; print ; }
348
- elsif (/^\# Date /) {
349
- my ($hashsign, $str, $time, $tz) = split ;
350
- $tz_str = sprintf "%+05d", (0-$tz)/36;
351
- print "Date: " .
352
- strftime("%a, %d %b %Y %H:%M:%S ",
353
- gmtime($time-$tz))
354
- . "$tz_str\n";
355
- } elsif (/^\# /) { next ; }
356
- else {
357
- print "\n", $_ ;
358
- $subject = 1;
359
- }
360
- ' -- "$hg" >"$dotest/$msgnum" || clean_abort
361
- done
362
- echo "$this" >"$dotest/last"
363
- this=
364
- msgnum=
365
- ;;
366
- *)
367
- if test -n "$patch_format"
368
- then
369
- clean_abort "$(eval_gettext "Patch format \$patch_format is not supported.")"
370
- else
371
- clean_abort "$(gettext "Patch format detection failed.")"
372
- fi
373
- ;;
374
- esac
375
-}
376
-
377
-prec=4
378
-dotest="$GIT_DIR/rebase-apply"
379
-sign= utf8=t keep= keepcr= skip= interactive= resolved= rebasing= abort=
380
-messageid= resolvemsg= resume= scissors= no_inbody_headers=
381
-git_apply_opt=
382
-committer_date_is_author_date=
383
-ignore_date=
384
-allow_rerere_autoupdate=
385
-gpg_sign_opt=
386
-threeway=
387
-
388
-if test "$(git config --bool --get am.messageid)" = true
389
-then
390
- messageid=t
391
-fi
392
-
393
-if test "$(git config --bool --get am.keepcr)" = true
394
-then
395
- keepcr=t
396
-fi
397
-
398
-while test $# != 0
399
-do
400
- case "$1" in
401
- -i|--interactive)
402
- interactive=t ;;
403
- -b|--binary)
404
- gettextln >&2 "The -b/--binary option has been a no-op for long time, and
405
-it will be removed. Please do not use it anymore."
406
- ;;
407
- -3|--3way)
408
- threeway=t ;;
409
- -s|--signoff)
410
- sign=t ;;
411
- -u|--utf8)
412
- utf8=t ;; # this is now default
413
- --no-utf8)
414
- utf8= ;;
415
- -m|--message-id)
416
- messageid=t ;;
417
- --no-message-id)
418
- messageid=f ;;
419
- -k|--keep)
420
- keep=t ;;
421
- --keep-non-patch)
422
- keep=b ;;
423
- -c|--scissors)
424
- scissors=t ;;
425
- --no-scissors)
426
- scissors=f ;;
427
- -r|--resolved|--continue)
428
- resolved=t ;;
429
- --skip)
430
- skip=t ;;
431
- --abort)
432
- abort=t ;;
433
- --rebasing)
434
- rebasing=t threeway=t ;;
435
- --resolvemsg=*)
436
- resolvemsg="${1#--resolvemsg=}" ;;
437
- --whitespace=*|--directory=*|--exclude=*|--include=*)
438
- git_apply_opt="$git_apply_opt $(sq "$1")" ;;
439
- -C*|-p*)
440
- git_apply_opt="$git_apply_opt $(sq "$1")" ;;
441
- --patch-format=*)
442
- patch_format="${1#--patch-format=}" ;;
443
- --reject|--ignore-whitespace|--ignore-space-change)
444
- git_apply_opt="$git_apply_opt $1" ;;
445
- --committer-date-is-author-date)
446
- committer_date_is_author_date=t ;;
447
- --ignore-date)
448
- ignore_date=t ;;
449
- --rerere-autoupdate|--no-rerere-autoupdate)
450
- allow_rerere_autoupdate="$1" ;;
451
- -q|--quiet)
452
- GIT_QUIET=t ;;
453
- --keep-cr)
454
- keepcr=t ;;
455
- --no-keep-cr)
456
- keepcr=f ;;
457
- --gpg-sign)
458
- gpg_sign_opt=-S ;;
459
- --gpg-sign=*)
460
- gpg_sign_opt="-S${1#--gpg-sign=}" ;;
461
- --)
462
- shift; break ;;
463
- *)
464
- usage ;;
465
- esac
466
- shift
467
-done
468
-
469
-# If the dotest directory exists, but we have finished applying all the
470
-# patches in them, clear it out.
471
-if test -d "$dotest" &&
472
- test -f "$dotest/last" &&
473
- test -f "$dotest/next" &&
474
- last=$(cat "$dotest/last") &&
475
- next=$(cat "$dotest/next") &&
476
- test $# != 0 &&
477
- test "$next" -gt "$last"
478
-then
479
- rm -fr "$dotest"
480
-fi
481
-
482
-if test -d "$dotest" && test -f "$dotest/last" && test -f "$dotest/next"
483
-then
484
- case "$#,$skip$resolved$abort" in
485
- 0,*t*)
486
- # Explicit resume command and we do not have file, so
487
- # we are happy.
488
- : ;;
489
- 0,)
490
- # No file input but without resume parameters; catch
491
- # user error to feed us a patch from standard input
492
- # when there is already $dotest. This is somewhat
493
- # unreliable -- stdin could be /dev/null for example
494
- # and the caller did not intend to feed us a patch but
495
- # wanted to continue unattended.
496
- test -t 0
497
- ;;
498
- *)
499
- false
500
- ;;
501
- esac ||
502
- die "$(eval_gettext "previous rebase directory \$dotest still exists but mbox given.")"
503
- resume=yes
504
-
505
- case "$skip,$abort" in
506
- t,t)
507
- die "$(gettext "Please make up your mind. --skip or --abort?")"
508
- ;;
509
- t,)
510
- git rerere clear
511
- head_tree=$(git rev-parse --verify -q HEAD || echo $empty_tree) &&
512
- git read-tree --reset -u $head_tree $head_tree &&
513
- index_tree=$(git write-tree) &&
514
- git read-tree -m -u $index_tree $head_tree
515
- git read-tree -m $head_tree
516
- ;;
517
- ,t)
518
- if test -f "$dotest/rebasing"
519
- then
520
- exec git rebase --abort
521
- fi
522
- git rerere clear
523
- if safe_to_abort
524
- then
525
- head_tree=$(git rev-parse --verify -q HEAD || echo $empty_tree) &&
526
- git read-tree --reset -u $head_tree $head_tree &&
527
- index_tree=$(git write-tree) &&
528
- orig_head=$(git rev-parse --verify -q ORIG_HEAD || echo $empty_tree) &&
529
- git read-tree -m -u $index_tree $orig_head
530
- if git rev-parse --verify -q ORIG_HEAD >/dev/null 2>&1
531
- then
532
- git reset ORIG_HEAD
533
- else
534
- git read-tree $empty_tree
535
- curr_branch=$(git symbolic-ref HEAD 2>/dev/null) &&
536
- git update-ref -d $curr_branch
537
- fi
538
- fi
539
- rm -fr "$dotest"
540
- exit ;;
541
- esac
542
- rm -f "$dotest/dirtyindex"
543
-else
544
- # Possible stray $dotest directory in the independent-run
545
- # case; in the --rebasing case, it is upto the caller
546
- # (git-rebase--am) to take care of stray directories.
547
- if test -d "$dotest" && test -z "$rebasing"
548
- then
549
- case "$skip,$resolved,$abort" in
550
- ,,t)
551
- rm -fr "$dotest"
552
- exit 0
553
- ;;
554
- *)
555
- die "$(eval_gettext "Stray \$dotest directory found.
556
-Use \"git am --abort\" to remove it.")"
557
- ;;
558
- esac
559
- fi
560
-
561
- # Make sure we are not given --skip, --continue, or --abort
562
- test "$skip$resolved$abort" = "" ||
563
- die "$(gettext "Resolve operation not in progress, we are not resuming.")"
564
-
565
- # Start afresh.
566
- mkdir -p "$dotest" || exit
567
-
568
- if test -n "$prefix" && test $# != 0
569
- then
570
- first=t
571
- for arg
572
- do
573
- test -n "$first" && {
574
- set x
575
- first=
576
- }
577
- if is_absolute_path "$arg"
578
- then
579
- set "$@" "$arg"
580
- else
581
- set "$@" "$prefix$arg"
582
- fi
583
- done
584
- shift
585
- fi
586
-
587
- check_patch_format "$@"
588
-
589
- split_patches "$@"
590
-
591
- # -i can and must be given when resuming; everything
592
- # else is kept
593
- echo " $git_apply_opt" >"$dotest/apply-opt"
594
- echo "$threeway" >"$dotest/threeway"
595
- echo "$sign" >"$dotest/sign"
596
- echo "$utf8" >"$dotest/utf8"
597
- echo "$keep" >"$dotest/keep"
598
- echo "$messageid" >"$dotest/messageid"
599
- echo "$scissors" >"$dotest/scissors"
600
- echo "$no_inbody_headers" >"$dotest/no_inbody_headers"
601
- echo "$GIT_QUIET" >"$dotest/quiet"
602
- echo 1 >"$dotest/next"
603
- if test -n "$rebasing"
604
- then
605
- : >"$dotest/rebasing"
606
- else
607
- : >"$dotest/applying"
608
- if test -n "$HAS_HEAD"
609
- then
610
- git update-ref ORIG_HEAD HEAD
611
- else
612
- git update-ref -d ORIG_HEAD >/dev/null 2>&1
613
- fi
614
- fi
615
-fi
616
-
617
-git update-index -q --refresh
618
-
619
-case "$resolved" in
620
-'')
621
- case "$HAS_HEAD" in
622
- '')
623
- files=$(git ls-files) ;;
624
- ?*)
625
- files=$(git diff-index --cached --name-only HEAD --) ;;
626
- esac || exit
627
- if test "$files"
628
- then
629
- test -n "$HAS_HEAD" && : >"$dotest/dirtyindex"
630
- die "$(eval_gettext "Dirty index: cannot apply patches (dirty: \$files)")"
631
- fi
632
-esac
633
-
634
-# Now, decide what command line options we will give to the git
635
-# commands we invoke, based on the result of parsing command line
636
-# options and previous invocation state stored in $dotest/ files.
637
-
638
-if test "$(cat "$dotest/utf8")" = t
639
-then
640
- utf8=-u
641
-else
642
- utf8=-n
643
-fi
644
-keep=$(cat "$dotest/keep")
645
-case "$keep" in
646
-t)
647
- keep=-k ;;
648
-b)
649
- keep=-b ;;
650
-*)
651
- keep= ;;
652
-esac
653
-case "$(cat "$dotest/messageid")" in
654
-t)
655
- messageid=-m ;;
656
-f)
657
- messageid= ;;
658
-esac
659
-case "$(cat "$dotest/scissors")" in
660
-t)
661
- scissors=--scissors ;;
662
-f)
663
- scissors=--no-scissors ;;
664
-esac
665
-if test "$(cat "$dotest/no_inbody_headers")" = t
666
-then
667
- no_inbody_headers=--no-inbody-headers
668
-else
669
- no_inbody_headers=
670
-fi
671
-if test "$(cat "$dotest/quiet")" = t
672
-then
673
- GIT_QUIET=t
674
-fi
675
-if test "$(cat "$dotest/threeway")" = t
676
-then
677
- threeway=t
678
-fi
679
-git_apply_opt=$(cat "$dotest/apply-opt")
680
-if test "$(cat "$dotest/sign")" = t
681
-then
682
- SIGNOFF=$(git var GIT_COMMITTER_IDENT | sed -e '
683
- s/>.*/>/
684
- s/^/Signed-off-by: /'
685
- )
686
-else
687
- SIGNOFF=
688
-fi
689
-
690
-last=$(cat "$dotest/last")
691
-this=$(cat "$dotest/next")
692
-if test "$skip" = t
693
-then
694
- this=$(expr "$this" + 1)
695
- resume=
696
-fi
697
-
698
-while test "$this" -le "$last"
699
-do
700
- msgnum=$(printf "%0${prec}d" $this)
701
- next=$(expr "$this" + 1)
702
- test -f "$dotest/$msgnum" || {
703
- resume=
704
- go_next
705
- continue
706
- }
707
-
708
- # If we are not resuming, parse and extract the patch information
709
- # into separate files:
710
- # - info records the authorship and title
711
- # - msg is the rest of commit log message
712
- # - patch is the patch body.
713
- #
714
- # When we are resuming, these files are either already prepared
715
- # by the user, or the user can tell us to do so by --continue flag.
716
- case "$resume" in
717
- '')
718
- if test -f "$dotest/rebasing"
719
- then
720
- commit=$(sed -e 's/^From \([0-9a-f]*\) .*/\1/' \
721
- -e q "$dotest/$msgnum") &&
722
- test "$(git cat-file -t "$commit")" = commit ||
723
- stop_here $this
724
- git cat-file commit "$commit" |
725
- sed -e '1,/^$/d' >"$dotest/msg-clean"
726
- echo "$commit" >"$dotest/original-commit"
727
- get_author_ident_from_commit "$commit" >"$dotest/author-script"
728
- git diff-tree --root --binary --full-index "$commit" >"$dotest/patch"
729
- else
730
- git mailinfo $keep $no_inbody_headers $messageid $scissors $utf8 "$dotest/msg" "$dotest/patch" \
731
- <"$dotest/$msgnum" >"$dotest/info" ||
732
- stop_here $this
733
-
734
- # skip pine's internal folder data
735
- sane_grep '^Author: Mail System Internal Data$' \
736
- <"$dotest"/info >/dev/null &&
737
- go_next && continue
738
-
739
- test -s "$dotest/patch" || {
740
- eval_gettextln "Patch is empty. Was it split wrong?
741
-If you would prefer to skip this patch, instead run \"\$cmdline --skip\".
742
-To restore the original branch and stop patching run \"\$cmdline --abort\"."
743
- stop_here $this
744
- }
745
- rm -f "$dotest/original-commit" "$dotest/author-script"
746
- {
747
- sed -n '/^Subject/ s/Subject: //p' "$dotest/info"
748
- echo
749
- cat "$dotest/msg"
750
- } |
751
- git stripspace > "$dotest/msg-clean"
752
- fi
753
- ;;
754
- esac
755
-
756
- if test -f "$dotest/author-script"
757
- then
758
- eval $(cat "$dotest/author-script")
759
- else
760
- GIT_AUTHOR_NAME="$(sed -n '/^Author/ s/Author: //p' "$dotest/info")"
761
- GIT_AUTHOR_EMAIL="$(sed -n '/^Email/ s/Email: //p' "$dotest/info")"
762
- GIT_AUTHOR_DATE="$(sed -n '/^Date/ s/Date: //p' "$dotest/info")"
763
- fi
764
-
765
- if test -z "$GIT_AUTHOR_EMAIL"
766
- then
767
- gettextln "Patch does not have a valid e-mail address."
768
- stop_here $this
769
- fi
770
-
771
- export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE
772
-
773
- case "$resume" in
774
- '')
775
- if test '' != "$SIGNOFF"
776
- then
777
- LAST_SIGNED_OFF_BY=$(
778
- sed -ne '/^Signed-off-by: /p' \
779
- "$dotest/msg-clean" |
780
- sed -ne '$p'
781
- )
782
- ADD_SIGNOFF=$(
783
- test "$LAST_SIGNED_OFF_BY" = "$SIGNOFF" || {
784
- test '' = "$LAST_SIGNED_OFF_BY" && echo
785
- echo "$SIGNOFF"
786
- })
787
- else
788
- ADD_SIGNOFF=
789
- fi
790
- {
791
- if test -s "$dotest/msg-clean"
792
- then
793
- cat "$dotest/msg-clean"
794
- fi
795
- if test '' != "$ADD_SIGNOFF"
796
- then
797
- echo "$ADD_SIGNOFF"
798
- fi
799
- } >"$dotest/final-commit"
800
- ;;
801
- *)
802
- case "$resolved$interactive" in
803
- tt)
804
- # This is used only for interactive view option.
805
- git diff-index -p --cached HEAD -- >"$dotest/patch"
806
- ;;
807
- esac
808
- esac
809
-
810
- resume=
811
- if test "$interactive" = t
812
- then
813
- test -t 0 ||
814
- die "$(gettext "cannot be interactive without stdin connected to a terminal.")"
815
- action=again
816
- while test "$action" = again
817
- do
818
- gettextln "Commit Body is:"
819
- echo "--------------------------"
820
- cat "$dotest/final-commit"
821
- echo "--------------------------"
822
- # TRANSLATORS: Make sure to include [y], [n], [e], [v] and [a]
823
- # in your translation. The program will only accept English
824
- # input at this point.
825
- gettext "Apply? [y]es/[n]o/[e]dit/[v]iew patch/[a]ccept all "
826
- read reply
827
- case "$reply" in
828
- [yY]*) action=yes ;;
829
- [aA]*) action=yes interactive= ;;
830
- [nN]*) action=skip ;;
831
- [eE]*) git_editor "$dotest/final-commit"
832
- action=again ;;
833
- [vV]*) action=again
834
- git_pager "$dotest/patch" ;;
835
- *) action=again ;;
836
- esac
837
- done
838
- else
839
- action=yes
840
- fi
841
-
842
- if test $action = skip
843
- then
844
- go_next
845
- continue
846
- fi
847
-
848
- hook="$(git rev-parse --git-path hooks/applypatch-msg)"
849
- if test -x "$hook"
850
- then
851
- "$hook" "$dotest/final-commit" || stop_here $this
852
- fi
853
-
854
- if test -f "$dotest/final-commit"
855
- then
856
- FIRSTLINE=$(sed 1q "$dotest/final-commit")
857
- else
858
- FIRSTLINE=""
859
- fi
860
-
861
- say "$(eval_gettext "Applying: \$FIRSTLINE")"
862
-
863
- case "$resolved" in
864
- '')
865
- # When we are allowed to fall back to 3-way later, don't give
866
- # false errors during the initial attempt.
867
- squelch=
868
- if test "$threeway" = t
869
- then
870
- squelch='>/dev/null 2>&1 '
871
- fi
872
- eval "git apply $squelch$git_apply_opt"' --index "$dotest/patch"'
873
- apply_status=$?
874
- ;;
875
- t)
876
- # Resolved means the user did all the hard work, and
877
- # we do not have to do any patch application. Just
878
- # trust what the user has in the index file and the
879
- # working tree.
880
- resolved=
881
- git diff-index --quiet --cached HEAD -- && {
882
- gettextln "No changes - did you forget to use 'git add'?
883
-If there is nothing left to stage, chances are that something else
884
-already introduced the same changes; you might want to skip this patch."
885
- stop_here_user_resolve $this
886
- }
887
- unmerged=$(git ls-files -u)
888
- if test -n "$unmerged"
889
- then
890
- gettextln "You still have unmerged paths in your index
891
-did you forget to use 'git add'?"
892
- stop_here_user_resolve $this
893
- fi
894
- apply_status=0
895
- git rerere
896
- ;;
897
- esac
898
-
899
- if test $apply_status != 0 && test "$threeway" = t
900
- then
901
- if (fall_back_3way)
902
- then
903
- # Applying the patch to an earlier tree and merging the
904
- # result may have produced the same tree as ours.
905
- git diff-index --quiet --cached HEAD -- && {
906
- say "$(gettext "No changes -- Patch already applied.")"
907
- go_next
908
- continue
909
- }
910
- # clear apply_status -- we have successfully merged.
911
- apply_status=0
912
- fi
913
- fi
914
- if test $apply_status != 0
915
- then
916
- eval_gettextln 'Patch failed at $msgnum $FIRSTLINE'
917
- if test "$(git config --bool advice.amworkdir)" != false
918
- then
919
- eval_gettextln 'The copy of the patch that failed is found in:
920
- $dotest/patch'
921
- fi
922
- stop_here_user_resolve $this
923
- fi
924
-
925
- hook="$(git rev-parse --git-path hooks/pre-applypatch)"
926
- if test -x "$hook"
927
- then
928
- "$hook" || stop_here $this
929
- fi
930
-
931
- tree=$(git write-tree) &&
932
- commit=$(
933
- if test -n "$ignore_date"
934
- then
935
- GIT_AUTHOR_DATE=
936
- fi
937
- parent=$(git rev-parse --verify -q HEAD) ||
938
- say >&2 "$(gettext "applying to an empty history")"
939
-
940
- if test -n "$committer_date_is_author_date"
941
- then
942
- GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
943
- export GIT_COMMITTER_DATE
944
- fi &&
945
- git commit-tree ${parent:+-p} $parent ${gpg_sign_opt:+"$gpg_sign_opt"} $tree \
946
- <"$dotest/final-commit"
947
- ) &&
948
- git update-ref -m "$GIT_REFLOG_ACTION: $FIRSTLINE" HEAD $commit $parent ||
949
- stop_here $this
950
-
951
- if test -f "$dotest/original-commit"; then
952
- echo "$(cat "$dotest/original-commit") $commit" >> "$dotest/rewritten"
953
- fi
954
-
955
- hook="$(git rev-parse --git-path hooks/post-applypatch)"
956
- test -x "$hook" && "$hook"
957
-
958
- go_next
959
-done
960
-
961
-if test -s "$dotest"/rewritten; then
962
- git notes copy --for-rewrite=rebase < "$dotest"/rewritten
963
- hook="$(git rev-parse --git-path hooks/post-rewrite)"
964
- if test -x "$hook"; then
965
- "$hook" rebase < "$dotest"/rewritten
966
- fi
967
-fi
968
-
969
-# If am was called with --rebasing (from git-rebase--am), it's up to
970
-# the caller to take care of housekeeping.
971
-if ! test -f "$dotest/rebasing"
972
-then
973
- rm -fr "$dotest"
974
- git gc --auto
975
-fi
contrib/examples/git-checkout.sh
deleted
-302
@@ -1,302 +0,0 @@
1
-#!/bin/sh
2
-
3
-OPTIONS_KEEPDASHDASH=t
4
-OPTIONS_SPEC="\
5
-git-checkout [options] [<branch>] [<paths>...]
6
---
7
-b= create a new branch started at <branch>
8
-l create the new branch's reflog
9
-track arrange that the new branch tracks the remote branch
10
-f proceed even if the index or working tree is not HEAD
11
-m merge local modifications into the new branch
12
-q,quiet be quiet
13
-"
14
-SUBDIRECTORY_OK=Sometimes
15
-. git-sh-setup
16
-require_work_tree
17
-
18
-old_name=HEAD
19
-old=$(git rev-parse --verify $old_name 2>/dev/null)
20
-oldbranch=$(git symbolic-ref $old_name 2>/dev/null)
21
-new=
22
-new_name=
23
-force=
24
-branch=
25
-track=
26
-newbranch=
27
-newbranch_log=
28
-merge=
29
-quiet=
30
-v=-v
31
-LF='
32
-'
33
-
34
-while test $# != 0; do
35
- case "$1" in
36
- -b)
37
- shift
38
- newbranch="$1"
39
- [ -z "$newbranch" ] &&
40
- die "git checkout: -b needs a branch name"
41
- git show-ref --verify --quiet -- "refs/heads/$newbranch" &&
42
- die "git checkout: branch $newbranch already exists"
43
- git check-ref-format "heads/$newbranch" ||
44
- die "git checkout: we do not like '$newbranch' as a branch name."
45
- ;;
46
- -l)
47
- newbranch_log=-l
48
- ;;
49
- --track|--no-track)
50
- track="$1"
51
- ;;
52
- -f)
53
- force=1
54
- ;;
55
- -m)
56
- merge=1
57
- ;;
58
- -q|--quiet)
59
- quiet=1
60
- v=
61
- ;;
62
- --)
63
- shift
64
- break
65
- ;;
66
- *)
67
- usage
68
- ;;
69
- esac
70
- shift
71
-done
72
-
73
-arg="$1"
74
-rev=$(git rev-parse --verify "$arg" 2>/dev/null)
75
-if rev=$(git rev-parse --verify "$rev^0" 2>/dev/null)
76
-then
77
- [ -z "$rev" ] && die "unknown flag $arg"
78
- new_name="$arg"
79
- if git show-ref --verify --quiet -- "refs/heads/$arg"
80
- then
81
- rev=$(git rev-parse --verify "refs/heads/$arg^0")
82
- branch="$arg"
83
- fi
84
- new="$rev"
85
- shift
86
-elif rev=$(git rev-parse --verify "$rev^{tree}" 2>/dev/null)
87
-then
88
- # checking out selected paths from a tree-ish.
89
- new="$rev"
90
- new_name="$rev^{tree}"
91
- shift
92
-fi
93
-[ "$1" = "--" ] && shift
94
-
95
-case "$newbranch,$track" in
96
-,--*)
97
- die "git checkout: --track and --no-track require -b"
98
-esac
99
-
100
-case "$force$merge" in
101
-11)
102
- die "git checkout: -f and -m are incompatible"
103
-esac
104
-
105
-# The behaviour of the command with and without explicit path
106
-# parameters is quite different.
107
-#
108
-# Without paths, we are checking out everything in the work tree,
109
-# possibly switching branches. This is the traditional behaviour.
110
-#
111
-# With paths, we are _never_ switching branch, but checking out
112
-# the named paths from either index (when no rev is given),
113
-# or the named tree-ish (when rev is given).
114
-
115
-if test "$#" -ge 1
116
-then
117
- hint=
118
- if test "$#" -eq 1
119
- then
120
- hint="
121
-Did you intend to checkout '$@' which can not be resolved as commit?"
122
- fi
123
- if test '' != "$newbranch$force$merge"
124
- then
125
- die "git checkout: updating paths is incompatible with switching branches/forcing$hint"
126
- fi
127
- if test '' != "$new"
128
- then
129
- # from a specific tree-ish; note that this is for
130
- # rescuing paths and is never meant to remove what
131
- # is not in the named tree-ish.
132
- git ls-tree --full-name -r "$new" "$@" |
133
- git update-index --index-info || exit $?
134
- fi
135
-
136
- # Make sure the request is about existing paths.
137
- git ls-files --full-name --error-unmatch -- "$@" >/dev/null || exit
138
- git ls-files --full-name -- "$@" |
139
- (cd_to_toplevel && git checkout-index -f -u --stdin)
140
-
141
- # Run a post-checkout hook -- the HEAD does not change so the
142
- # current HEAD is passed in for both args
143
- if test -x "$GIT_DIR"/hooks/post-checkout; then
144
- "$GIT_DIR"/hooks/post-checkout $old $old 0
145
- fi
146
-
147
- exit $?
148
-else
149
- # Make sure we did not fall back on $arg^{tree} codepath
150
- # since we are not checking out from an arbitrary tree-ish,
151
- # but switching branches.
152
- if test '' != "$new"
153
- then
154
- git rev-parse --verify "$new^{commit}" >/dev/null 2>&1 ||
155
- die "Cannot switch branch to a non-commit."
156
- fi
157
-fi
158
-
159
-# We are switching branches and checking out trees, so
160
-# we *NEED* to be at the toplevel.
161
-cd_to_toplevel
162
-
163
-[ -z "$new" ] && new=$old && new_name="$old_name"
164
-
165
-# If we don't have an existing branch that we're switching to,
166
-# and we don't have a new branch name for the target we
167
-# are switching to, then we are detaching our HEAD from any
168
-# branch. However, if "git checkout HEAD" detaches the HEAD
169
-# from the current branch, even though that may be logically
170
-# correct, it feels somewhat funny. More importantly, we do not
171
-# want "git checkout" or "git checkout -f" to detach HEAD.
172
-
173
-detached=
174
-detach_warn=
175
-
176
-describe_detached_head () {
177
- test -n "$quiet" || {
178
- printf >&2 "$1 "
179
- GIT_PAGER= git log >&2 -1 --pretty=oneline --abbrev-commit "$2" --
180
- }
181
-}
182
-
183
-if test -z "$branch$newbranch" && test "$new_name" != "$old_name"
184
-then
185
- detached="$new"
186
- if test -n "$oldbranch" && test -z "$quiet"
187
- then
188
- detach_warn="Note: moving to \"$new_name\" which isn't a local branch
189
-If you want to create a new branch from this checkout, you may do so
190
-(now or later) by using -b with the checkout command again. Example:
191
- git checkout -b <new_branch_name>"
192
- fi
193
-elif test -z "$oldbranch" && test "$new" != "$old"
194
-then
195
- describe_detached_head 'Previous HEAD position was' "$old"
196
-fi
197
-
198
-if [ "X$old" = X ]
199
-then
200
- if test -z "$quiet"
201
- then
202
- echo >&2 "warning: You appear to be on a branch yet to be born."
203
- echo >&2 "warning: Forcing checkout of $new_name."
204
- fi
205
- force=1
206
-fi
207
-
208
-if [ "$force" ]
209
-then
210
- git read-tree $v --reset -u $new
211
-else
212
- git update-index --refresh >/dev/null
213
- git read-tree $v -m -u --exclude-per-directory=.gitignore $old $new || (
214
- case "$merge,$v" in
215
- ,*)
216
- exit 1 ;;
217
- 1,)
218
- ;; # quiet
219
- *)
220
- echo >&2 "Falling back to 3-way merge..." ;;
221
- esac
222
-
223
- # Match the index to the working tree, and do a three-way.
224
- git diff-files --name-only | git update-index --remove --stdin &&
225
- work=$(git write-tree) &&
226
- git read-tree $v --reset -u $new || exit
227
-
228
- eval GITHEAD_$new='${new_name:-${branch:-$new}}' &&
229
- eval GITHEAD_$work=local &&
230
- export GITHEAD_$new GITHEAD_$work &&
231
- git merge-recursive $old -- $new $work
232
-
233
- # Do not register the cleanly merged paths in the index yet.
234
- # this is not a real merge before committing, but just carrying
235
- # the working tree changes along.
236
- unmerged=$(git ls-files -u)
237
- git read-tree $v --reset $new
238
- case "$unmerged" in
239
- '') ;;
240
- *)
241
- (
242
- z40=0000000000000000000000000000000000000000
243
- echo "$unmerged" |
244
- sed -e 's/^[0-7]* [0-9a-f]* /'"0 $z40 /"
245
- echo "$unmerged"
246
- ) | git update-index --index-info
247
- ;;
248
- esac
249
- exit 0
250
- )
251
- saved_err=$?
252
- if test "$saved_err" = 0 && test -z "$quiet"
253
- then
254
- git diff-index --name-status "$new"
255
- fi
256
- (exit $saved_err)
257
-fi
258
-
259
-#
260
-# Switch the HEAD pointer to the new branch if we
261
-# checked out a branch head, and remove any potential
262
-# old MERGE_HEAD's (subsequent commits will clearly not
263
-# be based on them, since we re-set the index)
264
-#
265
-if [ "$?" -eq 0 ]; then
266
- if [ "$newbranch" ]; then
267
- git branch $track $newbranch_log "$newbranch" "$new_name" || exit
268
- branch="$newbranch"
269
- fi
270
- if test -n "$branch"
271
- then
272
- old_branch_name=$(expr "z$oldbranch" : 'zrefs/heads/\(.*\)')
273
- GIT_DIR="$GIT_DIR" git symbolic-ref -m "checkout: moving from ${old_branch_name:-$old} to $branch" HEAD "refs/heads/$branch"
274
- if test -n "$quiet"
275
- then
276
- true # nothing
277
- elif test "refs/heads/$branch" = "$oldbranch"
278
- then
279
- echo >&2 "Already on branch \"$branch\""
280
- else
281
- echo >&2 "Switched to${newbranch:+ a new} branch \"$branch\""
282
- fi
283
- elif test -n "$detached"
284
- then
285
- old_branch_name=$(expr "z$oldbranch" : 'zrefs/heads/\(.*\)')
286
- git update-ref --no-deref -m "checkout: moving from ${old_branch_name:-$old} to $arg" HEAD "$detached" ||
287
- die "Cannot detach HEAD"
288
- if test -n "$detach_warn"
289
- then
290
- echo >&2 "$detach_warn"
291
- fi
292
- describe_detached_head 'HEAD is now at' HEAD
293
- fi
294
- rm -f "$GIT_DIR/MERGE_HEAD"
295
-else
296
- exit 1
297
-fi
298
-
299
-# Run a post-checkout hook
300
-if test -x "$GIT_DIR"/hooks/post-checkout; then
301
- "$GIT_DIR"/hooks/post-checkout $old $new 1
302
-fi
contrib/examples/git-clean.sh
deleted
-118
@@ -1,118 +0,0 @@
1
-#!/bin/sh
2
-#
3
-# Copyright (c) 2005-2006 Pavel Roskin
4
-#
5
-
6
-OPTIONS_KEEPDASHDASH=
7
-OPTIONS_SPEC="\
8
-git-clean [options] <paths>...
9
-
10
-Clean untracked files from the working directory
11
-
12
-When optional <paths>... arguments are given, the paths
13
-affected are further limited to those that match them.
14
---
15
-d remove directories as well
16
-f override clean.requireForce and clean anyway
17
-n don't remove anything, just show what would be done
18
-q be quiet, only report errors
19
-x remove ignored files as well
20
-X remove only ignored files"
21
-
22
-SUBDIRECTORY_OK=Yes
23
-. git-sh-setup
24
-require_work_tree
25
-
26
-ignored=
27
-ignoredonly=
28
-cleandir=
29
-rmf="rm -f --"
30
-rmrf="rm -rf --"
31
-rm_refuse="echo Not removing"
32
-echo1="echo"
33
-
34
-disabled=$(git config --bool clean.requireForce)
35
-
36
-while test $# != 0
37
-do
38
- case "$1" in
39
- -d)
40
- cleandir=1
41
- ;;
42
- -f)
43
- disabled=false
44
- ;;
45
- -n)
46
- disabled=false
47
- rmf="echo Would remove"
48
- rmrf="echo Would remove"
49
- rm_refuse="echo Would not remove"
50
- echo1=":"
51
- ;;
52
- -q)
53
- echo1=":"
54
- ;;
55
- -x)
56
- ignored=1
57
- ;;
58
- -X)
59
- ignoredonly=1
60
- ;;
61
- --)
62
- shift
63
- break
64
- ;;
65
- *)
66
- usage # should not happen
67
- ;;
68
- esac
69
- shift
70
-done
71
-
72
-# requireForce used to default to false but now it defaults to true.
73
-# IOW, lack of explicit "clean.requireForce = false" is taken as
74
-# "clean.requireForce = true".
75
-case "$disabled" in
76
-"")
77
- die "clean.requireForce not set and -n or -f not given; refusing to clean"
78
- ;;
79
-"true")
80
- die "clean.requireForce set and -n or -f not given; refusing to clean"
81
- ;;
82
-esac
83
-
84
-if [ "$ignored,$ignoredonly" = "1,1" ]; then
85
- die "-x and -X cannot be set together"
86
-fi
87
-
88
-if [ -z "$ignored" ]; then
89
- excl="--exclude-per-directory=.gitignore"
90
- excl_info= excludes_file=
91
- if [ -f "$GIT_DIR/info/exclude" ]; then
92
- excl_info="--exclude-from=$GIT_DIR/info/exclude"
93
- fi
94
- if cfg_excl=$(git config core.excludesfile) && test -f "$cfg_excl"
95
- then
96
- excludes_file="--exclude-from=$cfg_excl"
97
- fi
98
- if [ "$ignoredonly" ]; then
99
- excl="$excl --ignored"
100
- fi
101
-fi
102
-
103
-git ls-files --others --directory \
104
- $excl ${excl_info:+"$excl_info"} ${excludes_file:+"$excludes_file"} \
105
- -- "$@" |
106
-while read -r file; do
107
- if [ -d "$file" -a ! -L "$file" ]; then
108
- if [ -z "$cleandir" ]; then
109
- $rm_refuse "$file"
110
- continue
111
- fi
112
- $echo1 "Removing $file"
113
- $rmrf "$file"
114
- else
115
- $echo1 "Removing $file"
116
- $rmf "$file"
117
- fi
118
-done
contrib/examples/git-clone.sh
deleted
-525
@@ -1,525 +0,0 @@
1
-#!/bin/sh
2
-#
3
-# Copyright (c) 2005, Linus Torvalds
4
-# Copyright (c) 2005, Junio C Hamano
5
-#
6
-# Clone a repository into a different directory that does not yet exist.
7
-
8
-# See git-sh-setup why.
9
-unset CDPATH
10
-
11
-OPTIONS_SPEC="\
12
-git-clone [options] [--] <repo> [<dir>]
13
---
14
-n,no-checkout don't create a checkout
15
-bare create a bare repository
16
-naked create a bare repository
17
-l,local to clone from a local repository
18
-no-hardlinks don't use local hardlinks, always copy
19
-s,shared setup as a shared repository
20
-template= path to the template directory
21
-q,quiet be quiet
22
-reference= reference repository
23
-o,origin= use <name> instead of 'origin' to track upstream
24
-u,upload-pack= path to git-upload-pack on the remote
25
-depth= create a shallow clone of that depth
26
-
27
-use-separate-remote compatibility, do not use
28
-no-separate-remote compatibility, do not use"
29
-
30
-die() {
31
- echo >&2 "$@"
32
- exit 1
33
-}
34
-
35
-usage() {
36
- exec "$0" -h
37
-}
38
-
39
-eval "$(echo "$OPTIONS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)"
40
-
41
-get_repo_base() {
42
- (
43
- cd "$(/bin/pwd)" &&
44
- cd "$1" || cd "$1.git" &&
45
- {
46
- cd .git
47
- pwd
48
- }
49
- ) 2>/dev/null
50
-}
51
-
52
-if [ -n "$GIT_SSL_NO_VERIFY" -o \
53
- "$(git config --bool http.sslVerify)" = false ]; then
54
- curl_extra_args="-k"
55
-fi
56
-
57
-http_fetch () {
58
- # $1 = Remote, $2 = Local
59
- curl -nsfL $curl_extra_args "$1" >"$2"
60
- curl_exit_status=$?
61
- case $curl_exit_status in
62
- 126|127) exit ;;
63
- *) return $curl_exit_status ;;
64
- esac
65
-}
66
-
67
-clone_dumb_http () {
68
- # $1 - remote, $2 - local
69
- cd "$2" &&
70
- clone_tmp="$GIT_DIR/clone-tmp" &&
71
- mkdir -p "$clone_tmp" || exit 1
72
- if [ -n "$GIT_CURL_FTP_NO_EPSV" -o \
73
- "$(git config --bool http.noEPSV)" = true ]; then
74
- curl_extra_args="${curl_extra_args} --disable-epsv"
75
- fi
76
- http_fetch "$1/info/refs" "$clone_tmp/refs" ||
77
- die "Cannot get remote repository information.
78
-Perhaps git-update-server-info needs to be run there?"
79
- test "z$quiet" = z && v=-v || v=
80
- while read sha1 refname
81
- do
82
- name=$(expr "z$refname" : 'zrefs/\(.*\)') &&
83
- case "$name" in
84
- *^*) continue;;
85
- esac
86
- case "$bare,$name" in
87
- yes,* | ,heads/* | ,tags/*) ;;
88
- *) continue ;;
89
- esac
90
- if test -n "$use_separate_remote" &&
91
- branch_name=$(expr "z$name" : 'zheads/\(.*\)')
92
- then
93
- tname="remotes/$origin/$branch_name"
94
- else
95
- tname=$name
96
- fi
97
- git-http-fetch $v -a -w "$tname" "$sha1" "$1" || exit 1
98
- done <"$clone_tmp/refs"
99
- rm -fr "$clone_tmp"
100
- http_fetch "$1/HEAD" "$GIT_DIR/REMOTE_HEAD" ||
101
- rm -f "$GIT_DIR/REMOTE_HEAD"
102
- if test -f "$GIT_DIR/REMOTE_HEAD"; then
103
- head_sha1=$(cat "$GIT_DIR/REMOTE_HEAD")
104
- case "$head_sha1" in
105
- 'ref: refs/'*)
106
- ;;
107
- *)
108
- git-http-fetch $v -a "$head_sha1" "$1" ||
109
- rm -f "$GIT_DIR/REMOTE_HEAD"
110
- ;;
111
- esac
112
- fi
113
-}
114
-
115
-quiet=
116
-local=no
117
-use_local_hardlink=yes
118
-local_shared=no
119
-unset template
120
-no_checkout=
121
-upload_pack=
122
-bare=
123
-reference=
124
-origin=
125
-origin_override=
126
-use_separate_remote=t
127
-depth=
128
-no_progress=
129
-local_explicitly_asked_for=
130
-test -t 1 || no_progress=--no-progress
131
-
132
-while test $# != 0
133
-do
134
- case "$1" in
135
- -n|--no-checkout)
136
- no_checkout=yes ;;
137
- --naked|--bare)
138
- bare=yes ;;
139
- -l|--local)
140
- local_explicitly_asked_for=yes
141
- use_local_hardlink=yes
142
- ;;
143
- --no-hardlinks)
144
- use_local_hardlink=no ;;
145
- -s|--shared)
146
- local_shared=yes ;;
147
- --template)
148
- shift; template="--template=$1" ;;
149
- -q|--quiet)
150
- quiet=-q ;;
151
- --use-separate-remote|--no-separate-remote)
152
- die "clones are always made with separate-remote layout" ;;
153
- --reference)
154
- shift; reference="$1" ;;
155
- -o|--origin)
156
- shift;
157
- case "$1" in
158
- '')
159
- usage ;;
160
- */*)
161
- die "'$1' is not suitable for an origin name"
162
- esac
163
- git check-ref-format "heads/$1" ||
164
- die "'$1' is not suitable for a branch name"
165
- test -z "$origin_override" ||
166
- die "Do not give more than one --origin options."
167
- origin_override=yes
168
- origin="$1"
169
- ;;
170
- -u|--upload-pack)
171
- shift
172
- upload_pack="--upload-pack=$1" ;;
173
- --depth)
174
- shift
175
- depth="--depth=$1" ;;
176
- --)
177
- shift
178
- break ;;
179
- *)
180
- usage ;;
181
- esac
182
- shift
183
-done
184
-
185
-repo="$1"
186
-test -n "$repo" ||
187
- die 'you must specify a repository to clone.'
188
-
189
-# --bare implies --no-checkout and --no-separate-remote
190
-if test yes = "$bare"
191
-then
192
- if test yes = "$origin_override"
193
- then
194
- die '--bare and --origin $origin options are incompatible.'
195
- fi
196
- no_checkout=yes
197
- use_separate_remote=
198
-fi
199
-
200
-if test -z "$origin"
201
-then
202
- origin=origin
203
-fi
204
-
205
-# Turn the source into an absolute path if
206
-# it is local
207
-if base=$(get_repo_base "$repo"); then
208
- repo="$base"
209
- if test -z "$depth"
210
- then
211
- local=yes
212
- fi
213
-elif test -f "$repo"
214
-then
215
- case "$repo" in /*) ;; *) repo="$PWD/$repo" ;; esac
216
-fi
217
-
218
-# Decide the directory name of the new repository
219
-if test -n "$2"
220
-then
221
- dir="$2"
222
- test $# = 2 || die "excess parameter to git-clone"
223
-else
224
- # Derive one from the repository name
225
- # Try using "humanish" part of source repo if user didn't specify one
226
- if test -f "$repo"
227
- then
228
- # Cloning from a bundle
229
- dir=$(echo "$repo" | sed -e 's|/*\.bundle$||' -e 's|.*/||g')
230
- else
231
- dir=$(echo "$repo" |
232
- sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
233
- fi
234
-fi
235
-
236
-[ -e "$dir" ] && die "destination directory '$dir' already exists."
237
-[ yes = "$bare" ] && unset GIT_WORK_TREE
238
-[ -n "$GIT_WORK_TREE" ] && [ -e "$GIT_WORK_TREE" ] &&
239
-die "working tree '$GIT_WORK_TREE' already exists."
240
-D=
241
-W=
242
-cleanup() {
243
- test -z "$D" && rm -rf "$dir"
244
- test -z "$W" && test -n "$GIT_WORK_TREE" && rm -rf "$GIT_WORK_TREE"
245
- cd ..
246
- test -n "$D" && rm -rf "$D"
247
- test -n "$W" && rm -rf "$W"
248
- exit $err
249
-}
250
-trap 'err=$?; cleanup' 0
251
-mkdir -p "$dir" && D=$(cd "$dir" && pwd) || usage
252
-test -n "$GIT_WORK_TREE" && mkdir -p "$GIT_WORK_TREE" &&
253
-W=$(cd "$GIT_WORK_TREE" && pwd) && GIT_WORK_TREE="$W" && export GIT_WORK_TREE
254
-if test yes = "$bare" || test -n "$GIT_WORK_TREE"; then
255
- GIT_DIR="$D"
256
-else
257
- GIT_DIR="$D/.git"
258
-fi &&
259
-export GIT_DIR &&
260
-GIT_CONFIG="$GIT_DIR/config" git-init $quiet ${template+"$template"} || usage
261
-
262
-if test -n "$bare"
263
-then
264
- GIT_CONFIG="$GIT_DIR/config" git config core.bare true
265
-fi
266
-
267
-if test -n "$reference"
268
-then
269
- ref_git=
270
- if test -d "$reference"
271
- then
272
- if test -d "$reference/.git/objects"
273
- then
274
- ref_git="$reference/.git"
275
- elif test -d "$reference/objects"
276
- then
277
- ref_git="$reference"
278
- fi
279
- fi
280
- if test -n "$ref_git"
281
- then
282
- ref_git=$(cd "$ref_git" && pwd)
283
- echo "$ref_git/objects" >"$GIT_DIR/objects/info/alternates"
284
- (
285
- GIT_DIR="$ref_git" git for-each-ref \
286
- --format='%(objectname) %(*objectname)'
287
- ) |
288
- while read a b
289
- do
290
- test -z "$a" ||
291
- git update-ref "refs/reference-tmp/$a" "$a"
292
- test -z "$b" ||
293
- git update-ref "refs/reference-tmp/$b" "$b"
294
- done
295
- else
296
- die "reference repository '$reference' is not a local directory."
297
- fi
298
-fi
299
-
300
-rm -f "$GIT_DIR/CLONE_HEAD"
301
-
302
-# We do local magic only when the user tells us to.
303
-case "$local" in
304
-yes)
305
- ( cd "$repo/objects" ) ||
306
- die "cannot chdir to local '$repo/objects'."
307
-
308
- if test "$local_shared" = yes
309
- then
310
- mkdir -p "$GIT_DIR/objects/info"
311
- echo "$repo/objects" >>"$GIT_DIR/objects/info/alternates"
312
- else
313
- cpio_quiet_flag=""
314
- cpio --help 2>&1 | grep -- --quiet >/dev/null && \
315
- cpio_quiet_flag=--quiet
316
- l= &&
317
- if test "$use_local_hardlink" = yes
318
- then
319
- # See if we can hardlink and drop "l" if not.
320
- sample_file=$(cd "$repo" && \
321
- find objects -type f -print | sed -e 1q)
322
- # objects directory should not be empty because
323
- # we are cloning!
324
- test -f "$repo/$sample_file" ||
325
- die "fatal: cannot clone empty repository"
326
- if ln "$repo/$sample_file" "$GIT_DIR/objects/sample" 2>/dev/null
327
- then
328
- rm -f "$GIT_DIR/objects/sample"
329
- l=l
330
- elif test -n "$local_explicitly_asked_for"
331
- then
332
- echo >&2 "Warning: -l asked but cannot hardlink to $repo"
333
- fi
334
- fi &&
335
- cd "$repo" &&
336
- # Create dirs using umask and permissions and destination
337
- find objects -type d -print | (cd "$GIT_DIR" && xargs mkdir -p) &&
338
- # Copy existing 0444 permissions on content
339
- find objects ! -type d -print | cpio $cpio_quiet_flag -pumd$l "$GIT_DIR/" || \
340
- exit 1
341
- fi
342
- git-ls-remote "$repo" >"$GIT_DIR/CLONE_HEAD" || exit 1
343
- ;;
344
-*)
345
- case "$repo" in
346
- rsync://*)
347
- case "$depth" in
348
- "") ;;
349
- *) die "shallow over rsync not supported" ;;
350
- esac
351
- rsync $quiet -av --ignore-existing \
352
- --exclude info "$repo/objects/" "$GIT_DIR/objects/" ||
353
- exit
354
- # Look at objects/info/alternates for rsync -- http will
355
- # support it natively and git native ones will do it on the
356
- # remote end. Not having that file is not a crime.
357
- rsync -q "$repo/objects/info/alternates" \
358
- "$GIT_DIR/TMP_ALT" 2>/dev/null ||
359
- rm -f "$GIT_DIR/TMP_ALT"
360
- if test -f "$GIT_DIR/TMP_ALT"
361
- then
362
- ( cd "$D" &&
363
- . git-parse-remote &&
364
- resolve_alternates "$repo" <"$GIT_DIR/TMP_ALT" ) |
365
- while read alt
366
- do
367
- case "$alt" in 'bad alternate: '*) die "$alt";; esac
368
- case "$quiet" in
369
- '') echo >&2 "Getting alternate: $alt" ;;
370
- esac
371
- rsync $quiet -av --ignore-existing \
372
- --exclude info "$alt" "$GIT_DIR/objects" || exit
373
- done
374
- rm -f "$GIT_DIR/TMP_ALT"
375
- fi
376
- git-ls-remote "$repo" >"$GIT_DIR/CLONE_HEAD" || exit 1
377
- ;;
378
- https://*|http://*|ftp://*)
379
- case "$depth" in
380
- "") ;;
381
- *) die "shallow over http or ftp not supported" ;;
382
- esac
383
- if test -z "@@NO_CURL@@"
384
- then
385
- clone_dumb_http "$repo" "$D"
386
- else
387
- die "http transport not supported, rebuild Git with curl support"
388
- fi
389
- ;;
390
- *)
391
- if [ -f "$repo" ] ; then
392
- git bundle unbundle "$repo" > "$GIT_DIR/CLONE_HEAD" ||
393
- die "unbundle from '$repo' failed."
394
- else
395
- case "$upload_pack" in
396
- '') git-fetch-pack --all -k $quiet $depth $no_progress "$repo";;
397
- *) git-fetch-pack --all -k \
398
- $quiet "$upload_pack" $depth $no_progress "$repo" ;;
399
- esac >"$GIT_DIR/CLONE_HEAD" ||
400
- die "fetch-pack from '$repo' failed."
401
- fi
402
- ;;
403
- esac
404
- ;;
405
-esac
406
-test -d "$GIT_DIR/refs/reference-tmp" && rm -fr "$GIT_DIR/refs/reference-tmp"
407
-
408
-if test -f "$GIT_DIR/CLONE_HEAD"
409
-then
410
- # Read git-fetch-pack -k output and store the remote branches.
411
- if [ -n "$use_separate_remote" ]
412
- then
413
- branch_top="remotes/$origin"
414
- else
415
- branch_top="heads"
416
- fi
417
- tag_top="tags"
418
- while read sha1 name
419
- do
420
- case "$name" in
421
- *'^{}')
422
- continue ;;
423
- HEAD)
424
- destname="REMOTE_HEAD" ;;
425
- refs/heads/*)
426
- destname="refs/$branch_top/${name#refs/heads/}" ;;
427
- refs/tags/*)
428
- destname="refs/$tag_top/${name#refs/tags/}" ;;
429
- *)
430
- continue ;;
431
- esac
432
- git update-ref -m "clone: from $repo" "$destname" "$sha1" ""
433
- done < "$GIT_DIR/CLONE_HEAD"
434
-fi
435
-
436
-if test -n "$W"; then
437
- cd "$W" || exit
438
-else
439
- cd "$D" || exit
440
-fi
441
-
442
-if test -z "$bare"
443
-then
444
- # a non-bare repository is always in separate-remote layout
445
- remote_top="refs/remotes/$origin"
446
- head_sha1=
447
- test ! -r "$GIT_DIR/REMOTE_HEAD" || head_sha1=$(cat "$GIT_DIR/REMOTE_HEAD")
448
- case "$head_sha1" in
449
- 'ref: refs/'*)
450
- # Uh-oh, the remote told us (http transport done against
451
- # new style repository with a symref HEAD).
452
- # Ideally we should skip the guesswork but for now
453
- # opt for minimum change.
454
- head_sha1=$(expr "z$head_sha1" : 'zref: refs/heads/\(.*\)')
455
- head_sha1=$(cat "$GIT_DIR/$remote_top/$head_sha1")
456
- ;;
457
- esac
458
-
459
- # The name under $remote_top the remote HEAD seems to point at.
460
- head_points_at=$(
461
- (
462
- test -f "$GIT_DIR/$remote_top/master" && echo "master"
463
- cd "$GIT_DIR/$remote_top" &&
464
- find . -type f -print | sed -e 's/^\.\///'
465
- ) | (
466
- done=f
467
- while read name
468
- do
469
- test t = $done && continue
470
- branch_tip=$(cat "$GIT_DIR/$remote_top/$name")
471
- if test "$head_sha1" = "$branch_tip"
472
- then
473
- echo "$name"
474
- done=t
475
- fi
476
- done
477
- )
478
- )
479
-
480
- # Upstream URL
481
- git config remote."$origin".url "$repo" &&
482
-
483
- # Set up the mappings to track the remote branches.
484
- git config remote."$origin".fetch \
485
- "+refs/heads/*:$remote_top/*" '^$' &&
486
-
487
- # Write out remote.$origin config, and update our "$head_points_at".
488
- case "$head_points_at" in
489
- ?*)
490
- # Local default branch
491
- git symbolic-ref HEAD "refs/heads/$head_points_at" &&
492
-
493
- # Tracking branch for the primary branch at the remote.
494
- git update-ref HEAD "$head_sha1" &&
495
-
496
- rm -f "refs/remotes/$origin/HEAD"
497
- git symbolic-ref "refs/remotes/$origin/HEAD" \
498
- "refs/remotes/$origin/$head_points_at" &&
499
-
500
- git config branch."$head_points_at".remote "$origin" &&
501
- git config branch."$head_points_at".merge "refs/heads/$head_points_at"
502
- ;;
503
- '')
504
- if test -z "$head_sha1"
505
- then
506
- # Source had nonexistent ref in HEAD
507
- echo >&2 "Warning: Remote HEAD refers to nonexistent ref, unable to checkout."
508
- no_checkout=t
509
- else
510
- # Source had detached HEAD pointing nowhere
511
- git update-ref --no-deref HEAD "$head_sha1" &&
512
- rm -f "refs/remotes/$origin/HEAD"
513
- fi
514
- ;;
515
- esac
516
-
517
- case "$no_checkout" in
518
- '')
519
- test "z$quiet" = z && test "z$no_progress" = z && v=-v || v=
520
- git read-tree -m -u $v HEAD HEAD
521
- esac
522
-fi
523
-rm -f "$GIT_DIR/CLONE_HEAD" "$GIT_DIR/REMOTE_HEAD"
524
-
525
-trap - 0
contrib/examples/git-commit.sh
deleted
-639
@@ -1,639 +0,0 @@
1
-#!/bin/sh
2
-#
3
-# Copyright (c) 2005 Linus Torvalds
4
-# Copyright (c) 2006 Junio C Hamano
5
-
6
-USAGE='[-a | --interactive] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit> | --amend] [-u] [-e] [--author <author>] [--template <file>] [[-i | -o] <path>...]'
7
-SUBDIRECTORY_OK=Yes
8
-OPTIONS_SPEC=
9
-. git-sh-setup
10
-require_work_tree
11
-
12
-git rev-parse --verify HEAD >/dev/null 2>&1 || initial_commit=t
13
-
14
-case "$0" in
15
-*status)
16
- status_only=t
17
- ;;
18
-*commit)
19
- status_only=
20
- ;;
21
-esac
22
-
23
-refuse_partial () {
24
- echo >&2 "$1"
25
- echo >&2 "You might have meant to say 'git commit -i paths...', perhaps?"
26
- exit 1
27
-}
28
-
29
-TMP_INDEX=
30
-THIS_INDEX="${GIT_INDEX_FILE:-$GIT_DIR/index}"
31
-NEXT_INDEX="$GIT_DIR/next-index$$"
32
-rm -f "$NEXT_INDEX"
33
-save_index () {
34
- cp -p "$THIS_INDEX" "$NEXT_INDEX"
35
-}
36
-
37
-run_status () {
38
- # If TMP_INDEX is defined, that means we are doing
39
- # "--only" partial commit, and that index file is used
40
- # to build the tree for the commit. Otherwise, if
41
- # NEXT_INDEX exists, that is the index file used to
42
- # make the commit. Otherwise we are using as-is commit
43
- # so the regular index file is what we use to compare.
44
- if test '' != "$TMP_INDEX"
45
- then
46
- GIT_INDEX_FILE="$TMP_INDEX"
47
- export GIT_INDEX_FILE
48
- elif test -f "$NEXT_INDEX"
49
- then
50
- GIT_INDEX_FILE="$NEXT_INDEX"
51
- export GIT_INDEX_FILE
52
- fi
53
-
54
- if test "$status_only" = "t" || test "$use_status_color" = "t"; then
55
- color=
56
- else
57
- color=--nocolor
58
- fi
59
- git runstatus ${color} \
60
- ${verbose:+--verbose} \
61
- ${amend:+--amend} \
62
- ${untracked_files:+--untracked}
63
-}
64
-
65
-trap '
66
- test -z "$TMP_INDEX" || {
67
- test -f "$TMP_INDEX" && rm -f "$TMP_INDEX"
68
- }
69
- rm -f "$NEXT_INDEX"
70
-' 0
71
-
72
-################################################################
73
-# Command line argument parsing and sanity checking
74
-
75
-all=
76
-also=
77
-allow_empty=f
78
-interactive=
79
-only=
80
-logfile=
81
-use_commit=
82
-amend=
83
-edit_flag=
84
-no_edit=
85
-log_given=
86
-log_message=
87
-verify=t
88
-quiet=
89
-verbose=
90
-signoff=
91
-force_author=
92
-only_include_assumed=
93
-untracked_files=
94
-templatefile="$(git config commit.template)"
95
-while test $# != 0
96
-do
97
- case "$1" in
98
- -F|--F|-f|--f|--fi|--fil|--file)
99
- case "$#" in 1) usage ;; esac
100
- shift
101
- no_edit=t
102
- log_given=t$log_given
103
- logfile="$1"
104
- ;;
105
- -F*|-f*)
106
- no_edit=t
107
- log_given=t$log_given
108
- logfile="${1#-[Ff]}"
109
- ;;
110
- --F=*|--f=*|--fi=*|--fil=*|--file=*)
111
- no_edit=t
112
- log_given=t$log_given
113
- logfile="${1#*=}"
114
- ;;
115
- -a|--a|--al|--all)
116
- all=t
117
- ;;
118
- --allo|--allow|--allow-|--allow-e|--allow-em|--allow-emp|\
119
- --allow-empt|--allow-empty)
120
- allow_empty=t
121
- ;;
122
- --au=*|--aut=*|--auth=*|--autho=*|--author=*)
123
- force_author="${1#*=}"
124
- ;;
125
- --au|--aut|--auth|--autho|--author)
126
- case "$#" in 1) usage ;; esac
127
- shift
128
- force_author="$1"
129
- ;;
130
- -e|--e|--ed|--edi|--edit)
131
- edit_flag=t
132
- ;;
133
- -i|--i|--in|--inc|--incl|--inclu|--includ|--include)
134
- also=t
135
- ;;
136
- --int|--inte|--inter|--intera|--interac|--interact|--interacti|\
137
- --interactiv|--interactive)
138
- interactive=t
139
- ;;
140
- -o|--o|--on|--onl|--only)
141
- only=t
142
- ;;
143
- -m|--m|--me|--mes|--mess|--messa|--messag|--message)
144
- case "$#" in 1) usage ;; esac
145
- shift
146
- log_given=m$log_given
147
- log_message="${log_message:+${log_message}
148
-
149
-}$1"
150
- no_edit=t
151
- ;;
152
- -m*)
153
- log_given=m$log_given
154
- log_message="${log_message:+${log_message}
155
-
156
-}${1#-m}"
157
- no_edit=t
158
- ;;
159
- --m=*|--me=*|--mes=*|--mess=*|--messa=*|--messag=*|--message=*)
160
- log_given=m$log_given
161
- log_message="${log_message:+${log_message}
162
-
163
-}${1#*=}"
164
- no_edit=t
165
- ;;
166
- -n|--n|--no|--no-|--no-v|--no-ve|--no-ver|--no-veri|--no-verif|\
167
- --no-verify)
168
- verify=
169
- ;;
170
- --a|--am|--ame|--amen|--amend)
171
- amend=t
172
- use_commit=HEAD
173
- ;;
174
- -c)
175
- case "$#" in 1) usage ;; esac
176
- shift
177
- log_given=t$log_given
178
- use_commit="$1"
179
- no_edit=
180
- ;;
181
- --ree=*|--reed=*|--reedi=*|--reedit=*|--reedit-=*|--reedit-m=*|\
182
- --reedit-me=*|--reedit-mes=*|--reedit-mess=*|--reedit-messa=*|\
183
- --reedit-messag=*|--reedit-message=*)
184
- log_given=t$log_given
185
- use_commit="${1#*=}"
186
- no_edit=
187
- ;;
188
- --ree|--reed|--reedi|--reedit|--reedit-|--reedit-m|--reedit-me|\
189
- --reedit-mes|--reedit-mess|--reedit-messa|--reedit-messag|\
190
- --reedit-message)
191
- case "$#" in 1) usage ;; esac
192
- shift
193
- log_given=t$log_given
194
- use_commit="$1"
195
- no_edit=
196
- ;;
197
- -C)
198
- case "$#" in 1) usage ;; esac
199
- shift
200
- log_given=t$log_given
201
- use_commit="$1"
202
- no_edit=t
203
- ;;
204
- --reu=*|--reus=*|--reuse=*|--reuse-=*|--reuse-m=*|--reuse-me=*|\
205
- --reuse-mes=*|--reuse-mess=*|--reuse-messa=*|--reuse-messag=*|\
206
- --reuse-message=*)
207
- log_given=t$log_given
208
- use_commit="${1#*=}"
209
- no_edit=t
210
- ;;
211
- --reu|--reus|--reuse|--reuse-|--reuse-m|--reuse-me|--reuse-mes|\
212
- --reuse-mess|--reuse-messa|--reuse-messag|--reuse-message)
213
- case "$#" in 1) usage ;; esac
214
- shift
215
- log_given=t$log_given
216
- use_commit="$1"
217
- no_edit=t
218
- ;;
219
- -s|--s|--si|--sig|--sign|--signo|--signof|--signoff)
220
- signoff=t
221
- ;;
222
- -t|--t|--te|--tem|--temp|--templ|--templa|--templat|--template)
223
- case "$#" in 1) usage ;; esac
224
- shift
225
- templatefile="$1"
226
- no_edit=
227
- ;;
228
- -q|--q|--qu|--qui|--quie|--quiet)
229
- quiet=t
230
- ;;
231
- -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
232
- verbose=t
233
- ;;
234
- -u|--u|--un|--unt|--untr|--untra|--untrac|--untrack|--untracke|\
235
- --untracked|--untracked-|--untracked-f|--untracked-fi|--untracked-fil|\
236
- --untracked-file|--untracked-files)
237
- untracked_files=t
238
- ;;
239
- --)
240
- shift
241
- break
242
- ;;
243
- -*)
244
- usage
245
- ;;
246
- *)
247
- break
248
- ;;
249
- esac
250
- shift
251
-done
252
-case "$edit_flag" in t) no_edit= ;; esac
253
-
254
-################################################################
255
-# Sanity check options
256
-
257
-case "$amend,$initial_commit" in
258
-t,t)
259
- die "You do not have anything to amend." ;;
260
-t,)
261
- if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
262
- die "You are in the middle of a merge -- cannot amend."
263
- fi ;;
264
-esac
265
-
266
-case "$log_given" in
267
-tt*)
268
- die "Only one of -c/-C/-F can be used." ;;
269
-*tm*|*mt*)
270
- die "Option -m cannot be combined with -c/-C/-F." ;;
271
-esac
272
-
273
-case "$#,$also,$only,$amend" in
274
-*,t,t,*)
275
- die "Only one of --include/--only can be used." ;;
276
-0,t,,* | 0,,t,)
277
- die "No paths with --include/--only does not make sense." ;;
278
-0,,t,t)
279
- only_include_assumed="# Clever... amending the last one with dirty index." ;;
280
-0,,,*)
281
- ;;
282
-*,,,*)
283
- only_include_assumed="# Explicit paths specified without -i or -o; assuming --only paths..."
284
- also=
285
- ;;
286
-esac
287
-unset only
288
-case "$all,$interactive,$also,$#" in
289
-*t,*t,*)
290
- die "Cannot use -a, --interactive or -i at the same time." ;;
291
-t,,,[1-9]*)
292
- die "Paths with -a does not make sense." ;;
293
-,t,,[1-9]*)
294
- die "Paths with --interactive does not make sense." ;;
295
-,,t,0)
296
- die "No paths with -i does not make sense." ;;
297
-esac
298
-
299
-if test ! -z "$templatefile" && test -z "$log_given"
300
-then
301
- if test ! -f "$templatefile"
302
- then
303
- die "Commit template file does not exist."
304
- fi
305
-fi
306
-
307
-################################################################
308
-# Prepare index to have a tree to be committed
309
-
310
-case "$all,$also" in
311
-t,)
312
- if test ! -f "$THIS_INDEX"
313
- then
314
- die 'nothing to commit (use "git add file1 file2" to include for commit)'
315
- fi
316
- save_index &&
317
- (
318
- cd_to_toplevel &&
319
- GIT_INDEX_FILE="$NEXT_INDEX" &&
320
- export GIT_INDEX_FILE &&
321
- git diff-files --name-only -z |
322
- git update-index --remove -z --stdin
323
- ) || exit
324
- ;;
325
-,t)
326
- save_index &&
327
- git ls-files --error-unmatch -- "$@" >/dev/null || exit
328
-
329
- git diff-files --name-only -z -- "$@" |
330
- (
331
- cd_to_toplevel &&
332
- GIT_INDEX_FILE="$NEXT_INDEX" &&
333
- export GIT_INDEX_FILE &&
334
- git update-index --remove -z --stdin
335
- ) || exit
336
- ;;
337
-,)
338
- if test "$interactive" = t; then
339
- git add --interactive || exit
340
- fi
341
- case "$#" in
342
- 0)
343
- ;; # commit as-is
344
- *)
345
- if test -f "$GIT_DIR/MERGE_HEAD"
346
- then
347
- refuse_partial "Cannot do a partial commit during a merge."
348
- fi
349
-
350
- TMP_INDEX="$GIT_DIR/tmp-index$$"
351
- W=
352
- test -z "$initial_commit" && W=--with-tree=HEAD
353
- commit_only=$(git ls-files --error-unmatch $W -- "$@") || exit
354
-
355
- # Build a temporary index and update the real index
356
- # the same way.
357
- if test -z "$initial_commit"
358
- then
359
- GIT_INDEX_FILE="$THIS_INDEX" \
360
- git read-tree --index-output="$TMP_INDEX" -i -m HEAD
361
- else
362
- rm -f "$TMP_INDEX"
363
- fi || exit
364
-
365
- printf '%s\n' "$commit_only" |
366
- GIT_INDEX_FILE="$TMP_INDEX" \
367
- git update-index --add --remove --stdin &&
368
-
369
- save_index &&
370
- printf '%s\n' "$commit_only" |
371
- (
372
- GIT_INDEX_FILE="$NEXT_INDEX"
373
- export GIT_INDEX_FILE
374
- git update-index --add --remove --stdin
375
- ) || exit
376
- ;;
377
- esac
378
- ;;
379
-esac
380
-
381
-################################################################
382
-# If we do as-is commit, the index file will be THIS_INDEX,
383
-# otherwise NEXT_INDEX after we make this commit. We leave
384
-# the index as is if we abort.
385
-
386
-if test -f "$NEXT_INDEX"
387
-then
388
- USE_INDEX="$NEXT_INDEX"
389
-else
390
- USE_INDEX="$THIS_INDEX"
391
-fi
392
-
393
-case "$status_only" in
394
-t)
395
- # This will silently fail in a read-only repository, which is
396
- # what we want.
397
- GIT_INDEX_FILE="$USE_INDEX" git update-index -q --unmerged --refresh
398
- run_status
399
- exit $?
400
- ;;
401
-'')
402
- GIT_INDEX_FILE="$USE_INDEX" git update-index -q --refresh || exit
403
- ;;
404
-esac
405
-
406
-################################################################
407
-# Grab commit message, write out tree and make commit.
408
-
409
-if test t = "$verify" && test -x "$GIT_DIR"/hooks/pre-commit
410
-then
411
- GIT_INDEX_FILE="${TMP_INDEX:-${USE_INDEX}}" "$GIT_DIR"/hooks/pre-commit \
412
- || exit
413
-fi
414
-
415
-if test "$log_message" != ''
416
-then
417
- printf '%s\n' "$log_message"
418
-elif test "$logfile" != ""
419
-then
420
- if test "$logfile" = -
421
- then
422
- test -t 0 &&
423
- echo >&2 "(reading log message from standard input)"
424
- cat
425
- else
426
- cat <"$logfile"
427
- fi
428
-elif test "$use_commit" != ""
429
-then
430
- encoding=$(git config i18n.commitencoding || echo UTF-8)
431
- git show -s --pretty=raw --encoding="$encoding" "$use_commit" |
432
- sed -e '1,/^$/d' -e 's/^ //'
433
-elif test -f "$GIT_DIR/MERGE_MSG"
434
-then
435
- cat "$GIT_DIR/MERGE_MSG"
436
-elif test -f "$GIT_DIR/SQUASH_MSG"
437
-then
438
- cat "$GIT_DIR/SQUASH_MSG"
439
-elif test "$templatefile" != ""
440
-then
441
- cat "$templatefile"
442
-fi | git stripspace >"$GIT_DIR"/COMMIT_EDITMSG
443
-
444
-case "$signoff" in
445
-t)
446
- sign=$(git var GIT_COMMITTER_IDENT | sed -e '
447
- s/>.*/>/
448
- s/^/Signed-off-by: /
449
- ')
450
- blank_before_signoff=
451
- tail -n 1 "$GIT_DIR"/COMMIT_EDITMSG |
452
- grep 'Signed-off-by:' >/dev/null || blank_before_signoff='
453
-'
454
- tail -n 1 "$GIT_DIR"/COMMIT_EDITMSG |
455
- grep "$sign"$ >/dev/null ||
456
- printf '%s%s\n' "$blank_before_signoff" "$sign" \
457
- >>"$GIT_DIR"/COMMIT_EDITMSG
458
- ;;
459
-esac
460
-
461
-if test -f "$GIT_DIR/MERGE_HEAD" && test -z "$no_edit"; then
462
- echo "#"
463
- echo "# It looks like you may be committing a MERGE."
464
- echo "# If this is not correct, please remove the file"
465
- printf '%s\n' "# $GIT_DIR/MERGE_HEAD"
466
- echo "# and try again"
467
- echo "#"
468
-fi >>"$GIT_DIR"/COMMIT_EDITMSG
469
-
470
-# Author
471
-if test '' != "$use_commit"
472
-then
473
- eval "$(get_author_ident_from_commit "$use_commit")"
474
- export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE
475
-fi
476
-if test '' != "$force_author"
477
-then
478
- GIT_AUTHOR_NAME=$(expr "z$force_author" : 'z\(.*[^ ]\) *<.*') &&
479
- GIT_AUTHOR_EMAIL=$(expr "z$force_author" : '.*\(<.*\)') &&
480
- test '' != "$GIT_AUTHOR_NAME" &&
481
- test '' != "$GIT_AUTHOR_EMAIL" ||
482
- die "malformed --author parameter"
483
- export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
484
-fi
485
-
486
-PARENTS="-p HEAD"
487
-if test -z "$initial_commit"
488
-then
489
- rloga='commit'
490
- if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
491
- rloga='commit (merge)'
492
- PARENTS="-p HEAD "$(sed -e 's/^/-p /' "$GIT_DIR/MERGE_HEAD")
493
- elif test -n "$amend"; then
494
- rloga='commit (amend)'
495
- PARENTS=$(git cat-file commit HEAD |
496
- sed -n -e '/^$/q' -e 's/^parent /-p /p')
497
- fi
498
- current="$(git rev-parse --verify HEAD)"
499
-else
500
- if [ -z "$(git ls-files)" ]; then
501
- echo >&2 'nothing to commit (use "git add file1 file2" to include for commit)'
502
- exit 1
503
- fi
504
- PARENTS=""
505
- rloga='commit (initial)'
506
- current=''
507
-fi
508
-set_reflog_action "$rloga"
509
-
510
-if test -z "$no_edit"
511
-then
512
- {
513
- echo ""
514
- echo "# Please enter the commit message for your changes."
515
- echo "# (Comment lines starting with '#' will not be included)"
516
- test -z "$only_include_assumed" || echo "$only_include_assumed"
517
- run_status
518
- } >>"$GIT_DIR"/COMMIT_EDITMSG
519
-else
520
- # we need to check if there is anything to commit
521
- run_status >/dev/null
522
-fi
523
-case "$allow_empty,$?,$PARENTS" in
524
-t,* | ?,0,* | ?,*,-p' '?*-p' '?*)
525
- # an explicit --allow-empty, or a merge commit can record the
526
- # same tree as its parent. Otherwise having commitable paths
527
- # is required.
528
- ;;
529
-*)
530
- rm -f "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG"
531
- use_status_color=t
532
- run_status
533
- exit 1
534
-esac
535
-
536
-case "$no_edit" in
537
-'')
538
- git var GIT_AUTHOR_IDENT > /dev/null || die
539
- git var GIT_COMMITTER_IDENT > /dev/null || die
540
- git_editor "$GIT_DIR/COMMIT_EDITMSG"
541
- ;;
542
-esac
543
-
544
-case "$verify" in
545
-t)
546
- if test -x "$GIT_DIR"/hooks/commit-msg
547
- then
548
- "$GIT_DIR"/hooks/commit-msg "$GIT_DIR"/COMMIT_EDITMSG || exit
549
- fi
550
-esac
551
-
552
-if test -z "$no_edit"
553
-then
554
- sed -e '
555
- /^diff --git a\/.*/{
556
- s///
557
- q
558
- }
559
- /^#/d
560
- ' "$GIT_DIR"/COMMIT_EDITMSG
561
-else
562
- cat "$GIT_DIR"/COMMIT_EDITMSG
563
-fi |
564
-git stripspace >"$GIT_DIR"/COMMIT_MSG
565
-
566
-# Test whether the commit message has any content we didn't supply.
567
-have_commitmsg=
568
-grep -v -i '^Signed-off-by' "$GIT_DIR"/COMMIT_MSG |
569
- git stripspace > "$GIT_DIR"/COMMIT_BAREMSG
570
-
571
-# Is the commit message totally empty?
572
-if test -s "$GIT_DIR"/COMMIT_BAREMSG
573
-then
574
- if test "$templatefile" != ""
575
- then
576
- # Test whether this is just the unaltered template.
577
- if cnt=$(sed -e '/^#/d' < "$templatefile" |
578
- git stripspace |
579
- diff "$GIT_DIR"/COMMIT_BAREMSG - |
580
- wc -l) &&
581
- test 0 -lt $cnt
582
- then
583
- have_commitmsg=t
584
- fi
585
- else
586
- # No template, so the content in the commit message must
587
- # have come from the user.
588
- have_commitmsg=t
589
- fi
590
-fi
591
-
592
-rm -f "$GIT_DIR"/COMMIT_BAREMSG
593
-
594
-if test "$have_commitmsg" = "t"
595
-then
596
- if test -z "$TMP_INDEX"
597
- then
598
- tree=$(GIT_INDEX_FILE="$USE_INDEX" git write-tree)
599
- else
600
- tree=$(GIT_INDEX_FILE="$TMP_INDEX" git write-tree) &&
601
- rm -f "$TMP_INDEX"
602
- fi &&
603
- commit=$(git commit-tree $tree $PARENTS <"$GIT_DIR/COMMIT_MSG") &&
604
- rlogm=$(sed -e 1q "$GIT_DIR"/COMMIT_MSG) &&
605
- git update-ref -m "$GIT_REFLOG_ACTION: $rlogm" HEAD $commit "$current" &&
606
- rm -f -- "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/MERGE_MSG" &&
607
- if test -f "$NEXT_INDEX"
608
- then
609
- mv "$NEXT_INDEX" "$THIS_INDEX"
610
- else
611
- : ;# happy
612
- fi
613
-else
614
- echo >&2 "* no commit message? aborting commit."
615
- false
616
-fi
617
-ret="$?"
618
-rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG"
619
-
620
-cd_to_toplevel
621
-
622
-git rerere
623
-
624
-if test "$ret" = 0
625
-then
626
- git gc --auto
627
- if test -x "$GIT_DIR"/hooks/post-commit
628
- then
629
- "$GIT_DIR"/hooks/post-commit
630
- fi
631
- if test -z "$quiet"
632
- then
633
- commit=$(git diff-tree --always --shortstat --pretty="format:%h: %s"\
634
- --abbrev --summary --root HEAD --)
635
- echo "Created${initial_commit:+ initial} commit $commit"
636
- fi
637
-fi
638
-
639
-exit "$ret"
contrib/examples/git-difftool.perl
deleted
-481
@@ -1,481 +0,0 @@
1
-#!/usr/bin/perl
2
-# Copyright (c) 2009, 2010 David Aguilar
3
-# Copyright (c) 2012 Tim Henigan
4
-#
5
-# This is a wrapper around the GIT_EXTERNAL_DIFF-compatible
6
-# git-difftool--helper script.
7
-#
8
-# This script exports GIT_EXTERNAL_DIFF and GIT_PAGER for use by git.
9
-# The GIT_DIFF* variables are exported for use by git-difftool--helper.
10
-#
11
-# Any arguments that are unknown to this script are forwarded to 'git diff'.
12
-
13
-use 5.008;
14
-use strict;
15
-use warnings;
16
-use Git::LoadCPAN::Error qw(:try);
17
-use File::Basename qw(dirname);
18
-use File::Copy;
19
-use File::Find;
20
-use File::stat;
21
-use File::Path qw(mkpath rmtree);
22
-use File::Temp qw(tempdir);
23
-use Getopt::Long qw(:config pass_through);
24
-use Git;
25
-use Git::I18N;
26
-
27
-sub usage
28
-{
29
- my $exitcode = shift;
30
- print << 'USAGE';
31
-usage: git difftool [-t|--tool=<tool>] [--tool-help]
32
- [-x|--extcmd=<cmd>]
33
- [-g|--gui] [--no-gui]
34
- [--prompt] [-y|--no-prompt]
35
- [-d|--dir-diff]
36
- ['git diff' options]
37
-USAGE
38
- exit($exitcode);
39
-}
40
-
41
-sub print_tool_help
42
-{
43
- # See the comment at the bottom of file_diff() for the reason behind
44
- # using system() followed by exit() instead of exec().
45
- my $rc = system(qw(git mergetool --tool-help=diff));
46
- exit($rc | ($rc >> 8));
47
-}
48
-
49
-sub exit_cleanup
50
-{
51
- my ($tmpdir, $status) = @_;
52
- my $errno = $!;
53
- rmtree($tmpdir);
54
- if ($status and $errno) {
55
- my ($package, $file, $line) = caller();
56
- warn "$file line $line: $errno\n";
57
- }
58
- exit($status | ($status >> 8));
59
-}
60
-
61
-sub use_wt_file
62
-{
63
- my ($file, $sha1) = @_;
64
- my $null_sha1 = '0' x 40;
65
-
66
- if (-l $file || ! -e _) {
67
- return (0, $null_sha1);
68
- }
69
-
70
- my $wt_sha1 = Git::command_oneline('hash-object', $file);
71
- my $use = ($sha1 eq $null_sha1) || ($sha1 eq $wt_sha1);
72
- return ($use, $wt_sha1);
73
-}
74
-
75
-sub changed_files
76
-{
77
- my ($repo_path, $index, $worktree) = @_;
78
- $ENV{GIT_INDEX_FILE} = $index;
79
-
80
- my @gitargs = ('--git-dir', $repo_path, '--work-tree', $worktree);
81
- my @refreshargs = (
82
- @gitargs, 'update-index',
83
- '--really-refresh', '-q', '--unmerged');
84
- try {
85
- Git::command_oneline(@refreshargs);
86
- } catch Git::Error::Command with {};
87
-
88
- my @diffargs = (@gitargs, 'diff-files', '--name-only', '-z');
89
- my $line = Git::command_oneline(@diffargs);
90
- my @files;
91
- if (defined $line) {
92
- @files = split('\0', $line);
93
- } else {
94
- @files = ();
95
- }
96
-
97
- delete($ENV{GIT_INDEX_FILE});
98
-
99
- return map { $_ => 1 } @files;
100
-}
101
-
102
-sub setup_dir_diff
103
-{
104
- my ($worktree, $symlinks) = @_;
105
- my @gitargs = ('diff', '--raw', '--no-abbrev', '-z', @ARGV);
106
- my $diffrtn = Git::command_oneline(@gitargs);
107
- exit(0) unless defined($diffrtn);
108
-
109
- # Go to the root of the worktree now that we've captured the list of
110
- # changed files. The paths returned by diff --raw are relative to the
111
- # top-level of the repository, but we defer changing directories so
112
- # that @ARGV can perform pathspec limiting in the current directory.
113
- chdir($worktree);
114
-
115
- # Build index info for left and right sides of the diff
116
- my $submodule_mode = '160000';
117
- my $symlink_mode = '120000';
118
- my $null_mode = '0' x 6;
119
- my $null_sha1 = '0' x 40;
120
- my $lindex = '';
121
- my $rindex = '';
122
- my $wtindex = '';
123
- my %submodule;
124
- my %symlink;
125
- my @files = ();
126
- my %working_tree_dups = ();
127
- my @rawdiff = split('\0', $diffrtn);
128
-
129
- my $i = 0;
130
- while ($i < $#rawdiff) {
131
- if ($rawdiff[$i] =~ /^::/) {
132
- warn __ <<'EOF';
133
-Combined diff formats ('-c' and '--cc') are not supported in
134
-directory diff mode ('-d' and '--dir-diff').
135
-EOF
136
- exit(1);
137
- }
138
-
139
- my ($lmode, $rmode, $lsha1, $rsha1, $status) =
140
- split(' ', substr($rawdiff[$i], 1));
141
- my $src_path = $rawdiff[$i + 1];
142
- my $dst_path;
143
-
144
- if ($status =~ /^[CR]/) {
145
- $dst_path = $rawdiff[$i + 2];
146
- $i += 3;
147
- } else {
148
- $dst_path = $src_path;
149
- $i += 2;
150
- }
151
-
152
- if ($lmode eq $submodule_mode or $rmode eq $submodule_mode) {
153
- $submodule{$src_path}{left} = $lsha1;
154
- if ($lsha1 ne $rsha1) {
155
- $submodule{$dst_path}{right} = $rsha1;
156
- } else {
157
- $submodule{$dst_path}{right} = "$rsha1-dirty";
158
- }
159
- next;
160
- }
161
-
162
- if ($lmode eq $symlink_mode) {
163
- $symlink{$src_path}{left} =
164
- Git::command_oneline('show', $lsha1);
165
- }
166
-
167
- if ($rmode eq $symlink_mode) {
168
- $symlink{$dst_path}{right} =
169
- Git::command_oneline('show', $rsha1);
170
- }
171
-
172
- if ($lmode ne $null_mode and $status !~ /^C/) {
173
- $lindex .= "$lmode $lsha1\t$src_path\0";
174
- }
175
-
176
- if ($rmode ne $null_mode) {
177
- # Avoid duplicate entries
178
- if ($working_tree_dups{$dst_path}++) {
179
- next;
180
- }
181
- my ($use, $wt_sha1) =
182
- use_wt_file($dst_path, $rsha1);
183
- if ($use) {
184
- push @files, $dst_path;
185
- $wtindex .= "$rmode $wt_sha1\t$dst_path\0";
186
- } else {
187
- $rindex .= "$rmode $rsha1\t$dst_path\0";
188
- }
189
- }
190
- }
191
-
192
- # Go to the root of the worktree so that the left index files
193
- # are properly setup -- the index is toplevel-relative.
194
- chdir($worktree);
195
-
196
- # Setup temp directories
197
- my $tmpdir = tempdir('git-difftool.XXXXX', CLEANUP => 0, TMPDIR => 1);
198
- my $ldir = "$tmpdir/left";
199
- my $rdir = "$tmpdir/right";
200
- mkpath($ldir) or exit_cleanup($tmpdir, 1);
201
- mkpath($rdir) or exit_cleanup($tmpdir, 1);
202
-
203
- # Populate the left and right directories based on each index file
204
- my ($inpipe, $ctx);
205
- $ENV{GIT_INDEX_FILE} = "$tmpdir/lindex";
206
- ($inpipe, $ctx) =
207
- Git::command_input_pipe('update-index', '-z', '--index-info');
208
- print($inpipe $lindex);
209
- Git::command_close_pipe($inpipe, $ctx);
210
-
211
- my $rc = system('git', 'checkout-index', '--all', "--prefix=$ldir/");
212
- exit_cleanup($tmpdir, $rc) if $rc != 0;
213
-
214
- $ENV{GIT_INDEX_FILE} = "$tmpdir/rindex";
215
- ($inpipe, $ctx) =
216
- Git::command_input_pipe('update-index', '-z', '--index-info');
217
- print($inpipe $rindex);
218
- Git::command_close_pipe($inpipe, $ctx);
219
-
220
- $rc = system('git', 'checkout-index', '--all', "--prefix=$rdir/");
221
- exit_cleanup($tmpdir, $rc) if $rc != 0;
222
-
223
- $ENV{GIT_INDEX_FILE} = "$tmpdir/wtindex";
224
- ($inpipe, $ctx) =
225
- Git::command_input_pipe('update-index', '--info-only', '-z', '--index-info');
226
- print($inpipe $wtindex);
227
- Git::command_close_pipe($inpipe, $ctx);
228
-
229
- # If $GIT_DIR was explicitly set just for the update/checkout
230
- # commands, then it should be unset before continuing.
231
- delete($ENV{GIT_INDEX_FILE});
232
-
233
- # Changes in the working tree need special treatment since they are
234
- # not part of the index.
235
- for my $file (@files) {
236
- my $dir = dirname($file);
237
- unless (-d "$rdir/$dir") {
238
- mkpath("$rdir/$dir") or
239
- exit_cleanup($tmpdir, 1);
240
- }
241
- if ($symlinks) {
242
- symlink("$worktree/$file", "$rdir/$file") or
243
- exit_cleanup($tmpdir, 1);
244
- } else {
245
- copy($file, "$rdir/$file") or
246
- exit_cleanup($tmpdir, 1);
247
-
248
- my $mode = stat($file)->mode;
249
- chmod($mode, "$rdir/$file") or
250
- exit_cleanup($tmpdir, 1);
251
- }
252
- }
253
-
254
- # Changes to submodules require special treatment. This loop writes a
255
- # temporary file to both the left and right directories to show the
256
- # change in the recorded SHA1 for the submodule.
257
- for my $path (keys %submodule) {
258
- my $ok = 0;
259
- if (defined($submodule{$path}{left})) {
260
- $ok = write_to_file("$ldir/$path",
261
- "Subproject commit $submodule{$path}{left}");
262
- }
263
- if (defined($submodule{$path}{right})) {
264
- $ok = write_to_file("$rdir/$path",
265
- "Subproject commit $submodule{$path}{right}");
266
- }
267
- exit_cleanup($tmpdir, 1) if not $ok;
268
- }
269
-
270
- # Symbolic links require special treatment. The standard "git diff"
271
- # shows only the link itself, not the contents of the link target.
272
- # This loop replicates that behavior.
273
- for my $path (keys %symlink) {
274
- my $ok = 0;
275
- if (defined($symlink{$path}{left})) {
276
- $ok = write_to_file("$ldir/$path",
277
- $symlink{$path}{left});
278
- }
279
- if (defined($symlink{$path}{right})) {
280
- $ok = write_to_file("$rdir/$path",
281
- $symlink{$path}{right});
282
- }
283
- exit_cleanup($tmpdir, 1) if not $ok;
284
- }
285
-
286
- return ($ldir, $rdir, $tmpdir, @files);
287
-}
288
-
289
-sub write_to_file
290
-{
291
- my $path = shift;
292
- my $value = shift;
293
-
294
- # Make sure the path to the file exists
295
- my $dir = dirname($path);
296
- unless (-d "$dir") {
297
- mkpath("$dir") or return 0;
298
- }
299
-
300
- # If the file already exists in that location, delete it. This
301
- # is required in the case of symbolic links.
302
- unlink($path);
303
-
304
- open(my $fh, '>', $path) or return 0;
305
- print($fh $value);
306
- close($fh);
307
-
308
- return 1;
309
-}
310
-
311
-sub main
312
-{
313
- # parse command-line options. all unrecognized options and arguments
314
- # are passed through to the 'git diff' command.
315
- my %opts = (
316
- difftool_cmd => undef,
317
- dirdiff => undef,
318
- extcmd => undef,
319
- gui => undef,
320
- help => undef,
321
- prompt => undef,
322
- symlinks => $^O ne 'cygwin' &&
323
- $^O ne 'MSWin32' && $^O ne 'msys',
324
- tool_help => undef,
325
- trust_exit_code => undef,
326
- );
327
- GetOptions('g|gui!' => \$opts{gui},
328
- 'd|dir-diff' => \$opts{dirdiff},
329
- 'h' => \$opts{help},
330
- 'prompt!' => \$opts{prompt},
331
- 'y' => sub { $opts{prompt} = 0; },
332
- 'symlinks' => \$opts{symlinks},
333
- 'no-symlinks' => sub { $opts{symlinks} = 0; },
334
- 't|tool:s' => \$opts{difftool_cmd},
335
- 'tool-help' => \$opts{tool_help},
336
- 'trust-exit-code' => \$opts{trust_exit_code},
337
- 'no-trust-exit-code' => sub { $opts{trust_exit_code} = 0; },
338
- 'x|extcmd:s' => \$opts{extcmd});
339
-
340
- if (defined($opts{help})) {
341
- usage(0);
342
- }
343
- if (defined($opts{tool_help})) {
344
- print_tool_help();
345
- }
346
- if (defined($opts{difftool_cmd})) {
347
- if (length($opts{difftool_cmd}) > 0) {
348
- $ENV{GIT_DIFF_TOOL} = $opts{difftool_cmd};
349
- } else {
350
- print __("No <tool> given for --tool=<tool>\n");
351
- usage(1);
352
- }
353
- }
354
- if (defined($opts{extcmd})) {
355
- if (length($opts{extcmd}) > 0) {
356
- $ENV{GIT_DIFFTOOL_EXTCMD} = $opts{extcmd};
357
- } else {
358
- print __("No <cmd> given for --extcmd=<cmd>\n");
359
- usage(1);
360
- }
361
- }
362
- if ($opts{gui}) {
363
- my $guitool = Git::config('diff.guitool');
364
- if (defined($guitool) && length($guitool) > 0) {
365
- $ENV{GIT_DIFF_TOOL} = $guitool;
366
- }
367
- }
368
-
369
- if (!defined $opts{trust_exit_code}) {
370
- $opts{trust_exit_code} = Git::config_bool('difftool.trustExitCode');
371
- }
372
- if ($opts{trust_exit_code}) {
373
- $ENV{GIT_DIFFTOOL_TRUST_EXIT_CODE} = 'true';
374
- } else {
375
- $ENV{GIT_DIFFTOOL_TRUST_EXIT_CODE} = 'false';
376
- }
377
-
378
- # In directory diff mode, 'git-difftool--helper' is called once
379
- # to compare the a/b directories. In file diff mode, 'git diff'
380
- # will invoke a separate instance of 'git-difftool--helper' for
381
- # each file that changed.
382
- if (defined($opts{dirdiff})) {
383
- dir_diff($opts{extcmd}, $opts{symlinks});
384
- } else {
385
- file_diff($opts{prompt});
386
- }
387
-}
388
-
389
-sub dir_diff
390
-{
391
- my ($extcmd, $symlinks) = @_;
392
- my $rc;
393
- my $error = 0;
394
- my $repo = Git->repository();
395
- my $repo_path = $repo->repo_path();
396
- my $worktree = $repo->wc_path();
397
- $worktree =~ s|/$||; # Avoid double slashes in symlink targets
398
- my ($a, $b, $tmpdir, @files) = setup_dir_diff($worktree, $symlinks);
399
-
400
- if (defined($extcmd)) {
401
- $rc = system($extcmd, $a, $b);
402
- } else {
403
- $ENV{GIT_DIFFTOOL_DIRDIFF} = 'true';
404
- $rc = system('git', 'difftool--helper', $a, $b);
405
- }
406
- # If the diff including working copy files and those
407
- # files were modified during the diff, then the changes
408
- # should be copied back to the working tree.
409
- # Do not copy back files when symlinks are used and the
410
- # external tool did not replace the original link with a file.
411
- #
412
- # These hashes are loaded lazily since they aren't needed
413
- # in the common case of --symlinks and the difftool updating
414
- # files through the symlink.
415
- my %wt_modified;
416
- my %tmp_modified;
417
- my $indices_loaded = 0;
418
-
419
- for my $file (@files) {
420
- next if $symlinks && -l "$b/$file";
421
- next if ! -f "$b/$file";
422
-
423
- if (!$indices_loaded) {
424
- %wt_modified = changed_files(
425
- $repo_path, "$tmpdir/wtindex", $worktree);
426
- %tmp_modified = changed_files(
427
- $repo_path, "$tmpdir/wtindex", $b);
428
- $indices_loaded = 1;
429
- }
430
-
431
- if (exists $wt_modified{$file} and exists $tmp_modified{$file}) {
432
- warn sprintf(__(
433
- "warning: Both files modified:\n" .
434
- "'%s/%s' and '%s/%s'.\n" .
435
- "warning: Working tree file has been left.\n" .
436
- "warning:\n"), $worktree, $file, $b, $file);
437
- $error = 1;
438
- } elsif (exists $tmp_modified{$file}) {
439
- my $mode = stat("$b/$file")->mode;
440
- copy("$b/$file", $file) or
441
- exit_cleanup($tmpdir, 1);
442
-
443
- chmod($mode, $file) or
444
- exit_cleanup($tmpdir, 1);
445
- }
446
- }
447
- if ($error) {
448
- warn sprintf(__(
449
- "warning: Temporary files exist in '%s'.\n" .
450
- "warning: You may want to cleanup or recover these.\n"), $tmpdir);
451
- exit(1);
452
- } else {
453
- exit_cleanup($tmpdir, $rc);
454
- }
455
-}
456
-
457
-sub file_diff
458
-{
459
- my ($prompt) = @_;
460
-
461
- if (defined($prompt)) {
462
- if ($prompt) {
463
- $ENV{GIT_DIFFTOOL_PROMPT} = 'true';
464
- } else {
465
- $ENV{GIT_DIFFTOOL_NO_PROMPT} = 'true';
466
- }
467
- }
468
-
469
- $ENV{GIT_PAGER} = '';
470
- $ENV{GIT_EXTERNAL_DIFF} = 'git-difftool--helper';
471
-
472
- # ActiveState Perl for Win32 does not implement POSIX semantics of
473
- # exec* system call. It just spawns the given executable and finishes
474
- # the starting program, exiting with code 0.
475
- # system will at least catch the errors returned by git diff,
476
- # allowing the caller of git difftool better handling of failures.
477
- my $rc = system('git', 'diff', @ARGV);
478
- exit($rc | ($rc >> 8));
479
-}
480
-
481
-main();
contrib/examples/git-fetch.sh
deleted
-379
@@ -1,379 +0,0 @@
1
-#!/bin/sh
2
-#
3
-
4
-USAGE='<fetch-options> <repository> <refspec>...'
5
-SUBDIRECTORY_OK=Yes
6
-. git-sh-setup
7
-set_reflog_action "fetch $*"
8
-cd_to_toplevel ;# probably unnecessary...
9
-
10
-. git-parse-remote
11
-_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
12
-_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
13
-
14
-LF='
15
-'
16
-IFS="$LF"
17
-
18
-no_tags=
19
-tags=
20
-append=
21
-force=
22
-verbose=
23
-update_head_ok=
24
-exec=
25
-keep=
26
-shallow_depth=
27
-no_progress=
28
-test -t 1 || no_progress=--no-progress
29
-quiet=
30
-while test $# != 0
31
-do
32
- case "$1" in
33
- -a|--a|--ap|--app|--appe|--appen|--append)
34
- append=t
35
- ;;
36
- --upl|--uplo|--uploa|--upload|--upload-|--upload-p|\
37
- --upload-pa|--upload-pac|--upload-pack)
38
- shift
39
- exec="--upload-pack=$1"
40
- ;;
41
- --upl=*|--uplo=*|--uploa=*|--upload=*|\
42
- --upload-=*|--upload-p=*|--upload-pa=*|--upload-pac=*|--upload-pack=*)
43
- exec=--upload-pack=$(expr "z$1" : 'z-[^=]*=\(.*\)')
44
- shift
45
- ;;
46
- -f|--f|--fo|--for|--forc|--force)
47
- force=t
48
- ;;
49
- -t|--t|--ta|--tag|--tags)
50
- tags=t
51
- ;;
52
- -n|--n|--no|--no-|--no-t|--no-ta|--no-tag|--no-tags)
53
- no_tags=t
54
- ;;
55
- -u|--u|--up|--upd|--upda|--updat|--update|--update-|--update-h|\
56
- --update-he|--update-hea|--update-head|--update-head-|\
57
- --update-head-o|--update-head-ok)
58
- update_head_ok=t
59
- ;;
60
- -q|--q|--qu|--qui|--quie|--quiet)
61
- quiet=--quiet
62
- ;;
63
- -v|--verbose)
64
- verbose="$verbose"Yes
65
- ;;
66
- -k|--k|--ke|--kee|--keep)
67
- keep='-k -k'
68
- ;;
69
- --depth=*)
70
- shallow_depth="--depth=$(expr "z$1" : 'z-[^=]*=\(.*\)')"
71
- ;;
72
- --depth)
73
- shift
74
- shallow_depth="--depth=$1"
75
- ;;
76
- -*)
77
- usage
78
- ;;
79
- *)
80
- break
81
- ;;
82
- esac
83
- shift
84
-done
85
-
86
-case "$#" in
87
-0)
88
- origin=$(get_default_remote)
89
- test -n "$(get_remote_url ${origin})" ||
90
- die "Where do you want to fetch from today?"
91
- set x $origin ; shift ;;
92
-esac
93
-
94
-if test -z "$exec"
95
-then
96
- # No command line override and we have configuration for the remote.
97
- exec="--upload-pack=$(get_uploadpack $1)"
98
-fi
99
-
100
-remote_nick="$1"
101
-remote=$(get_remote_url "$@")
102
-refs=
103
-rref=
104
-rsync_slurped_objects=
105
-
106
-if test "" = "$append"
107
-then
108
- : >"$GIT_DIR/FETCH_HEAD"
109
-fi
110
-
111
-# Global that is reused later
112
-ls_remote_result=$(git ls-remote $exec "$remote") ||
113
- die "Cannot get the repository state from $remote"
114
-
115
-append_fetch_head () {
116
- flags=
117
- test -n "$verbose" && flags="$flags$LF-v"
118
- test -n "$force$single_force" && flags="$flags$LF-f"
119
- GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION" \
120
- git fetch--tool $flags append-fetch-head "$@"
121
-}
122
-
123
-# updating the current HEAD with git-fetch in a bare
124
-# repository is always fine.
125
-if test -z "$update_head_ok" && test $(is_bare_repository) = false
126
-then
127
- orig_head=$(git rev-parse --verify HEAD 2>/dev/null)
128
-fi
129
-
130
-# Allow --tags/--notags from remote.$1.tagopt
131
-case "$tags$no_tags" in
132
-'')
133
- case "$(git config --get "remote.$1.tagopt")" in
134
- --tags)
135
- tags=t ;;
136
- --no-tags)
137
- no_tags=t ;;
138
- esac
139
-esac
140
-
141
-# If --tags (and later --heads or --all) is specified, then we are
142
-# not talking about defaults stored in Pull: line of remotes or
143
-# branches file, and just fetch those and refspecs explicitly given.
144
-# Otherwise we do what we always did.
145
-
146
-reflist=$(get_remote_refs_for_fetch "$@")
147
-if test "$tags"
148
-then
149
- taglist=$(IFS=' ' &&
150
- echo "$ls_remote_result" |
151
- git show-ref --exclude-existing=refs/tags/ |
152
- while read sha1 name
153
- do
154
- echo ".${name}:${name}"
155
- done) || exit
156
- if test "$#" -gt 1
157
- then
158
- # remote URL plus explicit refspecs; we need to merge them.
159
- reflist="$reflist$LF$taglist"
160
- else
161
- # No explicit refspecs; fetch tags only.
162
- reflist=$taglist
163
- fi
164
-fi
165
-
166
-fetch_all_at_once () {
167
-
168
- eval=$(echo "$1" | git fetch--tool parse-reflist "-")
169
- eval "$eval"
170
-
171
- ( : subshell because we muck with IFS
172
- IFS=" $LF"
173
- (
174
- if test "$remote" = . ; then
175
- git show-ref $rref || echo failed "$remote"
176
- elif test -f "$remote" ; then
177
- test -n "$shallow_depth" &&
178
- die "shallow clone with bundle is not supported"
179
- git bundle unbundle "$remote" $rref ||
180
- echo failed "$remote"
181
- else
182
- if test -d "$remote" &&
183
-
184
- # The remote might be our alternate. With
185
- # this optimization we will bypass fetch-pack
186
- # altogether, which means we cannot be doing
187
- # the shallow stuff at all.
188
- test ! -f "$GIT_DIR/shallow" &&
189
- test -z "$shallow_depth" &&
190
-
191
- # See if all of what we are going to fetch are
192
- # connected to our repository's tips, in which
193
- # case we do not have to do any fetch.
194
- theirs=$(echo "$ls_remote_result" | \
195
- git fetch--tool -s pick-rref "$rref" "-") &&
196
-
197
- # This will barf when $theirs reach an object that
198
- # we do not have in our repository. Otherwise,
199
- # we already have everything the fetch would bring in.
200
- git rev-list --objects $theirs --not --all \
201
- >/dev/null 2>/dev/null
202
- then
203
- echo "$ls_remote_result" | \
204
- git fetch--tool pick-rref "$rref" "-"
205
- else
206
- flags=
207
- case $verbose in
208
- YesYes*)
209
- flags="-v"
210
- ;;
211
- esac
212
- git-fetch-pack --thin $exec $keep $shallow_depth \
213
- $quiet $no_progress $flags "$remote" $rref ||
214
- echo failed "$remote"
215
- fi
216
- fi
217
- ) |
218
- (
219
- flags=
220
- test -n "$verbose" && flags="$flags -v"
221
- test -n "$force" && flags="$flags -f"
222
- GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION" \
223
- git fetch--tool $flags native-store \
224
- "$remote" "$remote_nick" "$refs"
225
- )
226
- ) || exit
227
-
228
-}
229
-
230
-fetch_per_ref () {
231
- reflist="$1"
232
- refs=
233
- rref=
234
-
235
- for ref in $reflist
236
- do
237
- refs="$refs$LF$ref"
238
-
239
- # These are relative path from $GIT_DIR, typically starting at refs/
240
- # but may be HEAD
241
- if expr "z$ref" : 'z\.' >/dev/null
242
- then
243
- not_for_merge=t
244
- ref=$(expr "z$ref" : 'z\.\(.*\)')
245
- else
246
- not_for_merge=
247
- fi
248
- if expr "z$ref" : 'z+' >/dev/null
249
- then
250
- single_force=t
251
- ref=$(expr "z$ref" : 'z+\(.*\)')
252
- else
253
- single_force=
254
- fi
255
- remote_name=$(expr "z$ref" : 'z\([^:]*\):')
256
- local_name=$(expr "z$ref" : 'z[^:]*:\(.*\)')
257
-
258
- rref="$rref$LF$remote_name"
259
-
260
- # There are transports that can fetch only one head at a time...
261
- case "$remote" in
262
- http://* | https://* | ftp://*)
263
- test -n "$shallow_depth" &&
264
- die "shallow clone with http not supported"
265
- proto=$(expr "$remote" : '\([^:]*\):')
266
- if [ -n "$GIT_SSL_NO_VERIFY" ]; then
267
- curl_extra_args="-k"
268
- fi
269
- if [ -n "$GIT_CURL_FTP_NO_EPSV" -o \
270
- "$(git config --bool http.noEPSV)" = true ]; then
271
- noepsv_opt="--disable-epsv"
272
- fi
273
-
274
- # Find $remote_name from ls-remote output.
275
- head=$(echo "$ls_remote_result" | \
276
- git fetch--tool -s pick-rref "$remote_name" "-")
277
- expr "z$head" : "z$_x40\$" >/dev/null ||
278
- die "No such ref $remote_name at $remote"
279
- echo >&2 "Fetching $remote_name from $remote using $proto"
280
- case "$quiet" in '') v=-v ;; *) v= ;; esac
281
- git-http-fetch $v -a "$head" "$remote" || exit
282
- ;;
283
- rsync://*)
284
- test -n "$shallow_depth" &&
285
- die "shallow clone with rsync not supported"
286
- TMP_HEAD="$GIT_DIR/TMP_HEAD"
287
- rsync -L -q "$remote/$remote_name" "$TMP_HEAD" || exit 1
288
- head=$(git rev-parse --verify TMP_HEAD)
289
- rm -f "$TMP_HEAD"
290
- case "$quiet" in '') v=-v ;; *) v= ;; esac
291
- test "$rsync_slurped_objects" || {
292
- rsync -a $v --ignore-existing --exclude info \
293
- "$remote/objects/" "$GIT_OBJECT_DIRECTORY/" || exit
294
-
295
- # Look at objects/info/alternates for rsync -- http will
296
- # support it natively and git native ones will do it on
297
- # the remote end. Not having that file is not a crime.
298
- rsync -q "$remote/objects/info/alternates" \
299
- "$GIT_DIR/TMP_ALT" 2>/dev/null ||
300
- rm -f "$GIT_DIR/TMP_ALT"
301
- if test -f "$GIT_DIR/TMP_ALT"
302
- then
303
- resolve_alternates "$remote" <"$GIT_DIR/TMP_ALT" |
304
- while read alt
305
- do
306
- case "$alt" in 'bad alternate: '*) die "$alt";; esac
307
- echo >&2 "Getting alternate: $alt"
308
- rsync -av --ignore-existing --exclude info \
309
- "$alt" "$GIT_OBJECT_DIRECTORY/" || exit
310
- done
311
- rm -f "$GIT_DIR/TMP_ALT"
312
- fi
313
- rsync_slurped_objects=t
314
- }
315
- ;;
316
- esac
317
-
318
- append_fetch_head "$head" "$remote" \
319
- "$remote_name" "$remote_nick" "$local_name" "$not_for_merge" || exit
320
-
321
- done
322
-
323
-}
324
-
325
-fetch_main () {
326
- case "$remote" in
327
- http://* | https://* | ftp://* | rsync://* )
328
- fetch_per_ref "$@"
329
- ;;
330
- *)
331
- fetch_all_at_once "$@"
332
- ;;
333
- esac
334
-}
335
-
336
-fetch_main "$reflist" || exit
337
-
338
-# automated tag following
339
-case "$no_tags$tags" in
340
-'')
341
- case "$reflist" in
342
- *:refs/*)
343
- # effective only when we are following remote branch
344
- # using local tracking branch.
345
- taglist=$(IFS=' ' &&
346
- echo "$ls_remote_result" |
347
- git show-ref --exclude-existing=refs/tags/ |
348
- while read sha1 name
349
- do
350
- git cat-file -t "$sha1" >/dev/null 2>&1 || continue
351
- echo >&2 "Auto-following $name"
352
- echo ".${name}:${name}"
353
- done)
354
- esac
355
- case "$taglist" in
356
- '') ;;
357
- ?*)
358
- # do not deepen a shallow tree when following tags
359
- shallow_depth=
360
- fetch_main "$taglist" || exit ;;
361
- esac
362
-esac
363
-
364
-# If the original head was empty (i.e. no "master" yet), or
365
-# if we were told not to worry, we do not have to check.
366
-case "$orig_head" in
367
-'')
368
- ;;
369
-?*)
370
- curr_head=$(git rev-parse --verify HEAD 2>/dev/null)
371
- if test "$curr_head" != "$orig_head"
372
- then
373
- git update-ref \
374
- -m "$GIT_REFLOG_ACTION: Undoing incorrectly fetched HEAD." \
375
- HEAD "$orig_head"
376
- die "Cannot fetch into the current branch."
377
- fi
378
- ;;
379
-esac
contrib/examples/git-gc.sh
deleted
-37
@@ -1,37 +0,0 @@
1
-#!/bin/sh
2
-#
3
-# Copyright (c) 2006, Shawn O. Pearce
4
-#
5
-# Cleanup unreachable files and optimize the repository.
6
-
7
-USAGE='[--prune]'
8
-SUBDIRECTORY_OK=Yes
9
-. git-sh-setup
10
-
11
-no_prune=:
12
-while test $# != 0
13
-do
14
- case "$1" in
15
- --prune)
16
- no_prune=
17
- ;;
18
- --)
19
- usage
20
- ;;
21
- esac
22
- shift
23
-done
24
-
25
-case "$(git config --get gc.packrefs)" in
26
-notbare|"")
27
- test $(is_bare_repository) = true || pack_refs=true;;
28
-*)
29
- pack_refs=$(git config --bool --get gc.packrefs)
30
-esac
31
-
32
-test "true" != "$pack_refs" ||
33
-git pack-refs --prune &&
34
-git reflog expire --all &&
35
-git-repack -a -d -l &&
36
-$no_prune git prune &&
37
-git rerere gc || exit
contrib/examples/git-log.sh
deleted
-15
@@ -1,15 +0,0 @@
1
-#!/bin/sh
2
-#
3
-# Copyright (c) 2005 Linus Torvalds
4
-#
5
-
6
-USAGE='[--max-count=<n>] [<since>..<limit>] [--pretty=<format>] [git-rev-list options]'
7
-SUBDIRECTORY_OK='Yes'
8
-. git-sh-setup
9
-
10
-revs=$(git-rev-parse --revs-only --no-flags --default HEAD "$@") || exit
11
-[ "$revs" ] || {
12
- die "No HEAD ref"
13
-}
14
-git-rev-list --pretty $(git-rev-parse --default HEAD "$@") |
15
-LESS=-S ${PAGER:-less}
contrib/examples/git-ls-remote.sh
deleted
-142
@@ -1,142 +0,0 @@
1
-#!/bin/sh
2
-#
3
-
4
-usage () {
5
- echo >&2 "usage: $0 [--heads] [--tags] [-u|--upload-pack <upload-pack>]"
6
- echo >&2 " <repository> <refs>..."
7
- exit 1;
8
-}
9
-
10
-die () {
11
- echo >&2 "$*"
12
- exit 1
13
-}
14
-
15
-exec=
16
-while test $# != 0
17
-do
18
- case "$1" in
19
- -h|--h|--he|--hea|--head|--heads)
20
- heads=heads; shift ;;
21
- -t|--t|--ta|--tag|--tags)
22
- tags=tags; shift ;;
23
- -u|--u|--up|--upl|--uploa|--upload|--upload-|--upload-p|--upload-pa|\
24
- --upload-pac|--upload-pack)
25
- shift
26
- exec="--upload-pack=$1"
27
- shift;;
28
- -u=*|--u=*|--up=*|--upl=*|--uplo=*|--uploa=*|--upload=*|\
29
- --upload-=*|--upload-p=*|--upload-pa=*|--upload-pac=*|--upload-pack=*)
30
- exec=--upload-pack=$(expr "z$1" : 'z-[^=]*=\(.*\)')
31
- shift;;
32
- --)
33
- shift; break ;;
34
- -*)
35
- usage ;;
36
- *)
37
- break ;;
38
- esac
39
-done
40
-
41
-case "$#" in 0) usage ;; esac
42
-
43
-case ",$heads,$tags," in
44
-,,,) heads=heads tags=tags other=other ;;
45
-esac
46
-
47
-. git-parse-remote
48
-peek_repo="$(get_remote_url "$@")"
49
-shift
50
-
51
-tmp=.ls-remote-$$
52
-trap "rm -fr $tmp-*" 0 1 2 3 15
53
-tmpdir=$tmp-d
54
-
55
-case "$peek_repo" in
56
-http://* | https://* | ftp://* )
57
- if [ -n "$GIT_SSL_NO_VERIFY" -o \
58
- "$(git config --bool http.sslVerify)" = false ]; then
59
- curl_extra_args="-k"
60
- fi
61
- if [ -n "$GIT_CURL_FTP_NO_EPSV" -o \
62
- "$(git config --bool http.noEPSV)" = true ]; then
63
- curl_extra_args="${curl_extra_args} --disable-epsv"
64
- fi
65
- curl -nsf $curl_extra_args --header "Pragma: no-cache" "$peek_repo/info/refs" ||
66
- echo "failed slurping"
67
- ;;
68
-
69
-rsync://* )
70
- mkdir $tmpdir &&
71
- rsync -rlq "$peek_repo/HEAD" $tmpdir &&
72
- rsync -rq "$peek_repo/refs" $tmpdir || {
73
- echo "failed slurping"
74
- exit
75
- }
76
- head=$(cat "$tmpdir/HEAD") &&
77
- case "$head" in
78
- ref:' '*)
79
- head=$(expr "z$head" : 'zref: \(.*\)') &&
80
- head=$(cat "$tmpdir/$head") || exit
81
- esac &&
82
- echo "$head HEAD"
83
- (cd $tmpdir && find refs -type f) |
84
- while read path
85
- do
86
- tr -d '\012' <"$tmpdir/$path"
87
- echo " $path"
88
- done &&
89
- rm -fr $tmpdir
90
- ;;
91
-
92
-* )
93
- if test -f "$peek_repo" ; then
94
- git bundle list-heads "$peek_repo" ||
95
- echo "failed slurping"
96
- else
97
- git-peek-remote $exec "$peek_repo" ||
98
- echo "failed slurping"
99
- fi
100
- ;;
101
-esac |
102
-sort -t ' ' -k 2 |
103
-while read sha1 path
104
-do
105
- case "$sha1" in
106
- failed)
107
- exit 1 ;;
108
- esac
109
- case "$path" in
110
- refs/heads/*)
111
- group=heads ;;
112
- refs/tags/*)
113
- group=tags ;;
114
- *)
115
- group=other ;;
116
- esac
117
- case ",$heads,$tags,$other," in
118
- *,$group,*)
119
- ;;
120
- *)
121
- continue;;
122
- esac
123
- case "$#" in
124
- 0)
125
- match=yes ;;
126
- *)
127
- match=no
128
- for pat
129
- do
130
- case "/$path" in
131
- */$pat )
132
- match=yes
133
- break ;;
134
- esac
135
- done
136
- esac
137
- case "$match" in
138
- no)
139
- continue ;;
140
- esac
141
- echo "$sha1 $path"
142
-done
contrib/examples/git-merge-ours.sh
deleted
-14
@@ -1,14 +0,0 @@
1
-#!/bin/sh
2
-#
3
-# Copyright (c) 2005 Junio C Hamano
4
-#
5
-# Pretend we resolved the heads, but declare our tree trumps everybody else.
6
-#
7
-
8
-# We need to exit with 2 if the index does not match our HEAD tree,
9
-# because the current index is what we will be committing as the
10
-# merge result.
11
-
12
-git diff-index --quiet --cached HEAD -- || exit 2
13
-
14
-exit 0
contrib/examples/git-merge.sh
deleted
-620
@@ -1,620 +0,0 @@
1
-#!/bin/sh
2
-#
3
-# Copyright (c) 2005 Junio C Hamano
4
-#
5
-
6
-OPTIONS_KEEPDASHDASH=
7
-OPTIONS_SPEC="\
8
-git merge [options] <remote>...
9
-git merge [options] <msg> HEAD <remote>
10
---
11
-stat show a diffstat at the end of the merge
12
-n don't show a diffstat at the end of the merge
13
-summary (synonym to --stat)
14
-log add list of one-line log to merge commit message
15
-squash create a single commit instead of doing a merge
16
-commit perform a commit if the merge succeeds (default)
17
-ff allow fast-forward (default)
18
-ff-only abort if fast-forward is not possible
19
-rerere-autoupdate update index with any reused conflict resolution
20
-s,strategy= merge strategy to use
21
-X= option for selected merge strategy
22
-m,message= message to be used for the merge commit (if any)
23
-"
24
-
25
-SUBDIRECTORY_OK=Yes
26
-. git-sh-setup
27
-require_work_tree
28
-cd_to_toplevel
29
-
30
-test -z "$(git ls-files -u)" ||
31
- die "Merge is not possible because you have unmerged files."
32
-
33
-! test -e "$GIT_DIR/MERGE_HEAD" ||
34
- die 'You have not concluded your merge (MERGE_HEAD exists).'
35
-
36
-LF='
37
-'
38
-
39
-all_strategies='recur recursive octopus resolve stupid ours subtree'
40
-all_strategies="$all_strategies recursive-ours recursive-theirs"
41
-not_strategies='base file index tree'
42
-default_twohead_strategies='recursive'
43
-default_octopus_strategies='octopus'
44
-no_fast_forward_strategies='subtree ours'
45
-no_trivial_strategies='recursive recur subtree ours recursive-ours recursive-theirs'
46
-use_strategies=
47
-xopt=
48
-
49
-allow_fast_forward=t
50
-fast_forward_only=
51
-allow_trivial_merge=t
52
-squash= no_commit= log_arg= rr_arg=
53
-
54
-dropsave() {
55
- rm -f -- "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/MERGE_MSG" \
56
- "$GIT_DIR/MERGE_STASH" "$GIT_DIR/MERGE_MODE" || exit 1
57
-}
58
-
59
-savestate() {
60
- # Stash away any local modifications.
61
- git stash create >"$GIT_DIR/MERGE_STASH"
62
-}
63
-
64
-restorestate() {
65
- if test -f "$GIT_DIR/MERGE_STASH"
66
- then
67
- git reset --hard $head >/dev/null
68
- git stash apply $(cat "$GIT_DIR/MERGE_STASH")
69
- git update-index --refresh >/dev/null
70
- fi
71
-}
72
-
73
-finish_up_to_date () {
74
- case "$squash" in
75
- t)
76
- echo "$1 (nothing to squash)" ;;
77
- '')
78
- echo "$1" ;;
79
- esac
80
- dropsave
81
-}
82
-
83
-squash_message () {
84
- echo Squashed commit of the following:
85
- echo
86
- git log --no-merges --pretty=medium ^"$head" $remoteheads
87
-}
88
-
89
-finish () {
90
- if test '' = "$2"
91
- then
92
- rlogm="$GIT_REFLOG_ACTION"
93
- else
94
- echo "$2"
95
- rlogm="$GIT_REFLOG_ACTION: $2"
96
- fi
97
- case "$squash" in
98
- t)
99
- echo "Squash commit -- not updating HEAD"
100
- squash_message >"$GIT_DIR/SQUASH_MSG"
101
- ;;
102
- '')
103
- case "$merge_msg" in
104
- '')
105
- echo "No merge message -- not updating HEAD"
106
- ;;
107
- *)
108
- git update-ref -m "$rlogm" HEAD "$1" "$head" || exit 1
109
- git gc --auto
110
- ;;
111
- esac
112
- ;;
113
- esac
114
- case "$1" in
115
- '')
116
- ;;
117
- ?*)
118
- if test "$show_diffstat" = t
119
- then
120
- # We want color (if set), but no pager
121
- GIT_PAGER='' git diff --stat --summary -M "$head" "$1"
122
- fi
123
- ;;
124
- esac
125
-
126
- # Run a post-merge hook
127
- if test -x "$GIT_DIR"/hooks/post-merge
128
- then
129
- case "$squash" in
130
- t)
131
- "$GIT_DIR"/hooks/post-merge 1
132
- ;;
133
- '')
134
- "$GIT_DIR"/hooks/post-merge 0
135
- ;;
136
- esac
137
- fi
138
-}
139
-
140
-merge_name () {
141
- remote="$1"
142
- rh=$(git rev-parse --verify "$remote^0" 2>/dev/null) || return
143
- if truname=$(expr "$remote" : '\(.*\)~[0-9]*$') &&
144
- git show-ref -q --verify "refs/heads/$truname" 2>/dev/null
145
- then
146
- echo "$rh branch '$truname' (early part) of ."
147
- return
148
- fi
149
- if found_ref=$(git rev-parse --symbolic-full-name --verify \
150
- "$remote" 2>/dev/null)
151
- then
152
- expanded=$(git check-ref-format --branch "$remote") ||
153
- exit
154
- if test "${found_ref#refs/heads/}" != "$found_ref"
155
- then
156
- echo "$rh branch '$expanded' of ."
157
- return
158
- elif test "${found_ref#refs/remotes/}" != "$found_ref"
159
- then
160
- echo "$rh remote branch '$expanded' of ."
161
- return
162
- fi
163
- fi
164
- if test "$remote" = "FETCH_HEAD" && test -r "$GIT_DIR/FETCH_HEAD"
165
- then
166
- sed -e 's/ not-for-merge / /' -e 1q \
167
- "$GIT_DIR/FETCH_HEAD"
168
- return
169
- fi
170
- echo "$rh commit '$remote'"
171
-}
172
-
173
-parse_config () {
174
- while test $# != 0; do
175
- case "$1" in
176
- -n|--no-stat|--no-summary)
177
- show_diffstat=false ;;
178
- --stat|--summary)
179
- show_diffstat=t ;;
180
- --log|--no-log)
181
- log_arg=$1 ;;
182
- --squash)
183
- test "$allow_fast_forward" = t ||
184
- die "You cannot combine --squash with --no-ff."
185
- squash=t no_commit=t ;;
186
- --no-squash)
187
- squash= no_commit= ;;
188
- --commit)
189
- no_commit= ;;
190
- --no-commit)
191
- no_commit=t ;;
192
- --ff)
193
- allow_fast_forward=t ;;
194
- --no-ff)
195
- test "$squash" != t ||
196
- die "You cannot combine --squash with --no-ff."
197
- test "$fast_forward_only" != t ||
198
- die "You cannot combine --ff-only with --no-ff."
199
- allow_fast_forward=f ;;
200
- --ff-only)
201
- test "$allow_fast_forward" != f ||
202
- die "You cannot combine --ff-only with --no-ff."
203
- fast_forward_only=t ;;
204
- --rerere-autoupdate|--no-rerere-autoupdate)
205
- rr_arg=$1 ;;
206
- -s|--strategy)
207
- shift
208
- case " $all_strategies " in
209
- *" $1 "*)
210
- use_strategies="$use_strategies$1 "
211
- ;;
212
- *)
213
- case " $not_strategies " in
214
- *" $1 "*)
215
- false
216
- esac &&
217
- type "git-merge-$1" >/dev/null 2>&1 ||
218
- die "available strategies are: $all_strategies"
219
- use_strategies="$use_strategies$1 "
220
- ;;
221
- esac
222
- ;;
223
- -X)
224
- shift
225
- xopt="${xopt:+$xopt }$(git rev-parse --sq-quote "--$1")"
226
- ;;
227
- -m|--message)
228
- shift
229
- merge_msg="$1"
230
- have_message=t
231
- ;;
232
- --)
233
- shift
234
- break ;;
235
- *) usage ;;
236
- esac
237
- shift
238
- done
239
- args_left=$#
240
-}
241
-
242
-test $# != 0 || usage
243
-
244
-have_message=
245
-
246
-if branch=$(git-symbolic-ref -q HEAD)
247
-then
248
- mergeopts=$(git config "branch.${branch#refs/heads/}.mergeoptions")
249
- if test -n "$mergeopts"
250
- then
251
- parse_config $mergeopts --
252
- fi
253
-fi
254
-
255
-parse_config "$@"
256
-while test $args_left -lt $#; do shift; done
257
-
258
-if test -z "$show_diffstat"; then
259
- test "$(git config --bool merge.diffstat)" = false && show_diffstat=false
260
- test "$(git config --bool merge.stat)" = false && show_diffstat=false
261
- test -z "$show_diffstat" && show_diffstat=t
262
-fi
263
-
264
-# This could be traditional "merge <msg> HEAD <commit>..." and the
265
-# way we can tell it is to see if the second token is HEAD, but some
266
-# people might have misused the interface and used a commit-ish that
267
-# is the same as HEAD there instead. Traditional format never would
268
-# have "-m" so it is an additional safety measure to check for it.
269
-
270
-if test -z "$have_message" &&
271
- second_token=$(git rev-parse --verify "$2^0" 2>/dev/null) &&
272
- head_commit=$(git rev-parse --verify "HEAD" 2>/dev/null) &&
273
- test "$second_token" = "$head_commit"
274
-then
275
- merge_msg="$1"
276
- shift
277
- head_arg="$1"
278
- shift
279
-elif ! git rev-parse --verify HEAD >/dev/null 2>&1
280
-then
281
- # If the merged head is a valid one there is no reason to
282
- # forbid "git merge" into a branch yet to be born. We do
283
- # the same for "git pull".
284
- if test 1 -ne $#
285
- then
286
- echo >&2 "Can merge only exactly one commit into empty head"
287
- exit 1
288
- fi
289
-
290
- test "$squash" != t ||
291
- die "Squash commit into empty head not supported yet"
292
- test "$allow_fast_forward" = t ||
293
- die "Non-fast-forward into an empty head does not make sense"
294
- rh=$(git rev-parse --verify "$1^0") ||
295
- die "$1 - not something we can merge"
296
-
297
- git update-ref -m "initial pull" HEAD "$rh" "" &&
298
- git read-tree --reset -u HEAD
299
- exit
300
-
301
-else
302
- # We are invoked directly as the first-class UI.
303
- head_arg=HEAD
304
-
305
- # All the rest are the commits being merged; prepare
306
- # the standard merge summary message to be appended to
307
- # the given message. If remote is invalid we will die
308
- # later in the common codepath so we discard the error
309
- # in this loop.
310
- merge_msg="$(
311
- for remote
312
- do
313
- merge_name "$remote"
314
- done |
315
- if test "$have_message" = t
316
- then
317
- git fmt-merge-msg -m "$merge_msg" $log_arg
318
- else
319
- git fmt-merge-msg $log_arg
320
- fi
321
- )"
322
-fi
323
-head=$(git rev-parse --verify "$head_arg"^0) || usage
324
-
325
-# All the rest are remote heads
326
-test "$#" = 0 && usage ;# we need at least one remote head.
327
-set_reflog_action "merge $*"
328
-
329
-remoteheads=
330
-for remote
331
-do
332
- remotehead=$(git rev-parse --verify "$remote"^0 2>/dev/null) ||
333
- die "$remote - not something we can merge"
334
- remoteheads="${remoteheads}$remotehead "
335
- eval GITHEAD_$remotehead='"$remote"'
336
- export GITHEAD_$remotehead
337
-done
338
-set x $remoteheads ; shift
339
-
340
-case "$use_strategies" in
341
-'')
342
- case "$#" in
343
- 1)
344
- var="$(git config --get pull.twohead)"
345
- if test -n "$var"
346
- then
347
- use_strategies="$var"
348
- else
349
- use_strategies="$default_twohead_strategies"
350
- fi ;;
351
- *)
352
- var="$(git config --get pull.octopus)"
353
- if test -n "$var"
354
- then
355
- use_strategies="$var"
356
- else
357
- use_strategies="$default_octopus_strategies"
358
- fi ;;
359
- esac
360
- ;;
361
-esac
362
-
363
-for s in $use_strategies
364
-do
365
- for ss in $no_fast_forward_strategies
366
- do
367
- case " $s " in
368
- *" $ss "*)
369
- allow_fast_forward=f
370
- break
371
- ;;
372
- esac
373
- done
374
- for ss in $no_trivial_strategies
375
- do
376
- case " $s " in
377
- *" $ss "*)
378
- allow_trivial_merge=f
379
- break
380
- ;;
381
- esac
382
- done
383
-done
384
-
385
-case "$#" in
386
-1)
387
- common=$(git merge-base --all $head "$@")
388
- ;;
389
-*)
390
- common=$(git merge-base --all --octopus $head "$@")
391
- ;;
392
-esac
393
-echo "$head" >"$GIT_DIR/ORIG_HEAD"
394
-
395
-case "$allow_fast_forward,$#,$common,$no_commit" in
396
-?,*,'',*)
397
- # No common ancestors found. We need a real merge.
398
- ;;
399
-?,1,"$1",*)
400
- # If head can reach all the merge then we are up to date.
401
- # but first the most common case of merging one remote.
402
- finish_up_to_date "Already up to date."
403
- exit 0
404
- ;;
405
-t,1,"$head",*)
406
- # Again the most common case of merging one remote.
407
- echo "Updating $(git rev-parse --short $head)..$(git rev-parse --short $1)"
408
- git update-index --refresh 2>/dev/null
409
- msg="Fast-forward"
410
- if test -n "$have_message"
411
- then
412
- msg="$msg (no commit created; -m option ignored)"
413
- fi
414
- new_head=$(git rev-parse --verify "$1^0") &&
415
- git read-tree -v -m -u --exclude-per-directory=.gitignore $head "$new_head" &&
416
- finish "$new_head" "$msg" || exit
417
- dropsave
418
- exit 0
419
- ;;
420
-?,1,?*"$LF"?*,*)
421
- # We are not doing octopus and not fast-forward. Need a
422
- # real merge.
423
- ;;
424
-?,1,*,)
425
- # We are not doing octopus, not fast-forward, and have only
426
- # one common.
427
- git update-index --refresh 2>/dev/null
428
- case "$allow_trivial_merge,$fast_forward_only" in
429
- t,)
430
- # See if it is really trivial.
431
- git var GIT_COMMITTER_IDENT >/dev/null || exit
432
- echo "Trying really trivial in-index merge..."
433
- if git read-tree --trivial -m -u -v $common $head "$1" &&
434
- result_tree=$(git write-tree)
435
- then
436
- echo "Wonderful."
437
- result_commit=$(
438
- printf '%s\n' "$merge_msg" |
439
- git commit-tree $result_tree -p HEAD -p "$1"
440
- ) || exit
441
- finish "$result_commit" "In-index merge"
442
- dropsave
443
- exit 0
444
- fi
445
- echo "Nope."
446
- esac
447
- ;;
448
-*)
449
- # An octopus. If we can reach all the remote we are up to date.
450
- up_to_date=t
451
- for remote
452
- do
453
- common_one=$(git merge-base --all $head $remote)
454
- if test "$common_one" != "$remote"
455
- then
456
- up_to_date=f
457
- break
458
- fi
459
- done
460
- if test "$up_to_date" = t
461
- then
462
- finish_up_to_date "Already up to date. Yeeah!"
463
- exit 0
464
- fi
465
- ;;
466
-esac
467
-
468
-if test "$fast_forward_only" = t
469
-then
470
- die "Not possible to fast-forward, aborting."
471
-fi
472
-
473
-# We are going to make a new commit.
474
-git var GIT_COMMITTER_IDENT >/dev/null || exit
475
-
476
-# At this point, we need a real merge. No matter what strategy
477
-# we use, it would operate on the index, possibly affecting the
478
-# working tree, and when resolved cleanly, have the desired tree
479
-# in the index -- this means that the index must be in sync with
480
-# the $head commit. The strategies are responsible to ensure this.
481
-
482
-case "$use_strategies" in
483
-?*' '?*)
484
- # Stash away the local changes so that we can try more than one.
485
- savestate
486
- single_strategy=no
487
- ;;
488
-*)
489
- rm -f "$GIT_DIR/MERGE_STASH"
490
- single_strategy=yes
491
- ;;
492
-esac
493
-
494
-result_tree= best_cnt=-1 best_strategy= wt_strategy=
495
-merge_was_ok=
496
-for strategy in $use_strategies
497
-do
498
- test "$wt_strategy" = '' || {
499
- echo "Rewinding the tree to pristine..."
500
- restorestate
501
- }
502
- case "$single_strategy" in
503
- no)
504
- echo "Trying merge strategy $strategy..."
505
- ;;
506
- esac
507
-
508
- # Remember which strategy left the state in the working tree
509
- wt_strategy=$strategy
510
-
511
- eval 'git-merge-$strategy '"$xopt"' $common -- "$head_arg" "$@"'
512
- exit=$?
513
- if test "$no_commit" = t && test "$exit" = 0
514
- then
515
- merge_was_ok=t
516
- exit=1 ;# pretend it left conflicts.
517
- fi
518
-
519
- test "$exit" = 0 || {
520
-
521
- # The backend exits with 1 when conflicts are left to be resolved,
522
- # with 2 when it does not handle the given merge at all.
523
-
524
- if test "$exit" -eq 1
525
- then
526
- cnt=$({
527
- git diff-files --name-only
528
- git ls-files --unmerged
529
- } | wc -l)
530
- if test $best_cnt -le 0 || test $cnt -le $best_cnt
531
- then
532
- best_strategy=$strategy
533
- best_cnt=$cnt
534
- fi
535
- fi
536
- continue
537
- }
538
-
539
- # Automerge succeeded.
540
- result_tree=$(git write-tree) && break
541
-done
542
-
543
-# If we have a resulting tree, that means the strategy module
544
-# auto resolved the merge cleanly.
545
-if test '' != "$result_tree"
546
-then
547
- if test "$allow_fast_forward" = "t"
548
- then
549
- parents=$(git merge-base --independent "$head" "$@")
550
- else
551
- parents=$(git rev-parse "$head" "$@")
552
- fi
553
- parents=$(echo "$parents" | sed -e 's/^/-p /')
554
- result_commit=$(printf '%s\n' "$merge_msg" | git commit-tree $result_tree $parents) || exit
555
- finish "$result_commit" "Merge made by $wt_strategy."
556
- dropsave
557
- exit 0
558
-fi
559
-
560
-# Pick the result from the best strategy and have the user fix it up.
561
-case "$best_strategy" in
562
-'')
563
- restorestate
564
- case "$use_strategies" in
565
- ?*' '?*)
566
- echo >&2 "No merge strategy handled the merge."
567
- ;;
568
- *)
569
- echo >&2 "Merge with strategy $use_strategies failed."
570
- ;;
571
- esac
572
- exit 2
573
- ;;
574
-"$wt_strategy")
575
- # We already have its result in the working tree.
576
- ;;
577
-*)
578
- echo "Rewinding the tree to pristine..."
579
- restorestate
580
- echo "Using the $best_strategy to prepare resolving by hand."
581
- git-merge-$best_strategy $common -- "$head_arg" "$@"
582
- ;;
583
-esac
584
-
585
-if test "$squash" = t
586
-then
587
- finish
588
-else
589
- for remote
590
- do
591
- echo $remote
592
- done >"$GIT_DIR/MERGE_HEAD"
593
- printf '%s\n' "$merge_msg" >"$GIT_DIR/MERGE_MSG" ||
594
- die "Could not write to $GIT_DIR/MERGE_MSG"
595
- if test "$allow_fast_forward" != t
596
- then
597
- printf "%s" no-ff
598
- else
599
- :
600
- fi >"$GIT_DIR/MERGE_MODE" ||
601
- die "Could not write to $GIT_DIR/MERGE_MODE"
602
-fi
603
-
604
-if test "$merge_was_ok" = t
605
-then
606
- echo >&2 \
607
- "Automatic merge went well; stopped before committing as requested"
608
- exit 0
609
-else
610
- {
611
- echo '
612
-Conflicts:
613
-'
614
- git ls-files --unmerged |
615
- sed -e 's/^[^ ]* / /' |
616
- uniq
617
- } >>"$GIT_DIR/MERGE_MSG"
618
- git rerere $rr_arg
619
- die "Automatic merge failed; fix conflicts and then commit the result."
620
-fi
contrib/examples/git-notes.sh
deleted
-121
@@ -1,121 +0,0 @@
1
-#!/bin/sh
2
-
3
-USAGE="(edit [-F <file> | -m <msg>] | show) [commit]"
4
-. git-sh-setup
5
-
6
-test -z "$1" && usage
7
-ACTION="$1"; shift
8
-
9
-test -z "$GIT_NOTES_REF" && GIT_NOTES_REF="$(git config core.notesref)"
10
-test -z "$GIT_NOTES_REF" && GIT_NOTES_REF="refs/notes/commits"
11
-
12
-MESSAGE=
13
-while test $# != 0
14
-do
15
- case "$1" in
16
- -m)
17
- test "$ACTION" = "edit" || usage
18
- shift
19
- if test "$#" = "0"; then
20
- die "error: option -m needs an argument"
21
- else
22
- if [ -z "$MESSAGE" ]; then
23
- MESSAGE="$1"
24
- else
25
- MESSAGE="$MESSAGE
26
-
27
-$1"
28
- fi
29
- shift
30
- fi
31
- ;;
32
- -F)
33
- test "$ACTION" = "edit" || usage
34
- shift
35
- if test "$#" = "0"; then
36
- die "error: option -F needs an argument"
37
- else
38
- if [ -z "$MESSAGE" ]; then
39
- MESSAGE="$(cat "$1")"
40
- else
41
- MESSAGE="$MESSAGE
42
-
43
-$(cat "$1")"
44
- fi
45
- shift
46
- fi
47
- ;;
48
- -*)
49
- usage
50
- ;;
51
- *)
52
- break
53
- ;;
54
- esac
55
-done
56
-
57
-COMMIT=$(git rev-parse --verify --default HEAD "$@") ||
58
-die "Invalid commit: $@"
59
-
60
-case "$ACTION" in
61
-edit)
62
- if [ "${GIT_NOTES_REF#refs/notes/}" = "$GIT_NOTES_REF" ]; then
63
- die "Refusing to edit notes in $GIT_NOTES_REF (outside of refs/notes/)"
64
- fi
65
-
66
- MSG_FILE="$GIT_DIR/new-notes-$COMMIT"
67
- GIT_INDEX_FILE="$MSG_FILE.idx"
68
- export GIT_INDEX_FILE
69
-
70
- trap '
71
- test -f "$MSG_FILE" && rm "$MSG_FILE"
72
- test -f "$GIT_INDEX_FILE" && rm "$GIT_INDEX_FILE"
73
- ' 0
74
-
75
- CURRENT_HEAD=$(git show-ref "$GIT_NOTES_REF" | cut -f 1 -d ' ')
76
- if [ -z "$CURRENT_HEAD" ]; then
77
- PARENT=
78
- else
79
- PARENT="-p $CURRENT_HEAD"
80
- git read-tree "$GIT_NOTES_REF" || die "Could not read index"
81
- fi
82
-
83
- if [ -z "$MESSAGE" ]; then
84
- GIT_NOTES_REF= git log -1 $COMMIT | sed "s/^/#/" > "$MSG_FILE"
85
- if [ ! -z "$CURRENT_HEAD" ]; then
86
- git cat-file blob :$COMMIT >> "$MSG_FILE" 2> /dev/null
87
- fi
88
- core_editor="$(git config core.editor)"
89
- ${GIT_EDITOR:-${core_editor:-${VISUAL:-${EDITOR:-vi}}}} "$MSG_FILE"
90
- else
91
- echo "$MESSAGE" > "$MSG_FILE"
92
- fi
93
-
94
- grep -v ^# < "$MSG_FILE" | git stripspace > "$MSG_FILE".processed
95
- mv "$MSG_FILE".processed "$MSG_FILE"
96
- if [ -s "$MSG_FILE" ]; then
97
- BLOB=$(git hash-object -w "$MSG_FILE") ||
98
- die "Could not write into object database"
99
- git update-index --add --cacheinfo 0644 $BLOB $COMMIT ||
100
- die "Could not write index"
101
- else
102
- test -z "$CURRENT_HEAD" &&
103
- die "Will not initialise with empty tree"
104
- git update-index --force-remove $COMMIT ||
105
- die "Could not update index"
106
- fi
107
-
108
- TREE=$(git write-tree) || die "Could not write tree"
109
- NEW_HEAD=$(echo Annotate $COMMIT | git commit-tree $TREE $PARENT) ||
110
- die "Could not annotate"
111
- git update-ref -m "Annotate $COMMIT" \
112
- "$GIT_NOTES_REF" $NEW_HEAD $CURRENT_HEAD
113
-;;
114
-show)
115
- git rev-parse -q --verify "$GIT_NOTES_REF":$COMMIT > /dev/null ||
116
- die "No note for commit $COMMIT."
117
- git show "$GIT_NOTES_REF":$COMMIT
118
-;;
119
-*)
120
- usage
121
-esac
contrib/examples/git-pull.sh
deleted
-381
@@ -1,381 +0,0 @@
1
-#!/bin/sh
2
-#
3
-# Copyright (c) 2005 Junio C Hamano
4
-#
5
-# Fetch one or more remote refs and merge it/them into the current HEAD.
6
-
7
-SUBDIRECTORY_OK=Yes
8
-OPTIONS_KEEPDASHDASH=
9
-OPTIONS_STUCKLONG=Yes
10
-OPTIONS_SPEC="\
11
-git pull [options] [<repository> [<refspec>...]]
12
-
13
-Fetch one or more remote refs and integrate it/them with the current HEAD.
14
---
15
-v,verbose be more verbose
16
-q,quiet be more quiet
17
-progress force progress reporting
18
-
19
- Options related to merging
20
-r,rebase?false|true|preserve incorporate changes by rebasing rather than merging
21
-n! do not show a diffstat at the end of the merge
22
-stat show a diffstat at the end of the merge
23
-summary (synonym to --stat)
24
-log?n add (at most <n>) entries from shortlog to merge commit message
25
-squash create a single commit instead of doing a merge
26
-commit perform a commit if the merge succeeds (default)
27
-e,edit edit message before committing
28
-ff allow fast-forward
29
-ff-only! abort if fast-forward is not possible
30
-verify-signatures verify that the named commit has a valid GPG signature
31
-s,strategy=strategy merge strategy to use
32
-X,strategy-option=option option for selected merge strategy
33
-S,gpg-sign?key-id GPG sign commit
34
-
35
- Options related to fetching
36
-all fetch from all remotes
37
-a,append append to .git/FETCH_HEAD instead of overwriting
38
-upload-pack=path path to upload pack on remote end
39
-f,force force overwrite of local branch
40
-t,tags fetch all tags and associated objects
41
-p,prune prune remote-tracking branches no longer on remote
42
-recurse-submodules?on-demand control recursive fetching of submodules
43
-dry-run dry run
44
-k,keep keep downloaded pack
45
-depth=depth deepen history of shallow clone
46
-unshallow convert to a complete repository
47
-update-shallow accept refs that update .git/shallow
48
-refmap=refmap specify fetch refmap
49
-"
50
-test $# -gt 0 && args="$*"
51
-. git-sh-setup
52
-. git-sh-i18n
53
-set_reflog_action "pull${args+ $args}"
54
-require_work_tree_exists
55
-cd_to_toplevel
56
-
57
-
58
-die_conflict () {
59
- git diff-index --cached --name-status -r --ignore-submodules HEAD --
60
- if [ $(git config --bool --get advice.resolveConflict || echo true) = "true" ]; then
61
- die "$(gettext "Pull is not possible because you have unmerged files.
62
-Please, fix them up in the work tree, and then use 'git add/rm <file>'
63
-as appropriate to mark resolution and make a commit.")"
64
- else
65
- die "$(gettext "Pull is not possible because you have unmerged files.")"
66
- fi
67
-}
68
-
69
-die_merge () {
70
- if [ $(git config --bool --get advice.resolveConflict || echo true) = "true" ]; then
71
- die "$(gettext "You have not concluded your merge (MERGE_HEAD exists).
72
-Please, commit your changes before merging.")"
73
- else
74
- die "$(gettext "You have not concluded your merge (MERGE_HEAD exists).")"
75
- fi
76
-}
77
-
78
-test -z "$(git ls-files -u)" || die_conflict
79
-test -f "$GIT_DIR/MERGE_HEAD" && die_merge
80
-
81
-bool_or_string_config () {
82
- git config --bool "$1" 2>/dev/null || git config "$1"
83
-}
84
-
85
-strategy_args= diffstat= no_commit= squash= no_ff= ff_only=
86
-log_arg= verbosity= progress= recurse_submodules= verify_signatures=
87
-merge_args= edit= rebase_args= all= append= upload_pack= force= tags= prune=
88
-keep= depth= unshallow= update_shallow= refmap=
89
-curr_branch=$(git symbolic-ref -q HEAD)
90
-curr_branch_short="${curr_branch#refs/heads/}"
91
-rebase=$(bool_or_string_config branch.$curr_branch_short.rebase)
92
-if test -z "$rebase"
93
-then
94
- rebase=$(bool_or_string_config pull.rebase)
95
-fi
96
-
97
-# Setup default fast-forward options via `pull.ff`
98
-pull_ff=$(bool_or_string_config pull.ff)
99
-case "$pull_ff" in
100
-true)
101
- no_ff=--ff
102
- ;;
103
-false)
104
- no_ff=--no-ff
105
- ;;
106
-only)
107
- ff_only=--ff-only
108
- ;;
109
-esac
110
-
111
-
112
-dry_run=
113
-while :
114
-do
115
- case "$1" in
116
- -q|--quiet)
117
- verbosity="$verbosity -q" ;;
118
- -v|--verbose)
119
- verbosity="$verbosity -v" ;;
120
- --progress)
121
- progress=--progress ;;
122
- --no-progress)
123
- progress=--no-progress ;;
124
- -n|--no-stat|--no-summary)
125
- diffstat=--no-stat ;;
126
- --stat|--summary)
127
- diffstat=--stat ;;
128
- --log|--log=*|--no-log)
129
- log_arg="$1" ;;
130
- --no-commit)
131
- no_commit=--no-commit ;;
132
- --commit)
133
- no_commit=--commit ;;
134
- -e|--edit)
135
- edit=--edit ;;
136
- --no-edit)
137
- edit=--no-edit ;;
138
- --squash)
139
- squash=--squash ;;
140
- --no-squash)
141
- squash=--no-squash ;;
142
- --ff)
143
- no_ff=--ff ;;
144
- --no-ff)
145
- no_ff=--no-ff ;;
146
- --ff-only)
147
- ff_only=--ff-only ;;
148
- -s*|--strategy=*)
149
- strategy_args="$strategy_args $1"
150
- ;;
151
- -X*|--strategy-option=*)
152
- merge_args="$merge_args $(git rev-parse --sq-quote "$1")"
153
- ;;
154
- -r*|--rebase=*)
155
- rebase="${1#*=}"
156
- ;;
157
- --rebase)
158
- rebase=true
159
- ;;
160
- --no-rebase)
161
- rebase=false
162
- ;;
163
- --recurse-submodules)
164
- recurse_submodules=--recurse-submodules
165
- ;;
166
- --recurse-submodules=*)
167
- recurse_submodules="$1"
168
- ;;
169
- --no-recurse-submodules)
170
- recurse_submodules=--no-recurse-submodules
171
- ;;
172
- --verify-signatures)
173
- verify_signatures=--verify-signatures
174
- ;;
175
- --no-verify-signatures)
176
- verify_signatures=--no-verify-signatures
177
- ;;
178
- --gpg-sign|-S)
179
- gpg_sign_args=-S
180
- ;;
181
- --gpg-sign=*)
182
- gpg_sign_args=$(git rev-parse --sq-quote "-S${1#--gpg-sign=}")
183
- ;;
184
- -S*)
185
- gpg_sign_args=$(git rev-parse --sq-quote "$1")
186
- ;;
187
- --dry-run)
188
- dry_run=--dry-run
189
- ;;
190
- --all|--no-all)
191
- all=$1 ;;
192
- -a|--append|--no-append)
193
- append=$1 ;;
194
- --upload-pack=*|--no-upload-pack)
195
- upload_pack=$1 ;;
196
- -f|--force|--no-force)
197
- force="$force $1" ;;
198
- -t|--tags|--no-tags)
199
- tags=$1 ;;
200
- -p|--prune|--no-prune)
201
- prune=$1 ;;
202
- -k|--keep|--no-keep)
203
- keep=$1 ;;
204
- --depth=*|--no-depth)
205
- depth=$1 ;;
206
- --unshallow|--no-unshallow)
207
- unshallow=$1 ;;
208
- --update-shallow|--no-update-shallow)
209
- update_shallow=$1 ;;
210
- --refmap=*|--no-refmap)
211
- refmap=$1 ;;
212
- -h|--help-all)
213
- usage
214
- ;;
215
- --)
216
- shift
217
- break
218
- ;;
219
- *)
220
- usage
221
- ;;
222
- esac
223
- shift
224
-done
225
-
226
-case "$rebase" in
227
-preserve)
228
- rebase=true
229
- rebase_args=--preserve-merges
230
- ;;
231
-true|false|'')
232
- ;;
233
-*)
234
- echo "Invalid value for --rebase, should be true, false, or preserve"
235
- usage
236
- exit 1
237
- ;;
238
-esac
239
-
240
-error_on_no_merge_candidates () {
241
- exec >&2
242
-
243
- if test true = "$rebase"
244
- then
245
- op_type=rebase
246
- op_prep=against
247
- else
248
- op_type=merge
249
- op_prep=with
250
- fi
251
-
252
- upstream=$(git config "branch.$curr_branch_short.merge")
253
- remote=$(git config "branch.$curr_branch_short.remote")
254
-
255
- if [ $# -gt 1 ]; then
256
- if [ "$rebase" = true ]; then
257
- printf "There is no candidate for rebasing against "
258
- else
259
- printf "There are no candidates for merging "
260
- fi
261
- echo "among the refs that you just fetched."
262
- echo "Generally this means that you provided a wildcard refspec which had no"
263
- echo "matches on the remote end."
264
- elif [ $# -gt 0 ] && [ "$1" != "$remote" ]; then
265
- echo "You asked to pull from the remote '$1', but did not specify"
266
- echo "a branch. Because this is not the default configured remote"
267
- echo "for your current branch, you must specify a branch on the command line."
268
- elif [ -z "$curr_branch" -o -z "$upstream" ]; then
269
- . git-parse-remote
270
- error_on_missing_default_upstream "pull" $op_type $op_prep \
271
- "git pull <remote> <branch>"
272
- else
273
- echo "Your configuration specifies to $op_type $op_prep the ref '${upstream#refs/heads/}'"
274
- echo "from the remote, but no such ref was fetched."
275
- fi
276
- exit 1
277
-}
278
-
279
-test true = "$rebase" && {
280
- if ! git rev-parse -q --verify HEAD >/dev/null
281
- then
282
- # On an unborn branch
283
- if test -f "$(git rev-parse --git-path index)"
284
- then
285
- die "$(gettext "updating an unborn branch with changes added to the index")"
286
- fi
287
- else
288
- require_clean_work_tree "pull with rebase" "Please commit or stash them."
289
- fi
290
- oldremoteref= &&
291
- test -n "$curr_branch" &&
292
- . git-parse-remote &&
293
- remoteref="$(get_remote_merge_branch "$@" 2>/dev/null)" &&
294
- oldremoteref=$(git merge-base --fork-point "$remoteref" $curr_branch 2>/dev/null)
295
-}
296
-orig_head=$(git rev-parse -q --verify HEAD)
297
-git fetch $verbosity $progress $dry_run $recurse_submodules $all $append \
298
-${upload_pack:+"$upload_pack"} $force $tags $prune $keep $depth $unshallow $update_shallow \
299
-$refmap --update-head-ok "$@" || exit 1
300
-test -z "$dry_run" || exit 0
301
-
302
-curr_head=$(git rev-parse -q --verify HEAD)
303
-if test -n "$orig_head" && test "$curr_head" != "$orig_head"
304
-then
305
- # The fetch involved updating the current branch.
306
-
307
- # The working tree and the index file is still based on the
308
- # $orig_head commit, but we are merging into $curr_head.
309
- # First update the working tree to match $curr_head.
310
-
311
- eval_gettextln "Warning: fetch updated the current branch head.
312
-Warning: fast-forwarding your working tree from
313
-Warning: commit \$orig_head." >&2
314
- git update-index -q --refresh
315
- git read-tree -u -m "$orig_head" "$curr_head" ||
316
- die "$(eval_gettext "Cannot fast-forward your working tree.
317
-After making sure that you saved anything precious from
318
-$ git diff \$orig_head
319
-output, run
320
-$ git reset --hard
321
-to recover.")"
322
-
323
-fi
324
-
325
-merge_head=$(sed -e '/ not-for-merge /d' \
326
- -e 's/ .*//' "$GIT_DIR"/FETCH_HEAD | \
327
- tr '\012' ' ')
328
-
329
-case "$merge_head" in
330
-'')
331
- error_on_no_merge_candidates "$@"
332
- ;;
333
-?*' '?*)
334
- if test -z "$orig_head"
335
- then
336
- die "$(gettext "Cannot merge multiple branches into empty head")"
337
- fi
338
- if test true = "$rebase"
339
- then
340
- die "$(gettext "Cannot rebase onto multiple branches")"
341
- fi
342
- ;;
343
-esac
344
-
345
-# Pulling into unborn branch: a shorthand for branching off
346
-# FETCH_HEAD, for lazy typers.
347
-if test -z "$orig_head"
348
-then
349
- # Two-way merge: we claim the index is based on an empty tree,
350
- # and try to fast-forward to HEAD. This ensures we will not
351
- # lose index/worktree changes that the user already made on
352
- # the unborn branch.
353
- empty_tree=4b825dc642cb6eb9a060e54bf8d69288fbee4904
354
- git read-tree -m -u $empty_tree $merge_head &&
355
- git update-ref -m "initial pull" HEAD $merge_head "$curr_head"
356
- exit
357
-fi
358
-
359
-if test true = "$rebase"
360
-then
361
- o=$(git show-branch --merge-base $curr_branch $merge_head $oldremoteref)
362
- if test "$oldremoteref" = "$o"
363
- then
364
- unset oldremoteref
365
- fi
366
-fi
367
-
368
-case "$rebase" in
369
-true)
370
- eval="git-rebase $diffstat $strategy_args $merge_args $rebase_args $verbosity"
371
- eval="$eval $gpg_sign_args"
372
- eval="$eval --onto $merge_head ${oldremoteref:-$merge_head}"
373
- ;;
374
-*)
375
- eval="git-merge $diffstat $no_commit $verify_signatures $edit $squash $no_ff $ff_only"
376
- eval="$eval $log_arg $strategy_args $merge_args $verbosity $progress"
377
- eval="$eval $gpg_sign_args"
378
- eval="$eval FETCH_HEAD"
379
- ;;
380
-esac
381
-eval "exec $eval"
contrib/examples/git-remote.perl
deleted
-474
@@ -1,474 +0,0 @@
1
-#!/usr/bin/perl -w
2
-
3
-use strict;
4
-use Git;
5
-my $git = Git->repository();
6
-
7
-sub add_remote_config {
8
- my ($hash, $name, $what, $value) = @_;
9
- if ($what eq 'url') {
10
- # Having more than one is Ok -- it is used for push.
11
- if (! exists $hash->{'URL'}) {
12
- $hash->{$name}{'URL'} = $value;
13
- }
14
- }
15
- elsif ($what eq 'fetch') {
16
- $hash->{$name}{'FETCH'} ||= [];
17
- push @{$hash->{$name}{'FETCH'}}, $value;
18
- }
19
- elsif ($what eq 'push') {
20
- $hash->{$name}{'PUSH'} ||= [];
21
- push @{$hash->{$name}{'PUSH'}}, $value;
22
- }
23
- if (!exists $hash->{$name}{'SOURCE'}) {
24
- $hash->{$name}{'SOURCE'} = 'config';
25
- }
26
-}
27
-
28
-sub add_remote_remotes {
29
- my ($hash, $file, $name) = @_;
30
-
31
- if (exists $hash->{$name}) {
32
- $hash->{$name}{'WARNING'} = 'ignored due to config';
33
- return;
34
- }
35
-
36
- my $fh;
37
- if (!open($fh, '<', $file)) {
38
- print STDERR "Warning: cannot open $file\n";
39
- return;
40
- }
41
- my $it = { 'SOURCE' => 'remotes' };
42
- $hash->{$name} = $it;
43
- while (<$fh>) {
44
- chomp;
45
- if (/^URL:\s*(.*)$/) {
46
- # Having more than one is Ok -- it is used for push.
47
- if (! exists $it->{'URL'}) {
48
- $it->{'URL'} = $1;
49
- }
50
- }
51
- elsif (/^Push:\s*(.*)$/) {
52
- $it->{'PUSH'} ||= [];
53
- push @{$it->{'PUSH'}}, $1;
54
- }
55
- elsif (/^Pull:\s*(.*)$/) {
56
- $it->{'FETCH'} ||= [];
57
- push @{$it->{'FETCH'}}, $1;
58
- }
59
- elsif (/^\#/) {
60
- ; # ignore
61
- }
62
- else {
63
- print STDERR "Warning: funny line in $file: $_\n";
64
- }
65
- }
66
- close($fh);
67
-}
68
-
69
-sub list_remote {
70
- my ($git) = @_;
71
- my %seen = ();
72
- my @remotes = eval {
73
- $git->command(qw(config --get-regexp), '^remote\.');
74
- };
75
- for (@remotes) {
76
- if (/^remote\.(\S+?)\.([^.\s]+)\s+(.*)$/) {
77
- add_remote_config(\%seen, $1, $2, $3);
78
- }
79
- }
80
-
81
- my $dir = $git->repo_path() . "/remotes";
82
- if (opendir(my $dh, $dir)) {
83
- local $_;
84
- while ($_ = readdir($dh)) {
85
- chomp;
86
- next if (! -f "$dir/$_" || ! -r _);
87
- add_remote_remotes(\%seen, "$dir/$_", $_);
88
- }
89
- }
90
-
91
- return \%seen;
92
-}
93
-
94
-sub add_branch_config {
95
- my ($hash, $name, $what, $value) = @_;
96
- if ($what eq 'remote') {
97
- if (exists $hash->{$name}{'REMOTE'}) {
98
- print STDERR "Warning: more than one branch.$name.remote\n";
99
- }
100
- $hash->{$name}{'REMOTE'} = $value;
101
- }
102
- elsif ($what eq 'merge') {
103
- $hash->{$name}{'MERGE'} ||= [];
104
- push @{$hash->{$name}{'MERGE'}}, $value;
105
- }
106
-}
107
-
108
-sub list_branch {
109
- my ($git) = @_;
110
- my %seen = ();
111
- my @branches = eval {
112
- $git->command(qw(config --get-regexp), '^branch\.');
113
- };
114
- for (@branches) {
115
- if (/^branch\.([^.]*)\.(\S*)\s+(.*)$/) {
116
- add_branch_config(\%seen, $1, $2, $3);
117
- }
118
- }
119
-
120
- return \%seen;
121
-}
122
-
123
-my $remote = list_remote($git);
124
-my $branch = list_branch($git);
125
-
126
-sub update_ls_remote {
127
- my ($harder, $info) = @_;
128
-
129
- return if (($harder == 0) ||
130
- (($harder == 1) && exists $info->{'LS_REMOTE'}));
131
-
132
- my @ref = map { s|refs/heads/||; $_; } keys %{$git->remote_refs($info->{'URL'}, [ 'heads' ])};
133
- $info->{'LS_REMOTE'} = \@ref;
134
-}
135
-
136
-sub list_wildcard_mapping {
137
- my ($forced, $ours, $ls) = @_;
138
- my %refs;
139
- for (@$ls) {
140
- $refs{$_} = 01; # bit #0 to say "they have"
141
- }
142
- for ($git->command('for-each-ref', "refs/remotes/$ours")) {
143
- chomp;
144
- next unless (s|^[0-9a-f]{40}\s[a-z]+\srefs/remotes/$ours/||);
145
- next if ($_ eq 'HEAD');
146
- $refs{$_} ||= 0;
147
- $refs{$_} |= 02; # bit #1 to say "we have"
148
- }
149
- my (@new, @stale, @tracked);
150
- for (sort keys %refs) {
151
- my $have = $refs{$_};
152
- if ($have == 1) {
153
- push @new, $_;
154
- }
155
- elsif ($have == 2) {
156
- push @stale, $_;
157
- }
158
- elsif ($have == 3) {
159
- push @tracked, $_;
160
- }
161
- }
162
- return \@new, \@stale, \@tracked;
163
-}
164
-
165
-sub list_mapping {
166
- my ($name, $info) = @_;
167
- my $fetch = $info->{'FETCH'};
168
- my $ls = $info->{'LS_REMOTE'};
169
- my (@new, @stale, @tracked);
170
-
171
- for (@$fetch) {
172
- next unless (/(\+)?([^:]+):(.*)/);
173
- my ($forced, $theirs, $ours) = ($1, $2, $3);
174
- if ($theirs eq 'refs/heads/*' &&
175
- $ours =~ /^refs\/remotes\/(.*)\/\*$/) {
176
- # wildcard mapping
177
- my ($w_new, $w_stale, $w_tracked)
178
- = list_wildcard_mapping($forced, $1, $ls);
179
- push @new, @$w_new;
180
- push @stale, @$w_stale;
181
- push @tracked, @$w_tracked;
182
- }
183
- elsif ($theirs =~ /\*/ || $ours =~ /\*/) {
184
- print STDERR "Warning: unrecognized mapping in remotes.$name.fetch: $_\n";
185
- }
186
- elsif ($theirs =~ s|^refs/heads/||) {
187
- if (!grep { $_ eq $theirs } @$ls) {
188
- push @stale, $theirs;
189
- }
190
- elsif ($ours ne '') {
191
- push @tracked, $theirs;
192
- }
193
- }
194
- }
195
- return \@new, \@stale, \@tracked;
196
-}
197
-
198
-sub show_mapping {
199
- my ($name, $info) = @_;
200
- my ($new, $stale, $tracked) = list_mapping($name, $info);
201
- if (@$new) {
202
- print " New remote branches (next fetch will store in remotes/$name)\n";
203
- print " @$new\n";
204
- }
205
- if (@$stale) {
206
- print " Stale tracking branches in remotes/$name (use 'git remote prune')\n";
207
- print " @$stale\n";
208
- }
209
- if (@$tracked) {
210
- print " Tracked remote branches\n";
211
- print " @$tracked\n";
212
- }
213
-}
214
-
215
-sub prune_remote {
216
- my ($name, $ls_remote) = @_;
217
- if (!exists $remote->{$name}) {
218
- print STDERR "No such remote $name\n";
219
- return 1;
220
- }
221
- my $info = $remote->{$name};
222
- update_ls_remote($ls_remote, $info);
223
-
224
- my ($new, $stale, $tracked) = list_mapping($name, $info);
225
- my $prefix = "refs/remotes/$name";
226
- foreach my $to_prune (@$stale) {
227
- my @v = $git->command(qw(rev-parse --verify), "$prefix/$to_prune");
228
- $git->command(qw(update-ref -d), "$prefix/$to_prune", $v[0]);
229
- }
230
- return 0;
231
-}
232
-
233
-sub show_remote {
234
- my ($name, $ls_remote) = @_;
235
- if (!exists $remote->{$name}) {
236
- print STDERR "No such remote $name\n";
237
- return 1;
238
- }
239
- my $info = $remote->{$name};
240
- update_ls_remote($ls_remote, $info);
241
-
242
- print "* remote $name\n";
243
- print " URL: $info->{'URL'}\n";
244
- for my $branchname (sort keys %$branch) {
245
- next unless (defined $branch->{$branchname}{'REMOTE'} &&
246
- $branch->{$branchname}{'REMOTE'} eq $name);
247
- my @merged = map {
248
- s|^refs/heads/||;
249
- $_;
250
- } split(' ',"@{$branch->{$branchname}{'MERGE'}}");
251
- next unless (@merged);
252
- print " Remote branch(es) merged with 'git pull' while on branch $branchname\n";
253
- print " @merged\n";
254
- }
255
- if ($info->{'LS_REMOTE'}) {
256
- show_mapping($name, $info);
257
- }
258
- if ($info->{'PUSH'}) {
259
- my @pushed = map {
260
- s|^refs/heads/||;
261
- s|^\+refs/heads/|+|;
262
- s|:refs/heads/|:|;
263
- $_;
264
- } @{$info->{'PUSH'}};
265
- print " Local branch(es) pushed with 'git push'\n";
266
- print " @pushed\n";
267
- }
268
- return 0;
269
-}
270
-
271
-sub add_remote {
272
- my ($name, $url, $opts) = @_;
273
- if (exists $remote->{$name}) {
274
- print STDERR "remote $name already exists.\n";
275
- exit(1);
276
- }
277
- $git->command('config', "remote.$name.url", $url);
278
- my $track = $opts->{'track'} || ["*"];
279
-
280
- for (@$track) {
281
- $git->command('config', '--add', "remote.$name.fetch",
282
- $opts->{'mirror'} ?
283
- "+refs/$_:refs/$_" :
284
- "+refs/heads/$_:refs/remotes/$name/$_");
285
- }
286
- if ($opts->{'fetch'}) {
287
- $git->command('fetch', $name);
288
- }
289
- if (exists $opts->{'master'}) {
290
- $git->command('symbolic-ref', "refs/remotes/$name/HEAD",
291
- "refs/remotes/$name/$opts->{'master'}");
292
- }
293
-}
294
-
295
-sub update_remote {
296
- my ($name) = @_;
297
- my @remotes;
298
-
299
- my $conf = $git->config("remotes." . $name);
300
- if (defined($conf)) {
301
- @remotes = split(' ', $conf);
302
- } elsif ($name eq 'default') {
303
- @remotes = ();
304
- for (sort keys %$remote) {
305
- my $do_fetch = $git->config_bool("remote." . $_ .
306
- ".skipDefaultUpdate");
307
- unless ($do_fetch) {
308
- push @remotes, $_;
309
- }
310
- }
311
- } else {
312
- print STDERR "Remote group $name does not exist.\n";
313
- exit(1);
314
- }
315
- for (@remotes) {
316
- print "Updating $_\n";
317
- $git->command('fetch', "$_");
318
- }
319
-}
320
-
321
-sub rm_remote {
322
- my ($name) = @_;
323
- if (!exists $remote->{$name}) {
324
- print STDERR "No such remote $name\n";
325
- return 1;
326
- }
327
-
328
- $git->command('config', '--remove-section', "remote.$name");
329
-
330
- eval {
331
- my @trackers = $git->command('config', '--get-regexp',
332
- 'branch.*.remote', $name);
333
- for (@trackers) {
334
- /^branch\.(.*)?\.remote/;
335
- $git->config('--unset', "branch.$1.remote");
336
- $git->config('--unset', "branch.$1.merge");
337
- }
338
- };
339
-
340
- my @refs = $git->command('for-each-ref',
341
- '--format=%(refname) %(objectname)', "refs/remotes/$name");
342
- for (@refs) {
343
- my ($ref, $object) = split;
344
- $git->command(qw(update-ref -d), $ref, $object);
345
- }
346
- return 0;
347
-}
348
-
349
-sub add_usage {
350
- print STDERR "usage: git remote add [-f] [-t track]* [-m master] <name> <url>\n";
351
- exit(1);
352
-}
353
-
354
-my $VERBOSE = 0;
355
-@ARGV = grep {
356
- if ($_ eq '-v' or $_ eq '--verbose') {
357
- $VERBOSE=1;
358
- 0
359
- } else {
360
- 1
361
- }
362
-} @ARGV;
363
-
364
-if (!@ARGV) {
365
- for (sort keys %$remote) {
366
- print "$_";
367
- print "\t$remote->{$_}->{URL}" if $VERBOSE;
368
- print "\n";
369
- }
370
-}
371
-elsif ($ARGV[0] eq 'show') {
372
- my $ls_remote = 1;
373
- my $i;
374
- for ($i = 1; $i < @ARGV; $i++) {
375
- if ($ARGV[$i] eq '-n') {
376
- $ls_remote = 0;
377
- }
378
- else {
379
- last;
380
- }
381
- }
382
- if ($i >= @ARGV) {
383
- print STDERR "usage: git remote show <remote>\n";
384
- exit(1);
385
- }
386
- my $status = 0;
387
- for (; $i < @ARGV; $i++) {
388
- $status |= show_remote($ARGV[$i], $ls_remote);
389
- }
390
- exit($status);
391
-}
392
-elsif ($ARGV[0] eq 'update') {
393
- if (@ARGV <= 1) {
394
- update_remote("default");
395
- exit(1);
396
- }
397
- for (my $i = 1; $i < @ARGV; $i++) {
398
- update_remote($ARGV[$i]);
399
- }
400
-}
401
-elsif ($ARGV[0] eq 'prune') {
402
- my $ls_remote = 1;
403
- my $i;
404
- for ($i = 1; $i < @ARGV; $i++) {
405
- if ($ARGV[$i] eq '-n') {
406
- $ls_remote = 0;
407
- }
408
- else {
409
- last;
410
- }
411
- }
412
- if ($i >= @ARGV) {
413
- print STDERR "usage: git remote prune <remote>\n";
414
- exit(1);
415
- }
416
- my $status = 0;
417
- for (; $i < @ARGV; $i++) {
418
- $status |= prune_remote($ARGV[$i], $ls_remote);
419
- }
420
- exit($status);
421
-}
422
-elsif ($ARGV[0] eq 'add') {
423
- my %opts = ();
424
- while (1 < @ARGV && $ARGV[1] =~ /^-/) {
425
- my $opt = $ARGV[1];
426
- shift @ARGV;
427
- if ($opt eq '-f' || $opt eq '--fetch') {
428
- $opts{'fetch'} = 1;
429
- next;
430
- }
431
- if ($opt eq '-t' || $opt eq '--track') {
432
- if (@ARGV < 1) {
433
- add_usage();
434
- }
435
- $opts{'track'} ||= [];
436
- push @{$opts{'track'}}, $ARGV[1];
437
- shift @ARGV;
438
- next;
439
- }
440
- if ($opt eq '-m' || $opt eq '--master') {
441
- if ((@ARGV < 1) || exists $opts{'master'}) {
442
- add_usage();
443
- }
444
- $opts{'master'} = $ARGV[1];
445
- shift @ARGV;
446
- next;
447
- }
448
- if ($opt eq '--mirror') {
449
- $opts{'mirror'} = 1;
450
- next;
451
- }
452
- add_usage();
453
- }
454
- if (@ARGV != 3) {
455
- add_usage();
456
- }
457
- add_remote($ARGV[1], $ARGV[2], \%opts);
458
-}
459
-elsif ($ARGV[0] eq 'rm') {
460
- if (@ARGV <= 1) {
461
- print STDERR "usage: git remote rm <remote>\n";
462
- exit(1);
463
- }
464
- exit(rm_remote($ARGV[1]));
465
-}
466
-else {
467
- print STDERR "usage: git remote\n";
468
- print STDERR " git remote add <name> <url>\n";
469
- print STDERR " git remote rm <name>\n";
470
- print STDERR " git remote show <name>\n";
471
- print STDERR " git remote prune <name>\n";
472
- print STDERR " git remote update [group]\n";
473
- exit(1);
474
-}
contrib/examples/git-repack.sh
deleted
-194
@@ -1,194 +0,0 @@
1
-#!/bin/sh
2
-#
3
-# Copyright (c) 2005 Linus Torvalds
4
-#
5
-
6
-OPTIONS_KEEPDASHDASH=
7
-OPTIONS_SPEC="\
8
-git repack [options]
9
---
10
-a pack everything in a single pack
11
-A same as -a, and turn unreachable objects loose
12
-d remove redundant packs, and run git-prune-packed
13
-f pass --no-reuse-delta to git-pack-objects
14
-F pass --no-reuse-object to git-pack-objects
15
-n do not run git-update-server-info
16
-q,quiet be quiet
17
-l pass --local to git-pack-objects
18
-unpack-unreachable= with -A, do not loosen objects older than this
19
- Packing constraints
20
-window= size of the window used for delta compression
21
-window-memory= same as the above, but limit memory size instead of entries count
22
-depth= limits the maximum delta depth
23
-max-pack-size= maximum size of each packfile
24
-"
25
-SUBDIRECTORY_OK='Yes'
26
-. git-sh-setup
27
-
28
-no_update_info= all_into_one= remove_redundant= unpack_unreachable=
29
-local= no_reuse= extra=
30
-while test $# != 0
31
-do
32
- case "$1" in
33
- -n) no_update_info=t ;;
34
- -a) all_into_one=t ;;
35
- -A) all_into_one=t
36
- unpack_unreachable=--unpack-unreachable ;;
37
- --unpack-unreachable)
38
- unpack_unreachable="--unpack-unreachable=$2"; shift ;;
39
- -d) remove_redundant=t ;;
40
- -q) GIT_QUIET=t ;;
41
- -f) no_reuse=--no-reuse-delta ;;
42
- -F) no_reuse=--no-reuse-object ;;
43
- -l) local=--local ;;
44
- --max-pack-size|--window|--window-memory|--depth)
45
- extra="$extra $1=$2"; shift ;;
46
- --) shift; break;;
47
- *) usage ;;
48
- esac
49
- shift
50
-done
51
-
52
-case "$(git config --bool repack.usedeltabaseoffset || echo true)" in
53
-true)
54
- extra="$extra --delta-base-offset" ;;
55
-esac
56
-
57
-PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
58
-PACKTMP="$PACKDIR/.tmp-$$-pack"
59
-rm -f "$PACKTMP"-*
60
-trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
61
-
62
-# There will be more repacking strategies to come...
63
-case ",$all_into_one," in
64
-,,)
65
- args='--unpacked --incremental'
66
- ;;
67
-,t,)
68
- args= existing=
69
- if [ -d "$PACKDIR" ]; then
70
- for e in $(cd "$PACKDIR" && find . -type f -name '*.pack' \
71
- | sed -e 's/^\.\///' -e 's/\.pack$//')
72
- do
73
- if [ -e "$PACKDIR/$e.keep" ]; then
74
- : keep
75
- else
76
- existing="$existing $e"
77
- fi
78
- done
79
- if test -n "$existing" && test -n "$unpack_unreachable" && \
80
- test -n "$remove_redundant"
81
- then
82
- # This may have arbitrary user arguments, so we
83
- # have to protect it against whitespace splitting
84
- # when it gets run as "pack-objects $args" later.
85
- # Fortunately, we know it's an approxidate, so we
86
- # can just use dots instead.
87
- args="$args $(echo "$unpack_unreachable" | tr ' ' .)"
88
- fi
89
- fi
90
- ;;
91
-esac
92
-
93
-mkdir -p "$PACKDIR" || exit
94
-
95
-args="$args $local ${GIT_QUIET:+-q} $no_reuse$extra"
96
-names=$(git pack-objects --keep-true-parents --honor-pack-keep --non-empty --all --reflog $args </dev/null "$PACKTMP") ||
97
- exit 1
98
-if [ -z "$names" ]; then
99
- say Nothing new to pack.
100
-fi
101
-
102
-# Ok we have prepared all new packfiles.
103
-
104
-# First see if there are packs of the same name and if so
105
-# if we can move them out of the way (this can happen if we
106
-# repacked immediately after packing fully.
107
-rollback=
108
-failed=
109
-for name in $names
110
-do
111
- for sfx in pack idx
112
- do
113
- file=pack-$name.$sfx
114
- test -f "$PACKDIR/$file" || continue
115
- rm -f "$PACKDIR/old-$file" &&
116
- mv "$PACKDIR/$file" "$PACKDIR/old-$file" || {
117
- failed=t
118
- break
119
- }
120
- rollback="$rollback $file"
121
- done
122
- test -z "$failed" || break
123
-done
124
-
125
-# If renaming failed for any of them, roll the ones we have
126
-# already renamed back to their original names.
127
-if test -n "$failed"
128
-then
129
- rollback_failure=
130
- for file in $rollback
131
- do
132
- mv "$PACKDIR/old-$file" "$PACKDIR/$file" ||
133
- rollback_failure="$rollback_failure $file"
134
- done
135
- if test -n "$rollback_failure"
136
- then
137
- echo >&2 "WARNING: Some packs in use have been renamed by"
138
- echo >&2 "WARNING: prefixing old- to their name, in order to"
139
- echo >&2 "WARNING: replace them with the new version of the"
140
- echo >&2 "WARNING: file. But the operation failed, and"
141
- echo >&2 "WARNING: attempt to rename them back to their"
142
- echo >&2 "WARNING: original names also failed."
143
- echo >&2 "WARNING: Please rename them in $PACKDIR manually:"
144
- for file in $rollback_failure
145
- do
146
- echo >&2 "WARNING: old-$file -> $file"
147
- done
148
- fi
149
- exit 1
150
-fi
151
-
152
-# Now the ones with the same name are out of the way...
153
-fullbases=
154
-for name in $names
155
-do
156
- fullbases="$fullbases pack-$name"
157
- chmod a-w "$PACKTMP-$name.pack"
158
- chmod a-w "$PACKTMP-$name.idx"
159
- mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
160
- mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" ||
161
- exit
162
-done
163
-
164
-# Remove the "old-" files
165
-for name in $names
166
-do
167
- rm -f "$PACKDIR/old-pack-$name.idx"
168
- rm -f "$PACKDIR/old-pack-$name.pack"
169
-done
170
-
171
-# End of pack replacement.
172
-
173
-if test "$remove_redundant" = t
174
-then
175
- # We know $existing are all redundant.
176
- if [ -n "$existing" ]
177
- then
178
- ( cd "$PACKDIR" &&
179
- for e in $existing
180
- do
181
- case " $fullbases " in
182
- *" $e "*) ;;
183
- *) rm -f "$e.pack" "$e.idx" "$e.keep" ;;
184
- esac
185
- done
186
- )
187
- fi
188
- git prune-packed ${GIT_QUIET:+-q}
189
-fi
190
-
191
-case "$no_update_info" in
192
-t) : ;;
193
-*) git update-server-info ;;
194
-esac
contrib/examples/git-rerere.perl
deleted
-284
@@ -1,284 +0,0 @@
1
-#!/usr/bin/perl
2
-#
3
-# REuse REcorded REsolve. This tool records a conflicted automerge
4
-# result and its hand resolution, and helps to resolve future
5
-# automerge that results in the same conflict.
6
-#
7
-# To enable this feature, create a directory 'rr-cache' under your
8
-# .git/ directory.
9
-
10
-use Digest;
11
-use File::Path;
12
-use File::Copy;
13
-
14
-my $git_dir = $::ENV{GIT_DIR} || ".git";
15
-my $rr_dir = "$git_dir/rr-cache";
16
-my $merge_rr = "$git_dir/rr-cache/MERGE_RR";
17
-
18
-my %merge_rr = ();
19
-
20
-sub read_rr {
21
- if (!-f $merge_rr) {
22
- %merge_rr = ();
23
- return;
24
- }
25
- my $in;
26
- local $/ = "\0";
27
- open $in, "<$merge_rr" or die "$!: $merge_rr";
28
- while (<$in>) {
29
- chomp;
30
- my ($name, $path) = /^([0-9a-f]{40})\t(.*)$/s;
31
- $merge_rr{$path} = $name;
32
- }
33
- close $in;
34
-}
35
-
36
-sub write_rr {
37
- my $out;
38
- open $out, ">$merge_rr" or die "$!: $merge_rr";
39
- for my $path (sort keys %merge_rr) {
40
- my $name = $merge_rr{$path};
41
- print $out "$name\t$path\0";
42
- }
43
- close $out;
44
-}
45
-
46
-sub compute_conflict_name {
47
- my ($path) = @_;
48
- my @side = ();
49
- my $in;
50
- open $in, "<$path" or die "$!: $path";
51
-
52
- my $sha1 = Digest->new("SHA-1");
53
- my $hunk = 0;
54
- while (<$in>) {
55
- if (/^<<<<<<< .*/) {
56
- $hunk++;
57
- @side = ([], undef);
58
- }
59
- elsif (/^=======$/) {
60
- $side[1] = [];
61
- }
62
- elsif (/^>>>>>>> .*/) {
63
- my ($one, $two);
64
- $one = join('', @{$side[0]});
65
- $two = join('', @{$side[1]});
66
- if ($two le $one) {
67
- ($one, $two) = ($two, $one);
68
- }
69
- $sha1->add($one);
70
- $sha1->add("\0");
71
- $sha1->add($two);
72
- $sha1->add("\0");
73
- @side = ();
74
- }
75
- elsif (@side == 0) {
76
- next;
77
- }
78
- elsif (defined $side[1]) {
79
- push @{$side[1]}, $_;
80
- }
81
- else {
82
- push @{$side[0]}, $_;
83
- }
84
- }
85
- close $in;
86
- return ($sha1->hexdigest, $hunk);
87
-}
88
-
89
-sub record_preimage {
90
- my ($path, $name) = @_;
91
- my @side = ();
92
- my ($in, $out);
93
- open $in, "<$path" or die "$!: $path";
94
- open $out, ">$name" or die "$!: $name";
95
-
96
- while (<$in>) {
97
- if (/^<<<<<<< .*/) {
98
- @side = ([], undef);
99
- }
100
- elsif (/^=======$/) {
101
- $side[1] = [];
102
- }
103
- elsif (/^>>>>>>> .*/) {
104
- my ($one, $two);
105
- $one = join('', @{$side[0]});
106
- $two = join('', @{$side[1]});
107
- if ($two le $one) {
108
- ($one, $two) = ($two, $one);
109
- }
110
- print $out "<<<<<<<\n";
111
- print $out $one;
112
- print $out "=======\n";
113
- print $out $two;
114
- print $out ">>>>>>>\n";
115
- @side = ();
116
- }
117
- elsif (@side == 0) {
118
- print $out $_;
119
- }
120
- elsif (defined $side[1]) {
121
- push @{$side[1]}, $_;
122
- }
123
- else {
124
- push @{$side[0]}, $_;
125
- }
126
- }
127
- close $out;
128
- close $in;
129
-}
130
-
131
-sub find_conflict {
132
- my $in;
133
- local $/ = "\0";
134
- my $pid = open($in, '-|');
135
- die "$!" unless defined $pid;
136
- if (!$pid) {
137
- exec(qw(git ls-files -z -u)) or die "$!: ls-files";
138
- }
139
- my %path = ();
140
- my @path = ();
141
- while (<$in>) {
142
- chomp;
143
- my ($mode, $sha1, $stage, $path) =
144
- /^([0-7]+) ([0-9a-f]{40}) ([123])\t(.*)$/s;
145
- $path{$path} |= (1 << $stage);
146
- }
147
- close $in;
148
- while (my ($path, $status) = each %path) {
149
- if ($status == 14) { push @path, $path; }
150
- }
151
- return @path;
152
-}
153
-
154
-sub merge {
155
- my ($name, $path) = @_;
156
- record_preimage($path, "$rr_dir/$name/thisimage");
157
- unless (system('git', 'merge-file', map { "$rr_dir/$name/${_}image" }
158
- qw(this pre post))) {
159
- my $in;
160
- open $in, "<$rr_dir/$name/thisimage" or
161
- die "$!: $name/thisimage";
162
- my $out;
163
- open $out, ">$path" or die "$!: $path";
164
- while (<$in>) { print $out $_; }
165
- close $in;
166
- close $out;
167
- return 1;
168
- }
169
- return 0;
170
-}
171
-
172
-sub garbage_collect_rerere {
173
- # We should allow specifying these from the command line and
174
- # that is why the caller gives @ARGV to us, but I am lazy.
175
-
176
- my $cutoff_noresolve = 15; # two weeks
177
- my $cutoff_resolve = 60; # two months
178
- my @to_remove;
179
- while (<$rr_dir/*/preimage>) {
180
- my ($dir) = /^(.*)\/preimage$/;
181
- my $cutoff = ((-f "$dir/postimage")
182
- ? $cutoff_resolve
183
- : $cutoff_noresolve);
184
- my $age = -M "$_";
185
- if ($cutoff <= $age) {
186
- push @to_remove, $dir;
187
- }
188
- }
189
- if (@to_remove) {
190
- rmtree(\@to_remove);
191
- }
192
-}
193
-
194
--d "$rr_dir" || exit(0);
195
-
196
-read_rr();
197
-
198
-if (@ARGV) {
199
- my $arg = shift @ARGV;
200
- if ($arg eq 'clear') {
201
- for my $path (keys %merge_rr) {
202
- my $name = $merge_rr{$path};
203
- if (-d "$rr_dir/$name" &&
204
- ! -f "$rr_dir/$name/postimage") {
205
- rmtree(["$rr_dir/$name"]);
206
- }
207
- }
208
- unlink $merge_rr;
209
- }
210
- elsif ($arg eq 'status') {
211
- for my $path (keys %merge_rr) {
212
- print $path, "\n";
213
- }
214
- }
215
- elsif ($arg eq 'diff') {
216
- for my $path (keys %merge_rr) {
217
- my $name = $merge_rr{$path};
218
- system('diff', ((@ARGV == 0) ? ('-u') : @ARGV),
219
- '-L', "a/$path", '-L', "b/$path",
220
- "$rr_dir/$name/preimage", $path);
221
- }
222
- }
223
- elsif ($arg eq 'gc') {
224
- garbage_collect_rerere(@ARGV);
225
- }
226
- else {
227
- die "$0 unknown command: $arg\n";
228
- }
229
- exit 0;
230
-}
231
-
232
-my %conflict = map { $_ => 1 } find_conflict();
233
-
234
-# MERGE_RR records paths with conflicts immediately after merge
235
-# failed. Some of the conflicted paths might have been hand resolved
236
-# in the working tree since then, but the initial run would catch all
237
-# and register their preimages.
238
-
239
-for my $path (keys %conflict) {
240
- # This path has conflict. If it is not recorded yet,
241
- # record the pre-image.
242
- if (!exists $merge_rr{$path}) {
243
- my ($name, $hunk) = compute_conflict_name($path);
244
- next unless ($hunk);
245
- $merge_rr{$path} = $name;
246
- if (! -d "$rr_dir/$name") {
247
- mkpath("$rr_dir/$name", 0, 0777);
248
- print STDERR "Recorded preimage for '$path'\n";
249
- record_preimage($path, "$rr_dir/$name/preimage");
250
- }
251
- }
252
-}
253
-
254
-# Now some of the paths that had conflicts earlier might have been
255
-# hand resolved. Others may be similar to a conflict already that
256
-# was resolved before.
257
-
258
-for my $path (keys %merge_rr) {
259
- my $name = $merge_rr{$path};
260
-
261
- # We could resolve this automatically if we have images.
262
- if (-f "$rr_dir/$name/preimage" &&
263
- -f "$rr_dir/$name/postimage") {
264
- if (merge($name, $path)) {
265
- print STDERR "Resolved '$path' using previous resolution.\n";
266
- # Then we do not have to worry about this path
267
- # anymore.
268
- delete $merge_rr{$path};
269
- next;
270
- }
271
- }
272
-
273
- # Let's see if we have resolved it.
274
- (undef, my $hunk) = compute_conflict_name($path);
275
- next if ($hunk);
276
-
277
- print STDERR "Recorded resolution for '$path'.\n";
278
- copy($path, "$rr_dir/$name/postimage");
279
- # And we do not have to worry about this path anymore.
280
- delete $merge_rr{$path};
281
-}
282
-
283
-# Write out the rest.
284
-write_rr();
contrib/examples/git-reset.sh
deleted
-106
@@ -1,106 +0,0 @@
1
-#!/bin/sh
2
-#
3
-# Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano
4
-#
5
-USAGE='[--mixed | --soft | --hard] [<commit-ish>] [ [--] <paths>...]'
6
-SUBDIRECTORY_OK=Yes
7
-. git-sh-setup
8
-set_reflog_action "reset $*"
9
-require_work_tree
10
-
11
-update= reset_type=--mixed
12
-unset rev
13
-
14
-while test $# != 0
15
-do
16
- case "$1" in
17
- --mixed | --soft | --hard)
18
- reset_type="$1"
19
- ;;
20
- --)
21
- break
22
- ;;
23
- -*)
24
- usage
25
- ;;
26
- *)
27
- rev=$(git rev-parse --verify "$1") || exit
28
- shift
29
- break
30
- ;;
31
- esac
32
- shift
33
-done
34
-
35
-: ${rev=HEAD}
36
-rev=$(git rev-parse --verify $rev^0) || exit
37
-
38
-# Skip -- in "git reset HEAD -- foo" and "git reset -- foo".
39
-case "$1" in --) shift ;; esac
40
-
41
-# git reset --mixed tree [--] paths... can be used to
42
-# load chosen paths from the tree into the index without
43
-# affecting the working tree or HEAD.
44
-if test $# != 0
45
-then
46
- test "$reset_type" = "--mixed" ||
47
- die "Cannot do partial $reset_type reset."
48
-
49
- git diff-index --cached $rev -- "$@" |
50
- sed -e 's/^:\([0-7][0-7]*\) [0-7][0-7]* \([0-9a-f][0-9a-f]*\) [0-9a-f][0-9a-f]* [A-Z] \(.*\)$/\1 \2 \3/' |
51
- git update-index --add --remove --index-info || exit
52
- git update-index --refresh
53
- exit
54
-fi
55
-
56
-cd_to_toplevel
57
-
58
-if test "$reset_type" = "--hard"
59
-then
60
- update=-u
61
-fi
62
-
63
-# Soft reset does not touch the index file or the working tree
64
-# at all, but requires them in a good order. Other resets reset
65
-# the index file to the tree object we are switching to.
66
-if test "$reset_type" = "--soft"
67
-then
68
- if test -f "$GIT_DIR/MERGE_HEAD" ||
69
- test "" != "$(git ls-files --unmerged)"
70
- then
71
- die "Cannot do a soft reset in the middle of a merge."
72
- fi
73
-else
74
- git read-tree -v --reset $update "$rev" || exit
75
-fi
76
-
77
-# Any resets update HEAD to the head being switched to.
78
-if orig=$(git rev-parse --verify HEAD 2>/dev/null)
79
-then
80
- echo "$orig" >"$GIT_DIR/ORIG_HEAD"
81
-else
82
- rm -f "$GIT_DIR/ORIG_HEAD"
83
-fi
84
-git update-ref -m "$GIT_REFLOG_ACTION" HEAD "$rev"
85
-update_ref_status=$?
86
-
87
-case "$reset_type" in
88
---hard )
89
- test $update_ref_status = 0 && {
90
- printf "HEAD is now at "
91
- GIT_PAGER= git log --max-count=1 --pretty=oneline \
92
- --abbrev-commit HEAD
93
- }
94
- ;;
95
---soft )
96
- ;; # Nothing else to do
97
---mixed )
98
- # Report what has not been updated.
99
- git update-index --refresh
100
- ;;
101
-esac
102
-
103
-rm -f "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/rr-cache/MERGE_RR" \
104
- "$GIT_DIR/SQUASH_MSG" "$GIT_DIR/MERGE_MSG"
105
-
106
-exit $update_ref_status
contrib/examples/git-resolve.sh
deleted
-112
@@ -1,112 +0,0 @@
1
-#!/bin/sh
2
-#
3
-# Copyright (c) 2005 Linus Torvalds
4
-#
5
-# Resolve two trees.
6
-#
7
-
8
-echo 'WARNING: This command is DEPRECATED and will be removed very soon.' >&2
9
-echo 'WARNING: Please use git-merge or git-pull instead.' >&2
10
-sleep 2
11
-
12
-USAGE='<head> <remote> <merge-message>'
13
-. git-sh-setup
14
-
15
-dropheads() {
16
- rm -f -- "$GIT_DIR/MERGE_HEAD" \
17
- "$GIT_DIR/LAST_MERGE" || exit 1
18
-}
19
-
20
-head=$(git rev-parse --verify "$1"^0) &&
21
-merge=$(git rev-parse --verify "$2"^0) &&
22
-merge_name="$2" &&
23
-merge_msg="$3" || usage
24
-
25
-#
26
-# The remote name is just used for the message,
27
-# but we do want it.
28
-#
29
-if [ -z "$head" -o -z "$merge" -o -z "$merge_msg" ]; then
30
- usage
31
-fi
32
-
33
-dropheads
34
-echo $head > "$GIT_DIR"/ORIG_HEAD
35
-echo $merge > "$GIT_DIR"/LAST_MERGE
36
-
37
-common=$(git merge-base $head $merge)
38
-if [ -z "$common" ]; then
39
- die "Unable to find common commit between" $merge $head
40
-fi
41
-
42
-case "$common" in
43
-"$merge")
44
- echo "Already up to date. Yeeah!"
45
- dropheads
46
- exit 0
47
- ;;
48
-"$head")
49
- echo "Updating $(git rev-parse --short $head)..$(git rev-parse --short $merge)"
50
- git read-tree -u -m $head $merge || exit 1
51
- git update-ref -m "resolve $merge_name: Fast-forward" \
52
- HEAD "$merge" "$head"
53
- git diff-tree -p $head $merge | git apply --stat
54
- dropheads
55
- exit 0
56
- ;;
57
-esac
58
-
59
-# We are going to make a new commit.
60
-git var GIT_COMMITTER_IDENT >/dev/null || exit
61
-
62
-# Find an optimum merge base if there are more than one candidates.
63
-LF='
64
-'
65
-common=$(git merge-base -a $head $merge)
66
-case "$common" in
67
-?*"$LF"?*)
68
- echo "Trying to find the optimum merge base."
69
- G=.tmp-index$$
70
- best=
71
- best_cnt=-1
72
- for c in $common
73
- do
74
- rm -f $G
75
- GIT_INDEX_FILE=$G git read-tree -m $c $head $merge \
76
- 2>/dev/null || continue
77
- # Count the paths that are unmerged.
78
- cnt=$(GIT_INDEX_FILE=$G git ls-files --unmerged | wc -l)
79
- if test $best_cnt -le 0 || test $cnt -le $best_cnt
80
- then
81
- best=$c
82
- best_cnt=$cnt
83
- if test "$best_cnt" -eq 0
84
- then
85
- # Cannot do any better than all trivial merge.
86
- break
87
- fi
88
- fi
89
- done
90
- rm -f $G
91
- common="$best"
92
-esac
93
-
94
-echo "Trying to merge $merge into $head using $common."
95
-git update-index --refresh 2>/dev/null
96
-git read-tree -u -m $common $head $merge || exit 1
97
-result_tree=$(git write-tree 2> /dev/null)
98
-if [ $? -ne 0 ]; then
99
- echo "Simple merge failed, trying Automatic merge"
100
- git-merge-index -o git-merge-one-file -a
101
- if [ $? -ne 0 ]; then
102
- echo $merge > "$GIT_DIR"/MERGE_HEAD
103
- die "Automatic merge failed, fix up by hand"
104
- fi
105
- result_tree=$(git write-tree) || exit 1
106
-fi
107
-result_commit=$(echo "$merge_msg" | git commit-tree $result_tree -p $head -p $merge)
108
-echo "Committed merge $result_commit"
109
-git update-ref -m "resolve $merge_name: In-index merge" \
110
- HEAD "$result_commit" "$head"
111
-git diff-tree -p $head $result_commit | git apply --stat
112
-dropheads
contrib/examples/git-revert.sh
deleted
-207
@@ -1,207 +0,0 @@
1
-#!/bin/sh
2
-#
3
-# Copyright (c) 2005 Linus Torvalds
4
-# Copyright (c) 2005 Junio C Hamano
5
-#
6
-
7
-case "$0" in
8
-*-revert* )
9
- test -t 0 && edit=-e
10
- replay=
11
- me=revert
12
- USAGE='[--edit | --no-edit] [-n] <commit-ish>' ;;
13
-*-cherry-pick* )
14
- replay=t
15
- edit=
16
- me=cherry-pick
17
- USAGE='[--edit] [-n] [-r] [-x] <commit-ish>' ;;
18
-* )
19
- echo >&2 "What are you talking about?"
20
- exit 1 ;;
21
-esac
22
-
23
-SUBDIRECTORY_OK=Yes ;# we will cd up
24
-. git-sh-setup
25
-require_work_tree
26
-cd_to_toplevel
27
-
28
-no_commit=
29
-xopt=
30
-while case "$#" in 0) break ;; esac
31
-do
32
- case "$1" in
33
- -n|--n|--no|--no-|--no-c|--no-co|--no-com|--no-comm|\
34
- --no-commi|--no-commit)
35
- no_commit=t
36
- ;;
37
- -e|--e|--ed|--edi|--edit)
38
- edit=-e
39
- ;;
40
- --n|--no|--no-|--no-e|--no-ed|--no-edi|--no-edit)
41
- edit=
42
- ;;
43
- -r)
44
- : no-op ;;
45
- -x|--i-really-want-to-expose-my-private-commit-object-name)
46
- replay=
47
- ;;
48
- -X?*)
49
- xopt="$xopt$(git rev-parse --sq-quote "--${1#-X}")"
50
- ;;
51
- --strategy-option=*)
52
- xopt="$xopt$(git rev-parse --sq-quote "--${1#--strategy-option=}")"
53
- ;;
54
- -X|--strategy-option)
55
- shift
56
- xopt="$xopt$(git rev-parse --sq-quote "--$1")"
57
- ;;
58
- -*)
59
- usage
60
- ;;
61
- *)
62
- break
63
- ;;
64
- esac
65
- shift
66
-done
67
-
68
-set_reflog_action "$me"
69
-
70
-test "$me,$replay" = "revert,t" && usage
71
-
72
-case "$no_commit" in
73
-t)
74
- # We do not intend to commit immediately. We just want to
75
- # merge the differences in.
76
- head=$(git-write-tree) ||
77
- die "Your index file is unmerged."
78
- ;;
79
-*)
80
- head=$(git-rev-parse --verify HEAD) ||
81
- die "You do not have a valid HEAD"
82
- files=$(git-diff-index --cached --name-only $head) || exit
83
- if [ "$files" ]; then
84
- die "Dirty index: cannot $me (dirty: $files)"
85
- fi
86
- ;;
87
-esac
88
-
89
-rev=$(git-rev-parse --verify "$@") &&
90
-commit=$(git-rev-parse --verify "$rev^0") ||
91
- die "Not a single commit $@"
92
-prev=$(git-rev-parse --verify "$commit^1" 2>/dev/null) ||
93
- die "Cannot run $me a root commit"
94
-git-rev-parse --verify "$commit^2" >/dev/null 2>&1 &&
95
- die "Cannot run $me a multi-parent commit."
96
-
97
-encoding=$(git config i18n.commitencoding || echo UTF-8)
98
-
99
-# "commit" is an existing commit. We would want to apply
100
-# the difference it introduces since its first parent "prev"
101
-# on top of the current HEAD if we are cherry-pick. Or the
102
-# reverse of it if we are revert.
103
-
104
-case "$me" in
105
-revert)
106
- git show -s --pretty=oneline --encoding="$encoding" $commit |
107
- sed -e '
108
- s/^[^ ]* /Revert "/
109
- s/$/"/
110
- '
111
- echo
112
- echo "This reverts commit $commit."
113
- test "$rev" = "$commit" ||
114
- echo "(original 'git revert' arguments: $@)"
115
- base=$commit next=$prev
116
- ;;
117
-
118
-cherry-pick)
119
- pick_author_script='
120
- /^author /{
121
- s/'\''/'\''\\'\'\''/g
122
- h
123
- s/^author \([^<]*\) <[^>]*> .*$/\1/
124
- s/'\''/'\''\'\'\''/g
125
- s/.*/GIT_AUTHOR_NAME='\''&'\''/p
126
-
127
- g
128
- s/^author [^<]* <\([^>]*\)> .*$/\1/
129
- s/'\''/'\''\'\'\''/g
130
- s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
131
-
132
- g
133
- s/^author [^<]* <[^>]*> \(.*\)$/\1/
134
- s/'\''/'\''\'\'\''/g
135
- s/.*/GIT_AUTHOR_DATE='\''&'\''/p
136
-
137
- q
138
- }'
139
-
140
- logmsg=$(git show -s --pretty=raw --encoding="$encoding" "$commit")
141
- set_author_env=$(echo "$logmsg" |
142
- LANG=C LC_ALL=C sed -ne "$pick_author_script")
143
- eval "$set_author_env"
144
- export GIT_AUTHOR_NAME
145
- export GIT_AUTHOR_EMAIL
146
- export GIT_AUTHOR_DATE
147
-
148
- echo "$logmsg" |
149
- sed -e '1,/^$/d' -e 's/^ //'
150
- case "$replay" in
151
- '')
152
- echo "(cherry picked from commit $commit)"
153
- test "$rev" = "$commit" ||
154
- echo "(original 'git cherry-pick' arguments: $@)"
155
- ;;
156
- esac
157
- base=$prev next=$commit
158
- ;;
159
-
160
-esac >.msg
161
-
162
-eval GITHEAD_$head=HEAD
163
-eval GITHEAD_$next='$(git show -s \
164
- --pretty=oneline --encoding="$encoding" "$commit" |
165
- sed -e "s/^[^ ]* //")'
166
-export GITHEAD_$head GITHEAD_$next
167
-
168
-# This three way merge is an interesting one. We are at
169
-# $head, and would want to apply the change between $commit
170
-# and $prev on top of us (when reverting), or the change between
171
-# $prev and $commit on top of us (when cherry-picking or replaying).
172
-
173
-eval "git merge-recursive $xopt $base -- $head $next" &&
174
-result=$(git-write-tree 2>/dev/null) || {
175
- mv -f .msg "$GIT_DIR/MERGE_MSG"
176
- {
177
- echo '
178
-Conflicts:
179
-'
180
- git ls-files --unmerged |
181
- sed -e 's/^[^ ]* / /' |
182
- uniq
183
- } >>"$GIT_DIR/MERGE_MSG"
184
- echo >&2 "Automatic $me failed. After resolving the conflicts,"
185
- echo >&2 "mark the corrected paths with 'git-add <paths>'"
186
- echo >&2 "and commit the result."
187
- case "$me" in
188
- cherry-pick)
189
- echo >&2 "You may choose to use the following when making"
190
- echo >&2 "the commit:"
191
- echo >&2 "$set_author_env"
192
- esac
193
- exit 1
194
-}
195
-
196
-# If we are cherry-pick, and if the merge did not result in
197
-# hand-editing, we will hit this commit and inherit the original
198
-# author date and name.
199
-# If we are revert, or if our cherry-pick results in a hand merge,
200
-# we had better say that the current user is responsible for that.
201
-
202
-case "$no_commit" in
203
-'')
204
- git-commit -n -F .msg $edit
205
- rm -f .msg
206
- ;;
207
-esac
contrib/examples/git-svnimport.perl
deleted
-976
@@ -1,976 +0,0 @@
1
-#!/usr/bin/perl
2
-
3
-# This tool is copyright (c) 2005, Matthias Urlichs.
4
-# It is released under the Gnu Public License, version 2.
5
-#
6
-# The basic idea is to pull and analyze SVN changes.
7
-#
8
-# Checking out the files is done by a single long-running SVN connection.
9
-#
10
-# The head revision is on branch "origin" by default.
11
-# You can change that with the '-o' option.
12
-
13
-use strict;
14
-use warnings;
15
-use Getopt::Std;
16
-use File::Copy;
17
-use File::Spec;
18
-use File::Temp qw(tempfile);
19
-use File::Path qw(mkpath);
20
-use File::Basename qw(basename dirname);
21
-use Time::Local;
22
-use IO::Pipe;
23
-use POSIX qw(strftime dup2);
24
-use IPC::Open2;
25
-use SVN::Core;
26
-use SVN::Ra;
27
-
28
-die "Need SVN:Core 1.2.1 or better" if $SVN::Core::VERSION lt "1.2.1";
29
-
30
-$SIG{'PIPE'}="IGNORE";
31
-$ENV{'TZ'}="UTC";
32
-
33
-our($opt_h,$opt_o,$opt_v,$opt_u,$opt_C,$opt_i,$opt_m,$opt_M,$opt_t,$opt_T,
34
- $opt_b,$opt_r,$opt_I,$opt_A,$opt_s,$opt_l,$opt_d,$opt_D,$opt_S,$opt_F,
35
- $opt_P,$opt_R);
36
-
37
-sub usage() {
38
- print STDERR <<END;
39
-usage: ${\basename $0} # fetch/update GIT from SVN
40
- [-o branch-for-HEAD] [-h] [-v] [-l max_rev] [-R repack_each_revs]
41
- [-C GIT_repository] [-t tagname] [-T trunkname] [-b branchname]
42
- [-d|-D] [-i] [-u] [-r] [-I ignorefilename] [-s start_chg]
43
- [-m] [-M regex] [-A author_file] [-S] [-F] [-P project_name] [SVN_URL]
44
-END
45
- exit(1);
46
-}
47
-
48
-getopts("A:b:C:dDFhiI:l:mM:o:rs:t:T:SP:R:uv") or usage();
49
-usage if $opt_h;
50
-
51
-my $tag_name = $opt_t || "tags";
52
-my $trunk_name = defined $opt_T ? $opt_T : "trunk";
53
-my $branch_name = $opt_b || "branches";
54
-my $project_name = $opt_P || "";
55
-$project_name = "/" . $project_name if ($project_name);
56
-my $repack_after = $opt_R || 1000;
57
-my $root_pool = SVN::Pool->new_default;
58
-
59
-@ARGV == 1 or @ARGV == 2 or usage();
60
-
61
-$opt_o ||= "origin";
62
-$opt_s ||= 1;
63
-my $git_tree = $opt_C;
64
-$git_tree ||= ".";
65
-
66
-my $svn_url = $ARGV[0];
67
-my $svn_dir = $ARGV[1];
68
-
69
-our @mergerx = ();
70
-if ($opt_m) {
71
- my $branch_esc = quotemeta ($branch_name);
72
- my $trunk_esc = quotemeta ($trunk_name);
73
- @mergerx =
74
- (
75
- qr!\b(?:merg(?:ed?|ing))\b.*?\b((?:(?<=$branch_esc/)[\w\.\-]+)|(?:$trunk_esc))\b!i,
76
- qr!\b(?:from|of)\W+((?:(?<=$branch_esc/)[\w\.\-]+)|(?:$trunk_esc))\b!i,
77
- qr!\b(?:from|of)\W+(?:the )?([\w\.\-]+)[-\s]branch\b!i
78
- );
79
-}
80
-if ($opt_M) {
81
- unshift (@mergerx, qr/$opt_M/);
82
-}
83
-
84
-# Absolutize filename now, since we will have chdir'ed by the time we
85
-# get around to opening it.
86
-$opt_A = File::Spec->rel2abs($opt_A) if $opt_A;
87
-
88
-our %users = ();
89
-our $users_file = undef;
90
-sub read_users($) {
91
- $users_file = File::Spec->rel2abs(@_);
92
- die "Cannot open $users_file\n" unless -f $users_file;
93
- open(my $authors,$users_file);
94
- while(<$authors>) {
95
- chomp;
96
- next unless /^(\S+?)\s*=\s*(.+?)\s*<(.+)>\s*$/;
97
- (my $user,my $name,my $email) = ($1,$2,$3);
98
- $users{$user} = [$name,$email];
99
- }
100
- close($authors);
101
-}
102
-
103
-select(STDERR); $|=1; select(STDOUT);
104
-
105
-
106
-package SVNconn;
107
-# Basic SVN connection.
108
-# We're only interested in connecting and downloading, so ...
109
-
110
-use File::Spec;
111
-use File::Temp qw(tempfile);
112
-use POSIX qw(strftime dup2);
113
-use Fcntl qw(SEEK_SET);
114
-
115
-sub new {
116
- my($what,$repo) = @_;
117
- $what=ref($what) if ref($what);
118
-
119
- my $self = {};
120
- $self->{'buffer'} = "";
121
- bless($self,$what);
122
-
123
- $repo =~ s#/+$##;
124
- $self->{'fullrep'} = $repo;
125
- $self->conn();
126
-
127
- return $self;
128
-}
129
-
130
-sub conn {
131
- my $self = shift;
132
- my $repo = $self->{'fullrep'};
133
- my $auth = SVN::Core::auth_open ([SVN::Client::get_simple_provider,
134
- SVN::Client::get_ssl_server_trust_file_provider,
135
- SVN::Client::get_username_provider]);
136
- my $s = SVN::Ra->new(url => $repo, auth => $auth, pool => $root_pool);
137
- die "SVN connection to $repo: $!\n" unless defined $s;
138
- $self->{'svn'} = $s;
139
- $self->{'repo'} = $repo;
140
- $self->{'maxrev'} = $s->get_latest_revnum();
141
-}
142
-
143
-sub file {
144
- my($self,$path,$rev) = @_;
145
-
146
- my ($fh, $name) = tempfile('gitsvn.XXXXXX',
147
- DIR => File::Spec->tmpdir(), UNLINK => 1);
148
-
149
- print "... $rev $path ...\n" if $opt_v;
150
- my (undef, $properties);
151
- $path =~ s#^/*##;
152
- my $subpool = SVN::Pool::new_default_sub;
153
- eval { (undef, $properties)
154
- = $self->{'svn'}->get_file($path,$rev,$fh); };
155
- if($@) {
156
- return undef if $@ =~ /Attempted to get checksum/;
157
- die $@;
158
- }
159
- my $mode;
160
- if (exists $properties->{'svn:executable'}) {
161
- $mode = '100755';
162
- } elsif (exists $properties->{'svn:special'}) {
163
- my ($special_content, $filesize);
164
- $filesize = tell $fh;
165
- seek $fh, 0, SEEK_SET;
166
- read $fh, $special_content, $filesize;
167
- if ($special_content =~ s/^link //) {
168
- $mode = '120000';
169
- seek $fh, 0, SEEK_SET;
170
- truncate $fh, 0;
171
- print $fh $special_content;
172
- } else {
173
- die "unexpected svn:special file encountered";
174
- }
175
- } else {
176
- $mode = '100644';
177
- }
178
- close ($fh);
179
-
180
- return ($name, $mode);
181
-}
182
-
183
-sub ignore {
184
- my($self,$path,$rev) = @_;
185
-
186
- print "... $rev $path ...\n" if $opt_v;
187
- $path =~ s#^/*##;
188
- my $subpool = SVN::Pool::new_default_sub;
189
- my (undef,undef,$properties)
190
- = $self->{'svn'}->get_dir($path,$rev,undef);
191
- if (exists $properties->{'svn:ignore'}) {
192
- my ($fh, $name) = tempfile('gitsvn.XXXXXX',
193
- DIR => File::Spec->tmpdir(),
194
- UNLINK => 1);
195
- print $fh $properties->{'svn:ignore'};
196
- close($fh);
197
- return $name;
198
- } else {
199
- return undef;
200
- }
201
-}
202
-
203
-sub dir_list {
204
- my($self,$path,$rev) = @_;
205
- $path =~ s#^/*##;
206
- my $subpool = SVN::Pool::new_default_sub;
207
- my ($dirents,undef,$properties)
208
- = $self->{'svn'}->get_dir($path,$rev,undef);
209
- return $dirents;
210
-}
211
-
212
-package main;
213
-use URI;
214
-
215
-our $svn = $svn_url;
216
-$svn .= "/$svn_dir" if defined $svn_dir;
217
-my $svn2 = SVNconn->new($svn);
218
-$svn = SVNconn->new($svn);
219
-
220
-my $lwp_ua;
221
-if($opt_d or $opt_D) {
222
- $svn_url = URI->new($svn_url)->canonical;
223
- if($opt_D) {
224
- $svn_dir =~ s#/*$#/#;
225
- } else {
226
- $svn_dir = "";
227
- }
228
- if ($svn_url->scheme eq "http") {
229
- use LWP::UserAgent;
230
- $lwp_ua = LWP::UserAgent->new(keep_alive => 1, requests_redirectable => []);
231
- } else {
232
- print STDERR "Warning: not HTTP; turning off direct file access\n";
233
- $opt_d=0;
234
- }
235
-}
236
-
237
-sub pdate($) {
238
- my($d) = @_;
239
- $d =~ m#(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)#
240
- or die "Unparseable date: $d\n";
241
- my $y=$1; $y+=1900 if $y<1000;
242
- return timegm($6||0,$5,$4,$3,$2-1,$y);
243
-}
244
-
245
-sub getwd() {
246
- my $pwd = `pwd`;
247
- chomp $pwd;
248
- return $pwd;
249
-}
250
-
251
-
252
-sub get_headref($$) {
253
- my $name = shift;
254
- my $git_dir = shift;
255
- my $sha;
256
-
257
- if (open(C,"$git_dir/refs/heads/$name")) {
258
- chomp($sha = <C>);
259
- close(C);
260
- length($sha) == 40
261
- or die "Cannot get head id for $name ($sha): $!\n";
262
- }
263
- return $sha;
264
-}
265
-
266
-
267
--d $git_tree
268
- or mkdir($git_tree,0777)
269
- or die "Could not create $git_tree: $!";
270
-chdir($git_tree);
271
-
272
-my $orig_branch = "";
273
-my $forward_master = 0;
274
-my %branches;
275
-
276
-my $git_dir = $ENV{"GIT_DIR"} || ".git";
277
-$git_dir = getwd()."/".$git_dir unless $git_dir =~ m#^/#;
278
-$ENV{"GIT_DIR"} = $git_dir;
279
-my $orig_git_index;
280
-$orig_git_index = $ENV{GIT_INDEX_FILE} if exists $ENV{GIT_INDEX_FILE};
281
-my ($git_ih, $git_index) = tempfile('gitXXXXXX', SUFFIX => '.idx',
282
- DIR => File::Spec->tmpdir());
283
-close ($git_ih);
284
-$ENV{GIT_INDEX_FILE} = $git_index;
285
-my $maxnum = 0;
286
-my $last_rev = "";
287
-my $last_branch;
288
-my $current_rev = $opt_s || 1;
289
-unless(-d $git_dir) {
290
- system("git init");
291
- die "Cannot init the GIT db at $git_tree: $?\n" if $?;
292
- system("git read-tree --empty");
293
- die "Cannot init an empty tree: $?\n" if $?;
294
-
295
- $last_branch = $opt_o;
296
- $orig_branch = "";
297
-} else {
298
- -f "$git_dir/refs/heads/$opt_o"
299
- or die "Branch '$opt_o' does not exist.\n".
300
- "Either use the correct '-o branch' option,\n".
301
- "or import to a new repository.\n";
302
-
303
- -f "$git_dir/svn2git"
304
- or die "'$git_dir/svn2git' does not exist.\n".
305
- "You need that file for incremental imports.\n";
306
- open(F, "git symbolic-ref HEAD |") or
307
- die "Cannot run git-symbolic-ref: $!\n";
308
- chomp ($last_branch = <F>);
309
- $last_branch = basename($last_branch);
310
- close(F);
311
- unless($last_branch) {
312
- warn "Cannot read the last branch name: $! -- assuming 'master'\n";
313
- $last_branch = "master";
314
- }
315
- $orig_branch = $last_branch;
316
- $last_rev = get_headref($orig_branch, $git_dir);
317
- if (-f "$git_dir/SVN2GIT_HEAD") {
318
- die <<EOM;
319
-SVN2GIT_HEAD exists.
320
-Make sure your working directory corresponds to HEAD and remove SVN2GIT_HEAD.
321
-You may need to run
322
-
323
- git-read-tree -m -u SVN2GIT_HEAD HEAD
324
-EOM
325
- }
326
- system('cp', "$git_dir/HEAD", "$git_dir/SVN2GIT_HEAD");
327
-
328
- $forward_master =
329
- $opt_o ne 'master' && -f "$git_dir/refs/heads/master" &&
330
- system('cmp', '-s', "$git_dir/refs/heads/master",
331
- "$git_dir/refs/heads/$opt_o") == 0;
332
-
333
- # populate index
334
- system('git', 'read-tree', $last_rev);
335
- die "read-tree failed: $?\n" if $?;
336
-
337
- # Get the last import timestamps
338
- open my $B,"<", "$git_dir/svn2git";
339
- while(<$B>) {
340
- chomp;
341
- my($num,$branch,$ref) = split;
342
- $branches{$branch}{$num} = $ref;
343
- $branches{$branch}{"LAST"} = $ref;
344
- $current_rev = $num+1 if $current_rev <= $num;
345
- }
346
- close($B);
347
-}
348
--d $git_dir
349
- or die "Could not create git subdir ($git_dir).\n";
350
-
351
-my $default_authors = "$git_dir/svn-authors";
352
-if ($opt_A) {
353
- read_users($opt_A);
354
- copy($opt_A,$default_authors) or die "Copy failed: $!";
355
-} else {
356
- read_users($default_authors) if -f $default_authors;
357
-}
358
-
359
-open BRANCHES,">>", "$git_dir/svn2git";
360
-
361
-sub node_kind($$) {
362
- my ($svnpath, $revision) = @_;
363
- $svnpath =~ s#^/*##;
364
- my $subpool = SVN::Pool::new_default_sub;
365
- my $kind = $svn->{'svn'}->check_path($svnpath,$revision);
366
- return $kind;
367
-}
368
-
369
-sub get_file($$$) {
370
- my($svnpath,$rev,$path) = @_;
371
-
372
- # now get it
373
- my ($name,$mode);
374
- if($opt_d) {
375
- my($req,$res);
376
-
377
- # /svn/!svn/bc/2/django/trunk/django-docs/build.py
378
- my $url=$svn_url->clone();
379
- $url->path($url->path."/!svn/bc/$rev/$svn_dir$svnpath");
380
- print "... $path...\n" if $opt_v;
381
- $req = HTTP::Request->new(GET => $url);
382
- $res = $lwp_ua->request($req);
383
- if ($res->is_success) {
384
- my $fh;
385
- ($fh, $name) = tempfile('gitsvn.XXXXXX',
386
- DIR => File::Spec->tmpdir(), UNLINK => 1);
387
- print $fh $res->content;
388
- close($fh) or die "Could not write $name: $!\n";
389
- } else {
390
- return undef if $res->code == 301; # directory?
391
- die $res->status_line." at $url\n";
392
- }
393
- $mode = '0644'; # can't obtain mode via direct http request?
394
- } else {
395
- ($name,$mode) = $svn->file("$svnpath",$rev);
396
- return undef unless defined $name;
397
- }
398
-
399
- my $pid = open(my $F, '-|');
400
- die $! unless defined $pid;
401
- if (!$pid) {
402
- exec("git", "hash-object", "-w", $name)
403
- or die "Cannot create object: $!\n";
404
- }
405
- my $sha = <$F>;
406
- chomp $sha;
407
- close $F;
408
- unlink $name;
409
- return [$mode, $sha, $path];
410
-}
411
-
412
-sub get_ignore($$$$$) {
413
- my($new,$old,$rev,$path,$svnpath) = @_;
414
-
415
- return unless $opt_I;
416
- my $name = $svn->ignore("$svnpath",$rev);
417
- if ($path eq '/') {
418
- $path = $opt_I;
419
- } else {
420
- $path = File::Spec->catfile($path,$opt_I);
421
- }
422
- if (defined $name) {
423
- my $pid = open(my $F, '-|');
424
- die $! unless defined $pid;
425
- if (!$pid) {
426
- exec("git", "hash-object", "-w", $name)
427
- or die "Cannot create object: $!\n";
428
- }
429
- my $sha = <$F>;
430
- chomp $sha;
431
- close $F;
432
- unlink $name;
433
- push(@$new,['0644',$sha,$path]);
434
- } elsif (defined $old) {
435
- push(@$old,$path);
436
- }
437
-}
438
-
439
-sub project_path($$)
440
-{
441
- my ($path, $project) = @_;
442
-
443
- $path = "/".$path unless ($path =~ m#^\/#) ;
444
- return $1 if ($path =~ m#^$project\/(.*)$#);
445
-
446
- $path =~ s#\.#\\\.#g;
447
- $path =~ s#\+#\\\+#g;
448
- return "/" if ($project =~ m#^$path.*$#);
449
-
450
- return undef;
451
-}
452
-
453
-sub split_path($$) {
454
- my($rev,$path) = @_;
455
- my $branch;
456
-
457
- if($path =~ s#^/\Q$tag_name\E/([^/]+)/?##) {
458
- $branch = "/$1";
459
- } elsif($path =~ s#^/\Q$trunk_name\E/?##) {
460
- $branch = "/";
461
- } elsif($path =~ s#^/\Q$branch_name\E/([^/]+)/?##) {
462
- $branch = $1;
463
- } else {
464
- my %no_error = (
465
- "/" => 1,
466
- "/$tag_name" => 1,
467
- "/$branch_name" => 1
468
- );
469
- print STDERR "$rev: Unrecognized path: $path\n" unless (defined $no_error{$path});
470
- return ()
471
- }
472
- if ($path eq "") {
473
- $path = "/";
474
- } elsif ($project_name) {
475
- $path = project_path($path, $project_name);
476
- }
477
- return ($branch,$path);
478
-}
479
-
480
-sub branch_rev($$) {
481
-
482
- my ($srcbranch,$uptorev) = @_;
483
-
484
- my $bbranches = $branches{$srcbranch};
485
- my @revs = reverse sort { ($a eq 'LAST' ? 0 : $a) <=> ($b eq 'LAST' ? 0 : $b) } keys %$bbranches;
486
- my $therev;
487
- foreach my $arev(@revs) {
488
- next if ($arev eq 'LAST');
489
- if ($arev <= $uptorev) {
490
- $therev = $arev;
491
- last;
492
- }
493
- }
494
- return $therev;
495
-}
496
-
497
-sub expand_svndir($$$);
498
-
499
-sub expand_svndir($$$)
500
-{
501
- my ($svnpath, $rev, $path) = @_;
502
- my @list;
503
- get_ignore(\@list, undef, $rev, $path, $svnpath);
504
- my $dirents = $svn->dir_list($svnpath, $rev);
505
- foreach my $p(keys %$dirents) {
506
- my $kind = node_kind($svnpath.'/'.$p, $rev);
507
- if ($kind eq $SVN::Node::file) {
508
- my $f = get_file($svnpath.'/'.$p, $rev, $path.'/'.$p);
509
- push(@list, $f) if $f;
510
- } elsif ($kind eq $SVN::Node::dir) {
511
- push(@list,
512
- expand_svndir($svnpath.'/'.$p, $rev, $path.'/'.$p));
513
- }
514
- }
515
- return @list;
516
-}
517
-
518
-sub copy_path($$$$$$$$) {
519
- # Somebody copied a whole subdirectory.
520
- # We need to find the index entries from the old version which the
521
- # SVN log entry points to, and add them to the new place.
522
-
523
- my($newrev,$newbranch,$path,$oldpath,$rev,$node_kind,$new,$parents) = @_;
524
-
525
- my($srcbranch,$srcpath) = split_path($rev,$oldpath);
526
- unless(defined $srcbranch && defined $srcpath) {
527
- print "Path not found when copying from $oldpath @ $rev.\n".
528
- "Will try to copy from original SVN location...\n"
529
- if $opt_v;
530
- push (@$new, expand_svndir($oldpath, $rev, $path));
531
- return;
532
- }
533
- my $therev = branch_rev($srcbranch, $rev);
534
- my $gitrev = $branches{$srcbranch}{$therev};
535
- unless($gitrev) {
536
- print STDERR "$newrev:$newbranch: could not find $oldpath \@ $rev\n";
537
- return;
538
- }
539
- if ($srcbranch ne $newbranch) {
540
- push(@$parents, $branches{$srcbranch}{'LAST'});
541
- }
542
- print "$newrev:$newbranch:$path: copying from $srcbranch:$srcpath @ $rev\n" if $opt_v;
543
- if ($node_kind eq $SVN::Node::dir) {
544
- $srcpath =~ s#/*$#/#;
545
- }
546
-
547
- my $pid = open my $f,'-|';
548
- die $! unless defined $pid;
549
- if (!$pid) {
550
- exec("git","ls-tree","-r","-z",$gitrev,$srcpath)
551
- or die $!;
552
- }
553
- local $/ = "\0";
554
- while(<$f>) {
555
- chomp;
556
- my($m,$p) = split(/\t/,$_,2);
557
- my($mode,$type,$sha1) = split(/ /,$m);
558
- next if $type ne "blob";
559
- if ($node_kind eq $SVN::Node::dir) {
560
- $p = $path . substr($p,length($srcpath)-1);
561
- } else {
562
- $p = $path;
563
- }
564
- push(@$new,[$mode,$sha1,$p]);
565
- }
566
- close($f) or
567
- print STDERR "$newrev:$newbranch: could not list files in $oldpath \@ $rev\n";
568
-}
569
-
570
-sub commit {
571
- my($branch, $changed_paths, $revision, $author, $date, $message) = @_;
572
- my($committer_name,$committer_email,$dest);
573
- my($author_name,$author_email);
574
- my(@old,@new,@parents);
575
-
576
- if (not defined $author or $author eq "") {
577
- $committer_name = $committer_email = "unknown";
578
- } elsif (defined $users_file) {
579
- die "User $author is not listed in $users_file\n"
580
- unless exists $users{$author};
581
- ($committer_name,$committer_email) = @{$users{$author}};
582
- } elsif ($author =~ /^(.*?)\s+<(.*)>$/) {
583
- ($committer_name, $committer_email) = ($1, $2);
584
- } else {
585
- $author =~ s/^<(.*)>$/$1/;
586
- $committer_name = $committer_email = $author;
587
- }
588
-
589
- if ($opt_F && $message =~ /From:\s+(.*?)\s+<(.*)>\s*\n/) {
590
- ($author_name, $author_email) = ($1, $2);
591
- print "Author from From: $1 <$2>\n" if ($opt_v);;
592
- } elsif ($opt_S && $message =~ /Signed-off-by:\s+(.*?)\s+<(.*)>\s*\n/) {
593
- ($author_name, $author_email) = ($1, $2);
594
- print "Author from Signed-off-by: $1 <$2>\n" if ($opt_v);;
595
- } else {
596
- $author_name = $committer_name;
597
- $author_email = $committer_email;
598
- }
599
-
600
- $date = pdate($date);
601
-
602
- my $tag;
603
- my $parent;
604
- if($branch eq "/") { # trunk
605
- $parent = $opt_o;
606
- } elsif($branch =~ m#^/(.+)#) { # tag
607
- $tag = 1;
608
- $parent = $1;
609
- } else { # "normal" branch
610
- # nothing to do
611
- $parent = $branch;
612
- }
613
- $dest = $parent;
614
-
615
- my $prev = $changed_paths->{"/"};
616
- if($prev and $prev->[0] eq "A") {
617
- delete $changed_paths->{"/"};
618
- my $oldpath = $prev->[1];
619
- my $rev;
620
- if(defined $oldpath) {
621
- my $p;
622
- ($parent,$p) = split_path($revision,$oldpath);
623
- if(defined $parent) {
624
- if($parent eq "/") {
625
- $parent = $opt_o;
626
- } else {
627
- $parent =~ s#^/##; # if it's a tag
628
- }
629
- }
630
- } else {
631
- $parent = undef;
632
- }
633
- }
634
-
635
- my $rev;
636
- if($revision > $opt_s and defined $parent) {
637
- open(H,'-|',"git","rev-parse","--verify",$parent);
638
- $rev = <H>;
639
- close(H) or do {
640
- print STDERR "$revision: cannot find commit '$parent'!\n";
641
- return;
642
- };
643
- chop $rev;
644
- if(length($rev) != 40) {
645
- print STDERR "$revision: cannot find commit '$parent'!\n";
646
- return;
647
- }
648
- $rev = $branches{($parent eq $opt_o) ? "/" : $parent}{"LAST"};
649
- if($revision != $opt_s and not $rev) {
650
- print STDERR "$revision: do not know ancestor for '$parent'!\n";
651
- return;
652
- }
653
- } else {
654
- $rev = undef;
655
- }
656
-
657
-# if($prev and $prev->[0] eq "A") {
658
-# if(not $tag) {
659
-# unless(open(H,"> $git_dir/refs/heads/$branch")) {
660
-# print STDERR "$revision: Could not create branch $branch: $!\n";
661
-# $state=11;
662
-# next;
663
-# }
664
-# print H "$rev\n"
665
-# or die "Could not write branch $branch: $!";
666
-# close(H)
667
-# or die "Could not write branch $branch: $!";
668
-# }
669
-# }
670
- if(not defined $rev) {
671
- unlink($git_index);
672
- } elsif ($rev ne $last_rev) {
673
- print "Switching from $last_rev to $rev ($branch)\n" if $opt_v;
674
- system("git", "read-tree", $rev);
675
- die "read-tree failed for $rev: $?\n" if $?;
676
- $last_rev = $rev;
677
- }
678
-
679
- push (@parents, $rev) if defined $rev;
680
-
681
- my $cid;
682
- if($tag and not %$changed_paths) {
683
- $cid = $rev;
684
- } else {
685
- my @paths = sort keys %$changed_paths;
686
- foreach my $path(@paths) {
687
- my $action = $changed_paths->{$path};
688
-
689
- if ($action->[0] eq "R") {
690
- # refer to a file/tree in an earlier commit
691
- push(@old,$path); # remove any old stuff
692
- }
693
- if(($action->[0] eq "A") || ($action->[0] eq "R")) {
694
- my $node_kind = node_kind($action->[3], $revision);
695
- if ($node_kind eq $SVN::Node::file) {
696
- my $f = get_file($action->[3],
697
- $revision, $path);
698
- if ($f) {
699
- push(@new,$f) if $f;
700
- } else {
701
- my $opath = $action->[3];
702
- print STDERR "$revision: $branch: could not fetch '$opath'\n";
703
- }
704
- } elsif ($node_kind eq $SVN::Node::dir) {
705
- if($action->[1]) {
706
- copy_path($revision, $branch,
707
- $path, $action->[1],
708
- $action->[2], $node_kind,
709
- \@new, \@parents);
710
- } else {
711
- get_ignore(\@new, \@old, $revision,
712
- $path, $action->[3]);
713
- }
714
- }
715
- } elsif ($action->[0] eq "D") {
716
- push(@old,$path);
717
- } elsif ($action->[0] eq "M") {
718
- my $node_kind = node_kind($action->[3], $revision);
719
- if ($node_kind eq $SVN::Node::file) {
720
- my $f = get_file($action->[3],
721
- $revision, $path);
722
- push(@new,$f) if $f;
723
- } elsif ($node_kind eq $SVN::Node::dir) {
724
- get_ignore(\@new, \@old, $revision,
725
- $path, $action->[3]);
726
- }
727
- } else {
728
- die "$revision: unknown action '".$action->[0]."' for $path\n";
729
- }
730
- }
731
-
732
- while(@old) {
733
- my @o1;
734
- if(@old > 55) {
735
- @o1 = splice(@old,0,50);
736
- } else {
737
- @o1 = @old;
738
- @old = ();
739
- }
740
- my $pid = open my $F, "-|";
741
- die "$!" unless defined $pid;
742
- if (!$pid) {
743
- exec("git", "ls-files", "-z", @o1) or die $!;
744
- }
745
- @o1 = ();
746
- local $/ = "\0";
747
- while(<$F>) {
748
- chomp;
749
- push(@o1,$_);
750
- }
751
- close($F);
752
-
753
- while(@o1) {
754
- my @o2;
755
- if(@o1 > 55) {
756
- @o2 = splice(@o1,0,50);
757
- } else {
758
- @o2 = @o1;
759
- @o1 = ();
760
- }
761
- system("git","update-index","--force-remove","--",@o2);
762
- die "Cannot remove files: $?\n" if $?;
763
- }
764
- }
765
- while(@new) {
766
- my @n2;
767
- if(@new > 12) {
768
- @n2 = splice(@new,0,10);
769
- } else {
770
- @n2 = @new;
771
- @new = ();
772
- }
773
- system("git","update-index","--add",
774
- (map { ('--cacheinfo', @$_) } @n2));
775
- die "Cannot add files: $?\n" if $?;
776
- }
777
-
778
- my $pid = open(C,"-|");
779
- die "Cannot fork: $!" unless defined $pid;
780
- unless($pid) {
781
- exec("git","write-tree");
782
- die "Cannot exec git-write-tree: $!\n";
783
- }
784
- chomp(my $tree = <C>);
785
- length($tree) == 40
786
- or die "Cannot get tree id ($tree): $!\n";
787
- close(C)
788
- or die "Error running git-write-tree: $?\n";
789
- print "Tree ID $tree\n" if $opt_v;
790
-
791
- my $pr = IO::Pipe->new() or die "Cannot open pipe: $!\n";
792
- my $pw = IO::Pipe->new() or die "Cannot open pipe: $!\n";
793
- $pid = fork();
794
- die "Fork: $!\n" unless defined $pid;
795
- unless($pid) {
796
- $pr->writer();
797
- $pw->reader();
798
- open(OUT,">&STDOUT");
799
- dup2($pw->fileno(),0);
800
- dup2($pr->fileno(),1);
801
- $pr->close();
802
- $pw->close();
803
-
804
- my @par = ();
805
-
806
- # loose detection of merges
807
- # based on the commit msg
808
- foreach my $rx (@mergerx) {
809
- if ($message =~ $rx) {
810
- my $mparent = $1;
811
- if ($mparent eq 'HEAD') { $mparent = $opt_o };
812
- if ( -e "$git_dir/refs/heads/$mparent") {
813
- $mparent = get_headref($mparent, $git_dir);
814
- push (@parents, $mparent);
815
- print OUT "Merge parent branch: $mparent\n" if $opt_v;
816
- }
817
- }
818
- }
819
- my %seen_parents = ();
820
- my @unique_parents = grep { ! $seen_parents{$_} ++ } @parents;
821
- foreach my $bparent (@unique_parents) {
822
- push @par, '-p', $bparent;
823
- print OUT "Merge parent branch: $bparent\n" if $opt_v;
824
- }
825
-
826
- exec("env",
827
- "GIT_AUTHOR_NAME=$author_name",
828
- "GIT_AUTHOR_EMAIL=$author_email",
829
- "GIT_AUTHOR_DATE=".strftime("+0000 %Y-%m-%d %H:%M:%S",gmtime($date)),
830
- "GIT_COMMITTER_NAME=$committer_name",
831
- "GIT_COMMITTER_EMAIL=$committer_email",
832
- "GIT_COMMITTER_DATE=".strftime("+0000 %Y-%m-%d %H:%M:%S",gmtime($date)),
833
- "git", "commit-tree", $tree,@par);
834
- die "Cannot exec git-commit-tree: $!\n";
835
- }
836
- $pw->writer();
837
- $pr->reader();
838
-
839
- $message =~ s/[\s\n]+\z//;
840
- $message = "r$revision: $message" if $opt_r;
841
-
842
- print $pw "$message\n"
843
- or die "Error writing to git-commit-tree: $!\n";
844
- $pw->close();
845
-
846
- print "Committed change $revision:$branch ".strftime("%Y-%m-%d %H:%M:%S",gmtime($date)).")\n" if $opt_v;
847
- chomp($cid = <$pr>);
848
- length($cid) == 40
849
- or die "Cannot get commit id ($cid): $!\n";
850
- print "Commit ID $cid\n" if $opt_v;
851
- $pr->close();
852
-
853
- waitpid($pid,0);
854
- die "Error running git-commit-tree: $?\n" if $?;
855
- }
856
-
857
- if (not defined $cid) {
858
- $cid = $branches{"/"}{"LAST"};
859
- }
860
-
861
- if(not defined $dest) {
862
- print "... no known parent\n" if $opt_v;
863
- } elsif(not $tag) {
864
- print "Writing to refs/heads/$dest\n" if $opt_v;
865
- open(C,">$git_dir/refs/heads/$dest") and
866
- print C ("$cid\n") and
867
- close(C)
868
- or die "Cannot write branch $dest for update: $!\n";
869
- }
870
-
871
- if ($tag) {
872
- $last_rev = "-" if %$changed_paths;
873
- # the tag was 'complex', i.e. did not refer to a "real" revision
874
-
875
- $dest =~ tr/_/\./ if $opt_u;
876
-
877
- system('git', 'tag', '-f', $dest, $cid) == 0
878
- or die "Cannot create tag $dest: $!\n";
879
-
880
- print "Created tag '$dest' on '$branch'\n" if $opt_v;
881
- }
882
- $branches{$branch}{"LAST"} = $cid;
883
- $branches{$branch}{$revision} = $cid;
884
- $last_rev = $cid;
885
- print BRANCHES "$revision $branch $cid\n";
886
- print "DONE: $revision $dest $cid\n" if $opt_v;
887
-}
888
-
889
-sub commit_all {
890
- # Recursive use of the SVN connection does not work
891
- local $svn = $svn2;
892
-
893
- my ($changed_paths, $revision, $author, $date, $message) = @_;
894
- my %p;
895
- while(my($path,$action) = each %$changed_paths) {
896
- $p{$path} = [ $action->action,$action->copyfrom_path, $action->copyfrom_rev, $path ];
897
- }
898
- $changed_paths = \%p;
899
-
900
- my %done;
901
- my @col;
902
- my $pref;
903
- my $branch;
904
-
905
- while(my($path,$action) = each %$changed_paths) {
906
- ($branch,$path) = split_path($revision,$path);
907
- next if not defined $branch;
908
- next if not defined $path;
909
- $done{$branch}{$path} = $action;
910
- }
911
- while(($branch,$changed_paths) = each %done) {
912
- commit($branch, $changed_paths, $revision, $author, $date, $message);
913
- }
914
-}
915
-
916
-$opt_l = $svn->{'maxrev'} if not defined $opt_l or $opt_l > $svn->{'maxrev'};
917
-
918
-if ($opt_l < $current_rev) {
919
- print "Up to date: no new revisions to fetch!\n" if $opt_v;
920
- unlink("$git_dir/SVN2GIT_HEAD");
921
- exit;
922
-}
923
-
924
-print "Processing from $current_rev to $opt_l ...\n" if $opt_v;
925
-
926
-my $from_rev;
927
-my $to_rev = $current_rev - 1;
928
-
929
-my $subpool = SVN::Pool::new_default_sub;
930
-while ($to_rev < $opt_l) {
931
- $subpool->clear;
932
- $from_rev = $to_rev + 1;
933
- $to_rev = $from_rev + $repack_after;
934
- $to_rev = $opt_l if $opt_l < $to_rev;
935
- print "Fetching from $from_rev to $to_rev ...\n" if $opt_v;
936
- $svn->{'svn'}->get_log("",$from_rev,$to_rev,0,1,1,\&commit_all);
937
- my $pid = fork();
938
- die "Fork: $!\n" unless defined $pid;
939
- unless($pid) {
940
- exec("git", "repack", "-d")
941
- or die "Cannot repack: $!\n";
942
- }
943
- waitpid($pid, 0);
944
-}
945
-
946
-
947
-unlink($git_index);
948
-
949
-if (defined $orig_git_index) {
950
- $ENV{GIT_INDEX_FILE} = $orig_git_index;
951
-} else {
952
- delete $ENV{GIT_INDEX_FILE};
953
-}
954
-
955
-# Now switch back to the branch we were in before all of this happened
956
-if($orig_branch) {
957
- print "DONE\n" if $opt_v and (not defined $opt_l or $opt_l > 0);
958
- system("cp","$git_dir/refs/heads/$opt_o","$git_dir/refs/heads/master")
959
- if $forward_master;
960
- unless ($opt_i) {
961
- system('git', 'read-tree', '-m', '-u', 'SVN2GIT_HEAD', 'HEAD');
962
- die "read-tree failed: $?\n" if $?;
963
- }
964
-} else {
965
- $orig_branch = "master";
966
- print "DONE; creating $orig_branch branch\n" if $opt_v and (not defined $opt_l or $opt_l > 0);
967
- system("cp","$git_dir/refs/heads/$opt_o","$git_dir/refs/heads/master")
968
- unless -f "$git_dir/refs/heads/master";
969
- system('git', 'update-ref', 'HEAD', "$orig_branch");
970
- unless ($opt_i) {
971
- system('git checkout');
972
- die "checkout failed: $?\n" if $?;
973
- }
974
-}
975
-unlink("$git_dir/SVN2GIT_HEAD");
976
-close(BRANCHES);
contrib/examples/git-svnimport.txt
deleted
-179
@@ -1,179 +0,0 @@
1
-git-svnimport(1)
2
-================
3
-v0.1, July 2005
4
-
5
-NAME
6
-----
7
-git-svnimport - Import a SVN repository into git
8
-
9
-
10
-SYNOPSIS
11
---------
12
-[verse]
13
-'git-svnimport' [ -o <branch-for-HEAD> ] [ -h ] [ -v ] [ -d | -D ]
14
- [ -C <GIT_repository> ] [ -i ] [ -u ] [-l limit_rev]
15
- [ -b branch_subdir ] [ -T trunk_subdir ] [ -t tag_subdir ]
16
- [ -s start_chg ] [ -m ] [ -r ] [ -M regex ]
17
- [ -I <ignorefile_name> ] [ -A <author_file> ]
18
- [ -R <repack_each_revs>] [ -P <path_from_trunk> ]
19
- <SVN_repository_URL> [ <path> ]
20
-
21
-
22
-DESCRIPTION
23
------------
24
-Imports a SVN repository into git. It will either create a new
25
-repository, or incrementally import into an existing one.
26
-
27
-SVN access is done by the SVN::Perl module.
28
-
29
-git-svnimport assumes that SVN repositories are organized into one
30
-"trunk" directory where the main development happens, "branches/FOO"
31
-directories for branches, and "/tags/FOO" directories for tags.
32
-Other subdirectories are ignored.
33
-
34
-git-svnimport creates a file ".git/svn2git", which is required for
35
-incremental SVN imports.
36
-
37
-OPTIONS
38
--------
39
--C <target-dir>::
40
- The GIT repository to import to. If the directory doesn't
41
- exist, it will be created. Default is the current directory.
42
-
43
--s <start_rev>::
44
- Start importing at this SVN change number. The default is 1.
45
-+
46
-When importing incrementally, you might need to edit the .git/svn2git file.
47
-
48
--i::
49
- Import-only: don't perform a checkout after importing. This option
50
- ensures the working directory and index remain untouched and will
51
- not create them if they do not exist.
52
-
53
--T <trunk_subdir>::
54
- Name the SVN trunk. Default "trunk".
55
-
56
--t <tag_subdir>::
57
- Name the SVN subdirectory for tags. Default "tags".
58
-
59
--b <branch_subdir>::
60
- Name the SVN subdirectory for branches. Default "branches".
61
-
62
--o <branch-for-HEAD>::
63
- The 'trunk' branch from SVN is imported to the 'origin' branch within
64
- the git repository. Use this option if you want to import into a
65
- different branch.
66
-
67
--r::
68
- Prepend 'rX: ' to commit messages, where X is the imported
69
- subversion revision.
70
-
71
--u::
72
- Replace underscores in tag names with periods.
73
-
74
--I <ignorefile_name>::
75
- Import the svn:ignore directory property to files with this
76
- name in each directory. (The Subversion and GIT ignore
77
- syntaxes are similar enough that using the Subversion patterns
78
- directly with "-I .gitignore" will almost always just work.)
79
-
80
--A <author_file>::
81
- Read a file with lines on the form
82
-+
83
-------
84
- username = User's Full Name <email@addr.es>
85
-
86
-------
87
-+
88
-and use "User's Full Name <email@addr.es>" as the GIT
89
-author and committer for Subversion commits made by
90
-"username". If encountering a commit made by a user not in the
91
-list, abort.
92
-+
93
-For convenience, this data is saved to $GIT_DIR/svn-authors
94
-each time the -A option is provided, and read from that same
95
-file each time git-svnimport is run with an existing GIT
96
-repository without -A.
97
-
98
--m::
99
- Attempt to detect merges based on the commit message. This option
100
- will enable default regexes that try to capture the name source
101
- branch name from the commit message.
102
-
103
--M <regex>::
104
- Attempt to detect merges based on the commit message with a custom
105
- regex. It can be used with -m to also see the default regexes.
106
- You must escape forward slashes.
107
-
108
--l <max_rev>::
109
- Specify a maximum revision number to pull.
110
-+
111
-Formerly, this option controlled how many revisions to pull,
112
-due to SVN memory leaks. (These have been worked around.)
113
-
114
--R <repack_each_revs>::
115
- Specify how often git repository should be repacked.
116
-+
117
-The default value is 1000. git-svnimport will do imports in chunks of 1000
118
-revisions, after each chunk the git repository will be repacked. To disable
119
-this behavior specify some large value here which is greater than the number of
120
-revisions to import.
121
-
122
--P <path_from_trunk>::
123
- Partial import of the SVN tree.
124
-+
125
-By default, the whole tree on the SVN trunk (/trunk) is imported.
126
-'-P my/proj' will import starting only from '/trunk/my/proj'.
127
-This option is useful when you want to import one project from a
128
-svn repo which hosts multiple projects under the same trunk.
129
-
130
--v::
131
- Verbosity: let 'svnimport' report what it is doing.
132
-
133
--d::
134
- Use direct HTTP requests if possible. The "<path>" argument is used
135
- only for retrieving the SVN logs; the path to the contents is
136
- included in the SVN log.
137
-
138
--D::
139
- Use direct HTTP requests if possible. The "<path>" argument is used
140
- for retrieving the logs, as well as for the contents.
141
-+
142
-There's no safe way to automatically find out which of these options to
143
-use, so you need to try both. Usually, the one that's wrong will die
144
-with a 40x error pretty quickly.
145
-
146
-<SVN_repository_URL>::
147
- The URL of the SVN module you want to import. For local
148
- repositories, use "file:///absolute/path".
149
-+
150
-If you're using the "-d" or "-D" option, this is the URL of the SVN
151
-repository itself; it usually ends in "/svn".
152
-
153
-<path>::
154
- The path to the module you want to check out.
155
-
156
--h::
157
- Print a short usage message and exit.
158
-
159
-OUTPUT
160
-------
161
-If '-v' is specified, the script reports what it is doing.
162
-
163
-Otherwise, success is indicated the Unix way, i.e. by simply exiting with
164
-a zero exit status.
165
-
166
-Author
167
-------
168
-Written by Matthias Urlichs <smurf@smurf.noris.de>, with help from
169
-various participants of the git-list <git@vger.kernel.org>.
170
-
171
-Based on a cvs2git script by the same author.
172
-
173
-Documentation
174
---------------
175
-Documentation by Matthias Urlichs <smurf@smurf.noris.de>.
176
-
177
-GIT
178
----
179
-Part of the linkgit:git[7] suite
contrib/examples/git-tag.sh
deleted
-205
@@ -1,205 +0,0 @@
1
-#!/bin/sh
2
-# Copyright (c) 2005 Linus Torvalds
3
-
4
-USAGE='[-n [<num>]] -l [<pattern>] | [-a | -s | -u <key-id>] [-f | -d | -v] [-m <msg>] <tagname> [<head>]'
5
-SUBDIRECTORY_OK='Yes'
6
-. git-sh-setup
7
-
8
-message_given=
9
-annotate=
10
-signed=
11
-force=
12
-message=
13
-username=
14
-list=
15
-verify=
16
-LINES=0
17
-while test $# != 0
18
-do
19
- case "$1" in
20
- -a)
21
- annotate=1
22
- shift
23
- ;;
24
- -s)
25
- annotate=1
26
- signed=1
27
- shift
28
- ;;
29
- -f)
30
- force=1
31
- shift
32
- ;;
33
- -n)
34
- case "$#,$2" in
35
- 1,* | *,-*)
36
- LINES=1 # no argument
37
- ;;
38
- *) shift
39
- LINES=$(expr "$1" : '\([0-9]*\)')
40
- [ -z "$LINES" ] && LINES=1 # 1 line is default when -n is used
41
- ;;
42
- esac
43
- shift
44
- ;;
45
- -l)
46
- list=1
47
- shift
48
- case $# in
49
- 0) PATTERN=
50
- ;;
51
- *)
52
- PATTERN="$1" # select tags by shell pattern, not re
53
- shift
54
- ;;
55
- esac
56
- git rev-parse --symbolic --tags | sort |
57
- while read TAG
58
- do
59
- case "$TAG" in
60
- *$PATTERN*) ;;
61
- *) continue ;;
62
- esac
63
- [ "$LINES" -le 0 ] && { echo "$TAG"; continue ;}
64
- OBJTYPE=$(git cat-file -t "$TAG")
65
- case $OBJTYPE in
66
- tag)
67
- ANNOTATION=$(git cat-file tag "$TAG" |
68
- sed -e '1,/^$/d' |
69
- sed -n -e "
70
- /^-----BEGIN PGP SIGNATURE-----\$/q
71
- 2,\$s/^/ /
72
- p
73
- ${LINES}q
74
- ")
75
- printf "%-15s %s\n" "$TAG" "$ANNOTATION"
76
- ;;
77
- *) echo "$TAG"
78
- ;;
79
- esac
80
- done
81
- ;;
82
- -m)
83
- annotate=1
84
- shift
85
- message="$1"
86
- if test "$#" = "0"; then
87
- die "error: option -m needs an argument"
88
- else
89
- message="$1"
90
- message_given=1
91
- shift
92
- fi
93
- ;;
94
- -F)
95
- annotate=1
96
- shift
97
- if test "$#" = "0"; then
98
- die "error: option -F needs an argument"
99
- else
100
- message="$(cat "$1")"
101
- message_given=1
102
- shift
103
- fi
104
- ;;
105
- -u)
106
- annotate=1
107
- signed=1
108
- shift
109
- if test "$#" = "0"; then
110
- die "error: option -u needs an argument"
111
- else
112
- username="$1"
113
- shift
114
- fi
115
- ;;
116
- -d)
117
- shift
118
- had_error=0
119
- for tag
120
- do
121
- cur=$(git show-ref --verify --hash -- "refs/tags/$tag") || {
122
- echo >&2 "Seriously, what tag are you talking about?"
123
- had_error=1
124
- continue
125
- }
126
- git update-ref -m 'tag: delete' -d "refs/tags/$tag" "$cur" || {
127
- had_error=1
128
- continue
129
- }
130
- echo "Deleted tag $tag."
131
- done
132
- exit $had_error
133
- ;;
134
- -v)
135
- shift
136
- tag_name="$1"
137
- tag=$(git show-ref --verify --hash -- "refs/tags/$tag_name") ||
138
- die "Seriously, what tag are you talking about?"
139
- git-verify-tag -v "$tag"
140
- exit $?
141
- ;;
142
- -*)
143
- usage
144
- ;;
145
- *)
146
- break
147
- ;;
148
- esac
149
-done
150
-
151
-[ -n "$list" ] && exit 0
152
-
153
-name="$1"
154
-[ "$name" ] || usage
155
-prev=0000000000000000000000000000000000000000
156
-if git show-ref --verify --quiet -- "refs/tags/$name"
157
-then
158
- test -n "$force" || die "tag '$name' already exists"
159
- prev=$(git rev-parse "refs/tags/$name")
160
-fi
161
-shift
162
-git check-ref-format "tags/$name" ||
163
- die "we do not like '$name' as a tag name."
164
-
165
-object=$(git rev-parse --verify --default HEAD "$@") || exit 1
166
-type=$(git cat-file -t $object) || exit 1
167
-tagger=$(git var GIT_COMMITTER_IDENT) || exit 1
168
-
169
-test -n "$username" ||
170
- username=$(git config user.signingkey) ||
171
- username=$(expr "z$tagger" : 'z\(.*>\)')
172
-
173
-trap 'rm -f "$GIT_DIR"/TAG_TMP* "$GIT_DIR"/TAG_FINALMSG "$GIT_DIR"/TAG_EDITMSG' 0
174
-
175
-if [ "$annotate" ]; then
176
- if [ -z "$message_given" ]; then
177
- ( echo "#"
178
- echo "# Write a tag message"
179
- echo "#" ) > "$GIT_DIR"/TAG_EDITMSG
180
- git_editor "$GIT_DIR"/TAG_EDITMSG || exit
181
- else
182
- printf '%s\n' "$message" >"$GIT_DIR"/TAG_EDITMSG
183
- fi
184
-
185
- grep -v '^#' <"$GIT_DIR"/TAG_EDITMSG |
186
- git stripspace >"$GIT_DIR"/TAG_FINALMSG
187
-
188
- [ -s "$GIT_DIR"/TAG_FINALMSG -o -n "$message_given" ] || {
189
- echo >&2 "No tag message?"
190
- exit 1
191
- }
192
-
193
- ( printf 'object %s\ntype %s\ntag %s\ntagger %s\n\n' \
194
- "$object" "$type" "$name" "$tagger";
195
- cat "$GIT_DIR"/TAG_FINALMSG ) >"$GIT_DIR"/TAG_TMP
196
- rm -f "$GIT_DIR"/TAG_TMP.asc "$GIT_DIR"/TAG_FINALMSG
197
- if [ "$signed" ]; then
198
- gpg -bsa -u "$username" "$GIT_DIR"/TAG_TMP &&
199
- cat "$GIT_DIR"/TAG_TMP.asc >>"$GIT_DIR"/TAG_TMP ||
200
- die "failed to sign the tag with GPG."
201
- fi
202
- object=$(git-mktag < "$GIT_DIR"/TAG_TMP)
203
-fi
204
-
205
-git update-ref "refs/tags/$name" "$object" "$prev"
contrib/examples/git-verify-tag.sh
deleted
-45
@@ -1,45 +0,0 @@
1
-#!/bin/sh
2
-
3
-USAGE='<tag>'
4
-SUBDIRECTORY_OK='Yes'
5
-. git-sh-setup
6
-
7
-verbose=
8
-while test $# != 0
9
-do
10
- case "$1" in
11
- -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
12
- verbose=t ;;
13
- *)
14
- break ;;
15
- esac
16
- shift
17
-done
18
-
19
-if [ "$#" != "1" ]
20
-then
21
- usage
22
-fi
23
-
24
-type="$(git cat-file -t "$1" 2>/dev/null)" ||
25
- die "$1: no such object."
26
-
27
-test "$type" = tag ||
28
- die "$1: cannot verify a non-tag object of type $type."
29
-
30
-case "$verbose" in
31
-t)
32
- git cat-file -p "$1" |
33
- sed -n -e '/^-----BEGIN PGP SIGNATURE-----/q' -e p
34
- ;;
35
-esac
36
-
37
-trap 'rm -f "$GIT_DIR/.tmp-vtag"' 0
38
-
39
-git cat-file tag "$1" >"$GIT_DIR/.tmp-vtag" || exit 1
40
-sed -n -e '
41
- /^-----BEGIN PGP SIGNATURE-----$/q
42
- p
43
-' <"$GIT_DIR/.tmp-vtag" |
44
-gpg --verify "$GIT_DIR/.tmp-vtag" - || exit 1
45
-rm -f "$GIT_DIR/.tmp-vtag"
contrib/examples/git-whatchanged.sh
deleted
-28
@@ -1,28 +0,0 @@
1
-#!/bin/sh
2
-
3
-USAGE='[-p] [--max-count=<n>] [<since>..<limit>] [--pretty=<format>] [-m] [git-diff-tree options] [git-rev-list options]'
4
-SUBDIRECTORY_OK='Yes'
5
-. git-sh-setup
6
-
7
-diff_tree_flags=$(git-rev-parse --sq --no-revs --flags "$@") || exit
8
-case "$0" in
9
-*whatchanged)
10
- count=
11
- test -z "$diff_tree_flags" &&
12
- diff_tree_flags=$(git config --get whatchanged.difftree)
13
- diff_tree_default_flags='-c -M --abbrev' ;;
14
-*show)
15
- count=-n1
16
- test -z "$diff_tree_flags" &&
17
- diff_tree_flags=$(git config --get show.difftree)
18
- diff_tree_default_flags='--cc --always' ;;
19
-esac
20
-test -z "$diff_tree_flags" &&
21
- diff_tree_flags="$diff_tree_default_flags"
22
-
23
-rev_list_args=$(git-rev-parse --sq --default HEAD --revs-only "$@") &&
24
-diff_tree_args=$(git-rev-parse --sq --no-revs --no-flags "$@") &&
25
-
26
-eval "git-rev-list $count $rev_list_args" |
27
-eval "git-diff-tree --stdin --pretty -r $diff_tree_flags $diff_tree_args" |
28
-LESS="$LESS -S" ${PAGER:-less}