diff options
author | Jiang Xin <worldhello.net@gmail.com> | 2013-06-25 23:53:54 +0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-06-26 11:25:11 -0700 |
commit | 96a799b6d1d4a63dccfe8b5dcabd2d738fa6c26e (patch) | |
tree | b8f642112c29306b738d15ee074740f8836d2334 /builtin | |
parent | c1f1d24aa5c72821096e2a31aaf4175329ca0260 (diff) | |
download | git-96a799b6d1d4a63dccfe8b5dcabd2d738fa6c26e.tar.gz |
git-clean: add ask each interactive action
Add a new action for interactive git-clean: ask each. It's just like
the "rm -i" command, that the user must confirm one by one for each
file or directory to be cleaned.
Signed-off-by: Jiang Xin <worldhello.net@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/clean.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/builtin/clean.c b/builtin/clean.c index 643a5e0a01..bf03acfe88 100644 --- a/builtin/clean.c +++ b/builtin/clean.c @@ -717,6 +717,40 @@ static int select_by_numbers_cmd(void) return 0; } +static int ask_each_cmd(void) +{ + struct strbuf confirm = STRBUF_INIT; + struct strbuf buf = STRBUF_INIT; + struct string_list_item *item; + const char *qname; + int changed = 0, eof = 0; + + for_each_string_list_item(item, &del_list) { + /* Ctrl-D should stop removing files */ + if (!eof) { + qname = quote_path_relative(item->string, NULL, &buf); + printf(_("remove %s? "), qname); + if (strbuf_getline(&confirm, stdin, '\n') != EOF) { + strbuf_trim(&confirm); + } else { + putchar('\n'); + eof = 1; + } + } + if (!confirm.len || strncasecmp(confirm.buf, "yes", confirm.len)) { + *item->string = '\0'; + changed++; + } + } + + if (changed) + string_list_remove_empty_items(&del_list, 0); + + strbuf_release(&buf); + strbuf_release(&confirm); + return MENU_RETURN_NO_LOOP; +} + static int quit_cmd(void) { string_list_clear(&del_list, 0); @@ -731,6 +765,7 @@ static int help_cmd(void) "clean - start cleaning\n" "filter by pattern - exclude items from deletion\n" "select by numbers - select items to be deleted by numbers\n" + "ask each - confirm each deletion (like \"rm -i\")\n" "quit - stop cleaning\n" "help - this screen\n" "? - help for prompt selection" @@ -748,6 +783,7 @@ static void interactive_main_loop(void) {'c', "clean", 0, clean_cmd}, {'f', "filter by pattern", 0, filter_by_patterns_cmd}, {'s', "select by numbers", 0, select_by_numbers_cmd}, + {'a', "ask each", 0, ask_each_cmd}, {'q', "quit", 0, quit_cmd}, {'h', "help", 0, help_cmd}, }; |