Currently, we display an error message if 'git log' is run on a new repo with no commits. This is a corner case and shouldn't return an error. Also, updated other functions to use new 'default_to_head_if_exists()' function introduced. Signed-off-by: Leila Muhtasib <muhtasib@xxxxxxxxx> --- builtin/log.c | 24 +++++++++++++++++++----- 1 files changed, 19 insertions(+), 5 deletions(-) diff --git a/builtin/log.c b/builtin/log.c index 4f1b42a..1685946 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -355,6 +355,15 @@ static int git_log_config(const char *var, const char *value, void *cb) return git_diff_ui_config(var, value, cb); } +static const char *default_to_head_if_exists(void) +{ + unsigned char sha1[20]; + if (resolve_ref_unsafe("HEAD", sha1, 1, NULL)) + return "HEAD"; + else + return NULL; +} + int cmd_whatchanged(int argc, const char **argv, const char *prefix) { struct rev_info rev; @@ -366,7 +375,7 @@ int cmd_whatchanged(int argc, const char **argv, const char *prefix) rev.diff = 1; rev.simplify_history = 0; memset(&opt, 0, sizeof(opt)); - opt.def = "HEAD"; + opt.def = default_to_head_if_exists(); cmd_log_init(argc, argv, prefix, &rev, &opt); if (!rev.diffopt.output_format) rev.diffopt.output_format = DIFF_FORMAT_RAW; @@ -459,7 +468,7 @@ int cmd_show(int argc, const char **argv, const char *prefix) rev.diffopt.stat_width = -1; /* Scale to real terminal size */ memset(&opt, 0, sizeof(opt)); - opt.def = "HEAD"; + opt.def = default_to_head_if_exists(); opt.tweak = show_rev_tweak_rev; cmd_log_init(argc, argv, prefix, &rev, &opt); @@ -532,7 +541,7 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix) init_reflog_walk(&rev.reflog_info); rev.verbose_header = 1; memset(&opt, 0, sizeof(opt)); - opt.def = "HEAD"; + opt.def = default_to_head_if_exists(); cmd_log_init_defaults(&rev); rev.abbrev_commit = 1; rev.commit_format = CMIT_FMT_ONELINE; @@ -553,8 +562,13 @@ int cmd_log(int argc, const char **argv, const char *prefix) init_revisions(&rev, prefix); rev.always_show_header = 1; memset(&opt, 0, sizeof(opt)); - opt.def = "HEAD"; + opt.def = default_to_head_if_exists(); + cmd_log_init(argc, argv, prefix, &rev, &opt); + + if (!opt.def && !rev.cmdline.nr) + return 0; + return cmd_log_walk(&rev); } @@ -1128,7 +1142,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) DIFF_OPT_SET(&rev.diffopt, RECURSIVE); rev.subject_prefix = fmt_patch_subject_prefix; memset(&s_r_opt, 0, sizeof(s_r_opt)); - s_r_opt.def = "HEAD"; + s_r_opt.def = default_to_head_if_exists(); if (default_attach) { rev.mime_boundary = default_attach; -- 1.7.7.5 (Apple Git-26) -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html