refs: make error messages more consistent

* Always start error messages with a lower-case letter. * Always enclose reference names in single quotes. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>

Michael Haggerty committed Apr 27, 2016 at 15:21 UTC 0568c8e9dce2aa0dd18f41f23e3465f3639e371e
3 files changed +22 -22
refs.c
+4 -4
@@ -504,7 +504,7 @@ static int write_pseudoref(const char *pseudoref, const unsigned char *sha1,
504 filename = git_path("%s", pseudoref);
505 fd = hold_lock_file_for_update(&lock, filename, LOCK_DIE_ON_ERROR);
506 if (fd < 0) {
507 - strbuf_addf(err, "Could not open '%s' for writing: %s",
507 + strbuf_addf(err, "could not open '%s' for writing: %s",
508 filename, strerror(errno));
509 return -1;
510 }
@@ -515,14 +515,14 @@ static int write_pseudoref(const char *pseudoref, const unsigned char *sha1,
515 if (read_ref(pseudoref, actual_old_sha1))
516 die("could not read ref '%s'", pseudoref);
517 if (hashcmp(actual_old_sha1, old_sha1)) {
518 - strbuf_addf(err, "Unexpected sha1 when writing %s", pseudoref);
518 + strbuf_addf(err, "unexpected sha1 when writing '%s'", pseudoref);
519 rollback_lock_file(&lock);
520 goto done;
521 }
522 }
523
524 if (write_in_full(fd, buf.buf, buf.len) != buf.len) {
525 - strbuf_addf(err, "Could not write to '%s'", filename);
525 + strbuf_addf(err, "could not write to '%s'", filename);
526 rollback_lock_file(&lock);
527 goto done;
528 }
@@ -792,7 +792,7 @@ int ref_transaction_update(struct ref_transaction *transaction,
792
793 if (new_sha1 && !is_null_sha1(new_sha1) &&
794 check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
795 - strbuf_addf(err, "refusing to update ref with bad name %s",
795 + strbuf_addf(err, "refusing to update ref with bad name '%s'",
796 refname);
797 return -1;
798 }
refs/files-backend.c
+16 -16
@@ -1701,7 +1701,7 @@ static int verify_lock(struct ref_lock *lock,
1701 lock->old_oid.hash, NULL)) {
1702 if (old_sha1) {
1703 int save_errno = errno;
1704 - strbuf_addf(err, "can't verify ref %s", lock->ref_name);
1704 + strbuf_addf(err, "can't verify ref '%s'", lock->ref_name);
1705 errno = save_errno;
1706 return -1;
1707 } else {
@@ -1710,7 +1710,7 @@ static int verify_lock(struct ref_lock *lock,
1710 }
1711 }
1712 if (old_sha1 && hashcmp(lock->old_oid.hash, old_sha1)) {
1713 - strbuf_addf(err, "ref %s is at %s but expected %s",
1713 + strbuf_addf(err, "ref '%s' is at %s but expected %s",
1714 lock->ref_name,
1715 sha1_to_hex(lock->old_oid.hash),
1716 sha1_to_hex(old_sha1));
@@ -1790,7 +1790,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
1790 if (last_errno != ENOTDIR ||
1791 !verify_refname_available_dir(orig_refname, extras, skip,
1792 get_loose_refs(&ref_cache), err))
1793 - strbuf_addf(err, "unable to resolve reference %s: %s",
1793 + strbuf_addf(err, "unable to resolve reference '%s': %s",
1794 orig_refname, strerror(last_errno));
1795
1796 goto error_return;
@@ -1828,7 +1828,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
1828 /* fall through */
1829 default:
1830 last_errno = errno;
1831 - strbuf_addf(err, "unable to create directory for %s",
1831 + strbuf_addf(err, "unable to create directory for '%s'",
1832 ref_file.buf);
1833 goto error_return;
1834 }
@@ -2473,7 +2473,7 @@ static int log_ref_setup(const char *refname, struct strbuf *logfile, struct str
2473 strbuf_git_path(logfile, "logs/%s", refname);
2474 if (force_create || should_autocreate_reflog(refname)) {
2475 if (safe_create_leading_directories(logfile->buf) < 0) {
2476 - strbuf_addf(err, "unable to create directory for %s: "
2476 + strbuf_addf(err, "unable to create directory for '%s': "
2477 "%s", logfile->buf, strerror(errno));
2478 return -1;
2479 }
@@ -2487,7 +2487,7 @@ static int log_ref_setup(const char *refname, struct strbuf *logfile, struct str
2487
2488 if (errno == EISDIR) {
2489 if (remove_empty_directories(logfile)) {
2490 - strbuf_addf(err, "There are still logs under "
2490 + strbuf_addf(err, "there are still logs under "
2491 "'%s'", logfile->buf);
2492 return -1;
2493 }
@@ -2495,7 +2495,7 @@ static int log_ref_setup(const char *refname, struct strbuf *logfile, struct str
2495 }
2496
2497 if (logfd < 0) {
2498 - strbuf_addf(err, "unable to append to %s: %s",
2498 + strbuf_addf(err, "unable to append to '%s': %s",
2499 logfile->buf, strerror(errno));
2500 return -1;
2501 }
@@ -2564,13 +2564,13 @@ static int log_ref_write_1(const char *refname, const unsigned char *old_sha1,
2564 result = log_ref_write_fd(logfd, old_sha1, new_sha1,
2565 git_committer_info(0), msg);
2566 if (result) {
2567 - strbuf_addf(err, "unable to append to %s: %s", logfile->buf,
2567 + strbuf_addf(err, "unable to append to '%s': %s", logfile->buf,
2568 strerror(errno));
2569 close(logfd);
2570 return -1;
2571 }
2572 if (close(logfd)) {
2573 - strbuf_addf(err, "unable to append to %s: %s", logfile->buf,
2573 + strbuf_addf(err, "unable to append to '%s': %s", logfile->buf,
2574 strerror(errno));
2575 return -1;
2576 }
@@ -2611,14 +2611,14 @@ static int write_ref_to_lockfile(struct ref_lock *lock,
2611 o = parse_object(sha1);
2612 if (!o) {
2613 strbuf_addf(err,
2614 - "Trying to write ref %s with nonexistent object %s",
2614 + "trying to write ref '%s' with nonexistent object %s",
2615 lock->ref_name, sha1_to_hex(sha1));
2616 unlock_ref(lock);
2617 return -1;
2618 }
2619 if (o->type != OBJ_COMMIT && is_branch(lock->ref_name)) {
2620 strbuf_addf(err,
2621 - "Trying to write non-commit object %s to branch %s",
2621 + "trying to write non-commit object %s to branch '%s'",
2622 sha1_to_hex(sha1), lock->ref_name);
2623 unlock_ref(lock);
2624 return -1;
@@ -2628,7 +2628,7 @@ static int write_ref_to_lockfile(struct ref_lock *lock,
2628 write_in_full(fd, &term, 1) != 1 ||
2629 close_ref(lock) < 0) {
2630 strbuf_addf(err,
2631 - "Couldn't write %s", get_lock_file_path(lock->lk));
2631 + "couldn't write '%s'", get_lock_file_path(lock->lk));
2632 unlock_ref(lock);
2633 return -1;
2634 }
@@ -2649,7 +2649,7 @@ static int commit_ref_update(struct ref_lock *lock,
2649 (strcmp(lock->ref_name, lock->orig_ref_name) &&
2650 log_ref_write(lock->orig_ref_name, lock->old_oid.hash, sha1, logmsg, flags, err) < 0)) {
2651 char *old_msg = strbuf_detach(err, NULL);
2652 - strbuf_addf(err, "Cannot update the ref '%s': %s",
2652 + strbuf_addf(err, "cannot update the ref '%s': %s",
2653 lock->ref_name, old_msg);
2654 free(old_msg);
2655 unlock_ref(lock);
@@ -2684,7 +2684,7 @@ static int commit_ref_update(struct ref_lock *lock,
2684 }
2685 }
2686 if (commit_ref(lock)) {
2687 - strbuf_addf(err, "Couldn't set %s", lock->ref_name);
2687 + strbuf_addf(err, "couldn't set '%s'", lock->ref_name);
2688 unlock_ref(lock);
2689 return -1;
2690 }
@@ -3033,7 +3033,7 @@ static int ref_update_reject_duplicates(struct string_list *refnames,
3033 for (i = 1; i < n; i++)
3034 if (!strcmp(refnames->items[i - 1].string, refnames->items[i].string)) {
3035 strbuf_addf(err,
3036 - "Multiple updates for ref '%s' not allowed.",
3036 + "multiple updates for ref '%s' not allowed.",
3037 refnames->items[i].string);
3038 return 1;
3039 }
@@ -3137,7 +3137,7 @@ int ref_transaction_commit(struct ref_transaction *transaction,
3137 * Close it to free up the file descriptor:
3138 */
3139 if (close_ref(update->lock)) {
3140 - strbuf_addf(err, "Couldn't close %s.lock",
3140 + strbuf_addf(err, "couldn't close '%s.lock'",
3141 update->refname);
3142 goto cleanup;
3143 }
t/t1400-update-ref.sh
+2 -2
@@ -479,7 +479,7 @@ test_expect_success 'stdin fails with duplicate refs' '
479 create $a $m
480 EOF
481 test_must_fail git update-ref --stdin <stdin 2>err &&
482 - grep "fatal: Multiple updates for ref '"'"'$a'"'"' not allowed." err
482 + grep "fatal: multiple updates for ref '"'"'$a'"'"' not allowed." err
483 '
484
485 test_expect_success 'stdin create ref works' '
@@ -880,7 +880,7 @@ test_expect_success 'stdin -z fails option with unknown name' '
880 test_expect_success 'stdin -z fails with duplicate refs' '
881 printf $F "create $a" "$m" "create $b" "$m" "create $a" "$m" >stdin &&
882 test_must_fail git update-ref -z --stdin <stdin 2>err &&
883 - grep "fatal: Multiple updates for ref '"'"'$a'"'"' not allowed." err
883 + grep "fatal: multiple updates for ref '"'"'$a'"'"' not allowed." err
884 '
885
886 test_expect_success 'stdin -z create ref works' '