X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=builtin-commit.c;h=e3ad38b3bd78bc2d19c5e5d1ebfbe0388b22582e;hb=1c7b76be7d620bbaf2e6b8417f04012326bbb9df;hp=d75224381b7ad88d6bbb67db3a85bbb881cea941;hpb=182fb4df9120257c2e6b041dd58eef3de5b530d2;p=git.git diff --git a/builtin-commit.c b/builtin-commit.c index d75224381..e3ad38b3b 100644 --- a/builtin-commit.c +++ b/builtin-commit.c @@ -49,7 +49,8 @@ static char *logfile, *force_author, *template_file; static char *edit_message, *use_message; static char *author_name, *author_email, *author_date; static int all, edit_flag, also, interactive, only, amend, signoff; -static int quiet, verbose, untracked_files, no_verify, allow_empty; +static int quiet, verbose, no_verify, allow_empty; +static char *untracked_files_arg; /* * The default commit message cleanup mode will remove the lines * beginning with # (shell comments) and leading and trailing @@ -102,7 +103,7 @@ static struct option builtin_commit_options[] = { OPT_BOOLEAN('o', "only", &only, "commit only specified files"), OPT_BOOLEAN('n', "no-verify", &no_verify, "bypass pre-commit hook"), OPT_BOOLEAN(0, "amend", &amend, "amend previous commit"), - OPT_BOOLEAN('u', "untracked-files", &untracked_files, "show all untracked files"), + { OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, "mode", "show untracked files, optional modes: all, normal, no. (Default: all)", PARSE_OPT_OPTARG, NULL, (intptr_t)"all" }, OPT_BOOLEAN(0, "allow-empty", &allow_empty, "ok to record an empty change"), OPT_STRING(0, "cleanup", &cleanup_arg, "default", "how to strip spaces and #comments from message"), @@ -223,6 +224,8 @@ static char *prepare_index(int argc, const char **argv, const char *prefix) if (interactive) { interactive_add(argc, argv, prefix); + if (read_cache() < 0) + die("index file corrupt"); commit_style = COMMIT_AS_IS; return get_index_file(); } @@ -345,7 +348,7 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int s.reference = "HEAD^1"; } s.verbose = verbose; - s.untracked = untracked_files; + s.untracked = (show_untracked_files == SHOW_ALL_UNTRACKED_FILES); s.index_file = index_file; s.fp = fp; s.nowarn = nowarn; @@ -500,7 +503,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix) fp = fopen(git_path(commit_editmsg), "w"); if (fp == NULL) - die("could not open %s", git_path(commit_editmsg)); + die("could not open %s: %s", + git_path(commit_editmsg), strerror(errno)); if (cleanup_mode != CLEANUP_NONE) stripspace(&sb, 0); @@ -793,6 +797,17 @@ static int parse_and_validate_options(int argc, const char *argv[], else die("Invalid cleanup mode %s", cleanup_arg); + if (!untracked_files_arg) + ; /* default already initialized */ + else if (!strcmp(untracked_files_arg, "no")) + show_untracked_files = SHOW_NO_UNTRACKED_FILES; + else if (!strcmp(untracked_files_arg, "normal")) + show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES; + else if (!strcmp(untracked_files_arg, "all")) + show_untracked_files = SHOW_ALL_UNTRACKED_FILES; + else + die("Invalid untracked files mode '%s'", untracked_files_arg); + if (all && argc > 0) die("Paths with -a does not make sense."); else if (interactive && argc > 0) @@ -806,7 +821,7 @@ int cmd_status(int argc, const char **argv, const char *prefix) const char *index_file; int commitable; - git_config(git_status_config); + git_config(git_status_config, NULL); if (wt_status_use_color == -1) wt_status_use_color = git_use_color_default; @@ -860,7 +875,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1) } } -int git_commit_config(const char *k, const char *v) +int git_commit_config(const char *k, const char *v, void *cb) { if (!strcmp(k, "commit.template")) { if (!v) @@ -869,7 +884,7 @@ int git_commit_config(const char *k, const char *v) return 0; } - return git_status_config(k, v); + return git_status_config(k, v, cb); } static const char commit_utf8_warn[] = @@ -881,10 +896,19 @@ static void add_parent(struct strbuf *sb, const unsigned char *sha1) { struct object *obj = parse_object(sha1); const char *parent = sha1_to_hex(sha1); + const char *cp; + if (!obj) die("Unable to find commit parent %s", parent); if (obj->type != OBJ_COMMIT) die("Parent %s isn't a proper commit", parent); + + for (cp = sb->buf; cp && (cp = strstr(cp, "\nparent ")); cp += 8) { + if (!memcmp(cp + 8, parent, 40) && cp[48] == '\n') { + error("duplicate parent %s ignored", parent); + return; + } + } strbuf_addf(sb, "parent %s\n", parent); } @@ -897,7 +921,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix) unsigned char commit_sha1[20]; struct ref_lock *ref_lock; - git_config(git_commit_config); + git_config(git_commit_config, NULL); argc = parse_and_validate_options(argc, argv, builtin_commit_usage);