'git notes' merge [-v | -q] [-s <strategy> ] <notes_ref>
'git notes' merge --commit [-v | -q]
'git notes' merge --abort [-v | -q]
-'git notes' remove [<object>...]
+'git notes' remove [--ignore-missing] [<object>...]
'git notes' prune [-n | -v]
'git notes' get-ref
'GIT_NOTES_REF' and the "core.notesRef" configuration. The ref
is taken to be in `refs/notes/` if it is not qualified.
+--ignore-missing::
+ Do not consider it an error to request removing notes from an
+ object that does not have notes attached to it.
+
-n::
--dry-run::
Do not remove anything; just report the object names whose notes
return result < 0; /* return non-zero on conflicts */
}
-static int remove_one_note(struct notes_tree *t, const char *name)
+#define MISSING_OK 1
+
+static int remove_one_note(struct notes_tree *t, const char *name, unsigned flag)
{
int status;
unsigned char sha1[20];
fprintf(stderr, _("Object %s has no note\n"), name);
else
fprintf(stderr, _("Removing note for object %s\n"), name);
- return status;
+ return (flag & MISSING_OK) ? 0 : status;
}
static int remove_cmd(int argc, const char **argv, const char *prefix)
{
+ unsigned flag = 0;
struct option options[] = {
+ OPT_BIT(0, "ignore-missing", &flag,
+ "attempt to remove non-existent note is not an error",
+ MISSING_OK),
OPT_END()
};
struct notes_tree *t;
t = init_notes_check("remove");
if (!argc) {
- retval = remove_one_note(t, "HEAD");
+ retval = remove_one_note(t, "HEAD", flag);
} else {
while (*argv) {
- retval |= remove_one_note(t, *argv);
+ retval |= remove_one_note(t, *argv, flag);
argv++;
}
}
test "$before" = "$after"
'
+test_expect_success 'removing with --ignore-missing' '
+ before=$(git rev-parse --verify refs/notes/commits) &&
+ test_when_finished "git update-ref refs/notes/commits $before" &&
+
+ # We have only two -- add another and make sure it stays
+ git notes add -m "extra" &&
+ git notes list HEAD >after-removal-expect &&
+ git notes remove --ignore-missing HEAD^^ HEAD^^^ HEAD^ &&
+ git notes list | sed -e "s/ .*//" >actual &&
+ test_cmp after-removal-expect actual
+'
+
+test_expect_success 'removing with --ignore-missing but bogus ref' '
+ before=$(git rev-parse --verify refs/notes/commits) &&
+ test_when_finished "git update-ref refs/notes/commits $before" &&
+ test_must_fail git notes remove --ignore-missing HEAD^^ HEAD^^^ NO-SUCH-COMMIT &&
+ after=$(git rev-parse --verify refs/notes/commits) &&
+ test "$before" = "$after"
+'
+
test_expect_success 'list notes with "git notes list"' '
git notes list > output &&
test_cmp expect output