Fossil SCM
Add 'no-prompt' option to the clean command (i.e. answers 'No' to every prompt). Add initial tests of enhanced clean command.
Commit
bc1504eec7d45c12828993e683e9528018164a47
Parent
04b86407b019bf9…
2 files changed
+27
-18
+35
+27
-18
| --- src/checkin.c | ||
| +++ src/checkin.c | ||
| @@ -686,19 +686,21 @@ | ||
| 686 | 686 | ** comma separated list of glob patterns. |
| 687 | 687 | ** --keep <CSG> Keep files matching this comma separated |
| 688 | 688 | ** list of glob patterns. |
| 689 | 689 | ** -n|--dry-run Delete nothing, but display what would have been |
| 690 | 690 | ** deleted. |
| 691 | +** --no-prompt This option disables prompting the user for input | |
| 692 | +** and assumes an answer of 'No' for every question. | |
| 691 | 693 | ** --temp Remove only Fossil-generated temporary files. |
| 692 | 694 | ** -v|--verbose Show all files as they are removed. |
| 693 | 695 | ** |
| 694 | 696 | ** See also: addremove, extras, status |
| 695 | 697 | */ |
| 696 | 698 | void clean_cmd(void){ |
| 697 | 699 | int allFileFlag, allDirFlag, dryRunFlag, verboseFlag; |
| 698 | 700 | int emptyDirsFlag, dirsOnlyFlag; |
| 699 | - int disableUndo; | |
| 701 | + int disableUndo, noPrompt; | |
| 700 | 702 | unsigned scanFlags = 0; |
| 701 | 703 | int verilyFlag = 0; |
| 702 | 704 | const char *zIgnoreFlag, *zKeepFlag, *zCleanFlag; |
| 703 | 705 | Glob *pIgnore, *pKeep, *pClean; |
| 704 | 706 | int nRoot; |
| @@ -714,10 +716,11 @@ | ||
| 714 | 716 | } |
| 715 | 717 | if( !dryRunFlag ){ |
| 716 | 718 | dryRunFlag = find_option("whatif",0,0)!=0; |
| 717 | 719 | } |
| 718 | 720 | disableUndo = find_option("disable-undo",0,0)!=0; |
| 721 | + noPrompt = find_option("no-prompt",0,0)!=0; | |
| 719 | 722 | allFileFlag = allDirFlag = find_option("force","f",0)!=0; |
| 720 | 723 | dirsOnlyFlag = find_option("dirsonly",0,0)!=0; |
| 721 | 724 | emptyDirsFlag = find_option("emptydirs","d",0)!=0 || dirsOnlyFlag; |
| 722 | 725 | if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL; |
| 723 | 726 | if( find_option("temp",0,0)!=0 ) scanFlags |= SCAN_TEMP; |
| @@ -777,26 +780,29 @@ | ||
| 777 | 780 | int undoRc = UNDO_NONE; |
| 778 | 781 | if( !disableUndo ){ |
| 779 | 782 | undoRc = undo_maybe_save(zName+nRoot, UNDO_SIZE_LIMIT); |
| 780 | 783 | } |
| 781 | 784 | if( undoRc!=UNDO_SAVED_OK ){ |
| 782 | - Blob ans; | |
| 783 | 785 | char cReply; |
| 784 | - char *prompt = mprintf("\nWARNING: Deletion of this file will " | |
| 785 | - "not be undoable via the 'undo'\n" | |
| 786 | - " command because %s.\n\n" | |
| 787 | - "Remove unmanaged file \"%s\" (a=all/y/N)? ", | |
| 788 | - undo_save_message(undoRc), zName+nRoot); | |
| 789 | - prompt_user(prompt, &ans); | |
| 790 | - cReply = blob_str(&ans)[0]; | |
| 786 | + if( !noPrompt ){ | |
| 787 | + Blob ans; | |
| 788 | + char *prompt = mprintf("\nWARNING: Deletion of this file will " | |
| 789 | + "not be undoable via the 'undo'\n" | |
| 790 | + " command because %s.\n\n" | |
| 791 | + "Remove unmanaged file \"%s\" (a=all/y/N)? ", | |
| 792 | + undo_save_message(undoRc), zName+nRoot); | |
| 793 | + prompt_user(prompt, &ans); | |
| 794 | + cReply = blob_str(&ans)[0]; | |
| 795 | + blob_reset(&ans); | |
| 796 | + }else{ | |
| 797 | + cReply = 'N'; | |
| 798 | + } | |
| 791 | 799 | if( cReply=='a' || cReply=='A' ){ |
| 792 | 800 | allFileFlag = 1; |
| 793 | 801 | }else if( cReply!='y' && cReply!='Y' ){ |
| 794 | - blob_reset(&ans); | |
| 795 | 802 | continue; |
| 796 | 803 | } |
| 797 | - blob_reset(&ans); | |
| 798 | 804 | } |
| 799 | 805 | } |
| 800 | 806 | if( dryRunFlag || file_delete(zName)==0 ){ |
| 801 | 807 | if( verboseFlag || dryRunFlag ){ |
| 802 | 808 | fossil_print("Removed unmanaged file: %s\n", zName+nRoot); |
| @@ -830,23 +836,26 @@ | ||
| 830 | 836 | " or \"keep-glob\")\n", zName+nRoot); |
| 831 | 837 | } |
| 832 | 838 | continue; |
| 833 | 839 | } |
| 834 | 840 | if( !allDirFlag && !dryRunFlag && !glob_match(pClean, zName+nRoot) ){ |
| 835 | - Blob ans; | |
| 836 | 841 | char cReply; |
| 837 | - char *prompt = mprintf("Remove empty directory \"%s\" (a=all/y/N)? ", | |
| 838 | - zName+nRoot); | |
| 839 | - prompt_user(prompt, &ans); | |
| 840 | - cReply = blob_str(&ans)[0]; | |
| 842 | + if( !noPrompt ){ | |
| 843 | + Blob ans; | |
| 844 | + char *prompt = mprintf("Remove empty directory \"%s\" (a=all/y/N)? ", | |
| 845 | + zName+nRoot); | |
| 846 | + prompt_user(prompt, &ans); | |
| 847 | + cReply = blob_str(&ans)[0]; | |
| 848 | + blob_reset(&ans); | |
| 849 | + }else{ | |
| 850 | + cReply = 'N'; | |
| 851 | + } | |
| 841 | 852 | if( cReply=='a' || cReply=='A' ){ |
| 842 | 853 | allDirFlag = 1; |
| 843 | 854 | }else if( cReply!='y' && cReply!='Y' ){ |
| 844 | - blob_reset(&ans); | |
| 845 | 855 | continue; |
| 846 | 856 | } |
| 847 | - blob_reset(&ans); | |
| 848 | 857 | } |
| 849 | 858 | if( dryRunFlag || file_rmdir(zName)==0 ){ |
| 850 | 859 | if( verboseFlag || dryRunFlag ){ |
| 851 | 860 | fossil_print("Removed unmanaged directory: %s\n", zName+nRoot); |
| 852 | 861 | } |
| 853 | 862 | |
| 854 | 863 | ADDED test/clean.test |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -686,19 +686,21 @@ | |
| 686 | ** comma separated list of glob patterns. |
| 687 | ** --keep <CSG> Keep files matching this comma separated |
| 688 | ** list of glob patterns. |
| 689 | ** -n|--dry-run Delete nothing, but display what would have been |
| 690 | ** deleted. |
| 691 | ** --temp Remove only Fossil-generated temporary files. |
| 692 | ** -v|--verbose Show all files as they are removed. |
| 693 | ** |
| 694 | ** See also: addremove, extras, status |
| 695 | */ |
| 696 | void clean_cmd(void){ |
| 697 | int allFileFlag, allDirFlag, dryRunFlag, verboseFlag; |
| 698 | int emptyDirsFlag, dirsOnlyFlag; |
| 699 | int disableUndo; |
| 700 | unsigned scanFlags = 0; |
| 701 | int verilyFlag = 0; |
| 702 | const char *zIgnoreFlag, *zKeepFlag, *zCleanFlag; |
| 703 | Glob *pIgnore, *pKeep, *pClean; |
| 704 | int nRoot; |
| @@ -714,10 +716,11 @@ | |
| 714 | } |
| 715 | if( !dryRunFlag ){ |
| 716 | dryRunFlag = find_option("whatif",0,0)!=0; |
| 717 | } |
| 718 | disableUndo = find_option("disable-undo",0,0)!=0; |
| 719 | allFileFlag = allDirFlag = find_option("force","f",0)!=0; |
| 720 | dirsOnlyFlag = find_option("dirsonly",0,0)!=0; |
| 721 | emptyDirsFlag = find_option("emptydirs","d",0)!=0 || dirsOnlyFlag; |
| 722 | if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL; |
| 723 | if( find_option("temp",0,0)!=0 ) scanFlags |= SCAN_TEMP; |
| @@ -777,26 +780,29 @@ | |
| 777 | int undoRc = UNDO_NONE; |
| 778 | if( !disableUndo ){ |
| 779 | undoRc = undo_maybe_save(zName+nRoot, UNDO_SIZE_LIMIT); |
| 780 | } |
| 781 | if( undoRc!=UNDO_SAVED_OK ){ |
| 782 | Blob ans; |
| 783 | char cReply; |
| 784 | char *prompt = mprintf("\nWARNING: Deletion of this file will " |
| 785 | "not be undoable via the 'undo'\n" |
| 786 | " command because %s.\n\n" |
| 787 | "Remove unmanaged file \"%s\" (a=all/y/N)? ", |
| 788 | undo_save_message(undoRc), zName+nRoot); |
| 789 | prompt_user(prompt, &ans); |
| 790 | cReply = blob_str(&ans)[0]; |
| 791 | if( cReply=='a' || cReply=='A' ){ |
| 792 | allFileFlag = 1; |
| 793 | }else if( cReply!='y' && cReply!='Y' ){ |
| 794 | blob_reset(&ans); |
| 795 | continue; |
| 796 | } |
| 797 | blob_reset(&ans); |
| 798 | } |
| 799 | } |
| 800 | if( dryRunFlag || file_delete(zName)==0 ){ |
| 801 | if( verboseFlag || dryRunFlag ){ |
| 802 | fossil_print("Removed unmanaged file: %s\n", zName+nRoot); |
| @@ -830,23 +836,26 @@ | |
| 830 | " or \"keep-glob\")\n", zName+nRoot); |
| 831 | } |
| 832 | continue; |
| 833 | } |
| 834 | if( !allDirFlag && !dryRunFlag && !glob_match(pClean, zName+nRoot) ){ |
| 835 | Blob ans; |
| 836 | char cReply; |
| 837 | char *prompt = mprintf("Remove empty directory \"%s\" (a=all/y/N)? ", |
| 838 | zName+nRoot); |
| 839 | prompt_user(prompt, &ans); |
| 840 | cReply = blob_str(&ans)[0]; |
| 841 | if( cReply=='a' || cReply=='A' ){ |
| 842 | allDirFlag = 1; |
| 843 | }else if( cReply!='y' && cReply!='Y' ){ |
| 844 | blob_reset(&ans); |
| 845 | continue; |
| 846 | } |
| 847 | blob_reset(&ans); |
| 848 | } |
| 849 | if( dryRunFlag || file_rmdir(zName)==0 ){ |
| 850 | if( verboseFlag || dryRunFlag ){ |
| 851 | fossil_print("Removed unmanaged directory: %s\n", zName+nRoot); |
| 852 | } |
| 853 | |
| 854 | DDED test/clean.test |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -686,19 +686,21 @@ | |
| 686 | ** comma separated list of glob patterns. |
| 687 | ** --keep <CSG> Keep files matching this comma separated |
| 688 | ** list of glob patterns. |
| 689 | ** -n|--dry-run Delete nothing, but display what would have been |
| 690 | ** deleted. |
| 691 | ** --no-prompt This option disables prompting the user for input |
| 692 | ** and assumes an answer of 'No' for every question. |
| 693 | ** --temp Remove only Fossil-generated temporary files. |
| 694 | ** -v|--verbose Show all files as they are removed. |
| 695 | ** |
| 696 | ** See also: addremove, extras, status |
| 697 | */ |
| 698 | void clean_cmd(void){ |
| 699 | int allFileFlag, allDirFlag, dryRunFlag, verboseFlag; |
| 700 | int emptyDirsFlag, dirsOnlyFlag; |
| 701 | int disableUndo, noPrompt; |
| 702 | unsigned scanFlags = 0; |
| 703 | int verilyFlag = 0; |
| 704 | const char *zIgnoreFlag, *zKeepFlag, *zCleanFlag; |
| 705 | Glob *pIgnore, *pKeep, *pClean; |
| 706 | int nRoot; |
| @@ -714,10 +716,11 @@ | |
| 716 | } |
| 717 | if( !dryRunFlag ){ |
| 718 | dryRunFlag = find_option("whatif",0,0)!=0; |
| 719 | } |
| 720 | disableUndo = find_option("disable-undo",0,0)!=0; |
| 721 | noPrompt = find_option("no-prompt",0,0)!=0; |
| 722 | allFileFlag = allDirFlag = find_option("force","f",0)!=0; |
| 723 | dirsOnlyFlag = find_option("dirsonly",0,0)!=0; |
| 724 | emptyDirsFlag = find_option("emptydirs","d",0)!=0 || dirsOnlyFlag; |
| 725 | if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL; |
| 726 | if( find_option("temp",0,0)!=0 ) scanFlags |= SCAN_TEMP; |
| @@ -777,26 +780,29 @@ | |
| 780 | int undoRc = UNDO_NONE; |
| 781 | if( !disableUndo ){ |
| 782 | undoRc = undo_maybe_save(zName+nRoot, UNDO_SIZE_LIMIT); |
| 783 | } |
| 784 | if( undoRc!=UNDO_SAVED_OK ){ |
| 785 | char cReply; |
| 786 | if( !noPrompt ){ |
| 787 | Blob ans; |
| 788 | char *prompt = mprintf("\nWARNING: Deletion of this file will " |
| 789 | "not be undoable via the 'undo'\n" |
| 790 | " command because %s.\n\n" |
| 791 | "Remove unmanaged file \"%s\" (a=all/y/N)? ", |
| 792 | undo_save_message(undoRc), zName+nRoot); |
| 793 | prompt_user(prompt, &ans); |
| 794 | cReply = blob_str(&ans)[0]; |
| 795 | blob_reset(&ans); |
| 796 | }else{ |
| 797 | cReply = 'N'; |
| 798 | } |
| 799 | if( cReply=='a' || cReply=='A' ){ |
| 800 | allFileFlag = 1; |
| 801 | }else if( cReply!='y' && cReply!='Y' ){ |
| 802 | continue; |
| 803 | } |
| 804 | } |
| 805 | } |
| 806 | if( dryRunFlag || file_delete(zName)==0 ){ |
| 807 | if( verboseFlag || dryRunFlag ){ |
| 808 | fossil_print("Removed unmanaged file: %s\n", zName+nRoot); |
| @@ -830,23 +836,26 @@ | |
| 836 | " or \"keep-glob\")\n", zName+nRoot); |
| 837 | } |
| 838 | continue; |
| 839 | } |
| 840 | if( !allDirFlag && !dryRunFlag && !glob_match(pClean, zName+nRoot) ){ |
| 841 | char cReply; |
| 842 | if( !noPrompt ){ |
| 843 | Blob ans; |
| 844 | char *prompt = mprintf("Remove empty directory \"%s\" (a=all/y/N)? ", |
| 845 | zName+nRoot); |
| 846 | prompt_user(prompt, &ans); |
| 847 | cReply = blob_str(&ans)[0]; |
| 848 | blob_reset(&ans); |
| 849 | }else{ |
| 850 | cReply = 'N'; |
| 851 | } |
| 852 | if( cReply=='a' || cReply=='A' ){ |
| 853 | allDirFlag = 1; |
| 854 | }else if( cReply!='y' && cReply!='Y' ){ |
| 855 | continue; |
| 856 | } |
| 857 | } |
| 858 | if( dryRunFlag || file_rmdir(zName)==0 ){ |
| 859 | if( verboseFlag || dryRunFlag ){ |
| 860 | fossil_print("Removed unmanaged directory: %s\n", zName+nRoot); |
| 861 | } |
| 862 | |
| 863 | DDED test/clean.test |
+35
| --- a/test/clean.test | ||
| +++ b/test/clean.test | ||
| @@ -0,0 +1,35 @@ | ||
| 1 | +# | |
| 2 | +# Copyright (c) 2015 D. Richard Hipp | |
| 3 | +# | |
| 4 | +# This program is free software; you can redistribute it and/or | |
| 5 | +# modify it under the terms of the Simplified BSD License (also | |
| 6 | +# known as the "2-Clause License" or "FreeBSD License".) | |
| 7 | +# | |
| 8 | +# This program is distributed in the hope that it will be useful, | |
| 9 | +# but without any warranty; without even the implied warranty of | |
| 10 | +# merchantability or fitness for a particular purpose. | |
| 11 | +# | |
| 12 | +# Author contact information: | |
| 13 | +# [email protected] | |
| 14 | +# http://www.hwaci.com/drh/ | |
| 15 | +# | |
| 16 | +############################################################################ | |
| 17 | +# | |
| 18 | +# Tests of the "clean" command, including the ability to undo it. | |
| 19 | +# | |
| 20 | + | |
| 21 | +repo_init########### | |
| 22 | + | |
| 23 | +fossil extra | |
| 24 | +test clean-0 {[normalize_result] eq {}} | |
| 25 | + | |
| 26 | +#############0bute it and/or | |
| 27 | +# modify it under the terms of the Simplified BSD License (also | |
| 28 | +# kn# | |
| 29 | +# Copyright (c) 2015 D. Richard Hipp | |
| 30 | +# | |
| 31 | +# This program is free software; you can redistribute it and/or | |
| 32 | +# modify it under the terms of the Simplified BSD License (also | |
| 33 | +# known as the "2-Clause License" or "FreeBSD License".) | |
| 34 | +# | |
| 35 | +# This program is distributed in the hope that it will be |
| --- a/test/clean.test | |
| +++ b/test/clean.test | |
| @@ -0,0 +1,35 @@ | |
| --- a/test/clean.test | |
| +++ b/test/clean.test | |
| @@ -0,0 +1,35 @@ | |
| 1 | # |
| 2 | # Copyright (c) 2015 D. Richard Hipp |
| 3 | # |
| 4 | # This program is free software; you can redistribute it and/or |
| 5 | # modify it under the terms of the Simplified BSD License (also |
| 6 | # known as the "2-Clause License" or "FreeBSD License".) |
| 7 | # |
| 8 | # This program is distributed in the hope that it will be useful, |
| 9 | # but without any warranty; without even the implied warranty of |
| 10 | # merchantability or fitness for a particular purpose. |
| 11 | # |
| 12 | # Author contact information: |
| 13 | # [email protected] |
| 14 | # http://www.hwaci.com/drh/ |
| 15 | # |
| 16 | ############################################################################ |
| 17 | # |
| 18 | # Tests of the "clean" command, including the ability to undo it. |
| 19 | # |
| 20 | |
| 21 | repo_init########### |
| 22 | |
| 23 | fossil extra |
| 24 | test clean-0 {[normalize_result] eq {}} |
| 25 | |
| 26 | #############0bute it and/or |
| 27 | # modify it under the terms of the Simplified BSD License (also |
| 28 | # kn# |
| 29 | # Copyright (c) 2015 D. Richard Hipp |
| 30 | # |
| 31 | # This program is free software; you can redistribute it and/or |
| 32 | # modify it under the terms of the Simplified BSD License (also |
| 33 | # known as the "2-Clause License" or "FreeBSD License".) |
| 34 | # |
| 35 | # This program is distributed in the hope that it will be |