286
if (!c)
287
return 0;
288
} else {
289
- init_notes(NULL, NULL, NULL, 0);
289
+ init_notes(NULL, NULL, NULL, NOTES_INIT_WRITABLE);
290
t = &default_notes_tree;
291
}
292
329
return ret;
330
}
331
332
-static struct notes_tree *init_notes_check(const char *subcommand)
332
+static struct notes_tree *init_notes_check(const char *subcommand,
333
+ int flags)
334
{
335
struct notes_tree *t;
335
- init_notes(NULL, NULL, NULL, 0);
336
+ const char *ref;
337
+ init_notes(NULL, NULL, NULL, flags);
338
t = &default_notes_tree;
339
338
- if (!starts_with(t->ref, "refs/notes/"))
340
+ ref = (flags & NOTES_INIT_WRITABLE) ? t->update_ref : t->ref;
341
+ if (!starts_with(ref, "refs/notes/"))
342
die("Refusing to %s notes in %s (outside of refs/notes/)",
340
- subcommand, t->ref);
343
+ subcommand, ref);
344
return t;
345
}
346
363
usage_with_options(git_notes_list_usage, options);
364
}
365
363
- t = init_notes_check("list");
366
+ t = init_notes_check("list", 0);
367
if (argc) {
368
if (get_sha1(argv[0], object))
369
die(_("Failed to resolve '%s' as a valid ref."), argv[0]);
423
if (get_sha1(object_ref, object))
424
die(_("Failed to resolve '%s' as a valid ref."), object_ref);
425
423
- t = init_notes_check("add");
426
+ t = init_notes_check("add", NOTES_INIT_WRITABLE);
427
note = get_note(t, object);
428
429
if (note) {
514
if (get_sha1(object_ref, object))
515
die(_("Failed to resolve '%s' as a valid ref."), object_ref);
516
514
- t = init_notes_check("copy");
517
+ t = init_notes_check("copy", NOTES_INIT_WRITABLE);
518
note = get_note(t, object);
519
520
if (note) {
592
if (get_sha1(object_ref, object))
593
die(_("Failed to resolve '%s' as a valid ref."), object_ref);
594
592
- t = init_notes_check(argv[0]);
595
+ t = init_notes_check(argv[0], NOTES_INIT_WRITABLE);
596
note = get_note(t, object);
597
598
prepare_note_data(object, &d, edit ? note : NULL);
655
if (get_sha1(object_ref, object))
656
die(_("Failed to resolve '%s' as a valid ref."), object_ref);
657
655
- t = init_notes_check("show");
658
+ t = init_notes_check("show", 0);
659
note = get_note(t, object);
660
661
if (!note)
812
expand_notes_ref(&remote_ref);
813
o.remote_ref = remote_ref.buf;
814
812
- t = init_notes_check("merge");
815
+ t = init_notes_check("merge", NOTES_INIT_WRITABLE);
816
817
if (strategy) {
818
if (parse_notes_merge_strategy(strategy, &o.strategy)) {
904
argc = parse_options(argc, argv, prefix, options,
905
git_notes_remove_usage, 0);
906
904
- t = init_notes_check("remove");
907
+ t = init_notes_check("remove", NOTES_INIT_WRITABLE);
908
909
if (!argc && !from_stdin) {
910
retval = remove_one_note(t, "HEAD", flag);
946
usage_with_options(git_notes_prune_usage, options);
947
}
948
946
- t = init_notes_check("prune");
949
+ t = init_notes_check("prune", NOTES_INIT_WRITABLE);
950
951
prune_notes(t, (verbose ? NOTES_PRUNE_VERBOSE : 0) |
952
(show_only ? NOTES_PRUNE_VERBOSE|NOTES_PRUNE_DRYRUN : 0) );