Fossil SCM

Add 'no-prompt' option to the clean command (i.e. answers 'No' to every prompt). Add initial tests of enhanced clean command.

mistachkin 2015-07-03 18:36 enhancedUndo
Commit bc1504eec7d45c12828993e683e9528018164a47
2 files changed +27 -18 +35
+27 -18
--- src/checkin.c
+++ src/checkin.c
@@ -686,19 +686,21 @@
686686
** comma separated list of glob patterns.
687687
** --keep <CSG> Keep files matching this comma separated
688688
** list of glob patterns.
689689
** -n|--dry-run Delete nothing, but display what would have been
690690
** deleted.
691
+** --no-prompt This option disables prompting the user for input
692
+** and assumes an answer of 'No' for every question.
691693
** --temp Remove only Fossil-generated temporary files.
692694
** -v|--verbose Show all files as they are removed.
693695
**
694696
** See also: addremove, extras, status
695697
*/
696698
void clean_cmd(void){
697699
int allFileFlag, allDirFlag, dryRunFlag, verboseFlag;
698700
int emptyDirsFlag, dirsOnlyFlag;
699
- int disableUndo;
701
+ int disableUndo, noPrompt;
700702
unsigned scanFlags = 0;
701703
int verilyFlag = 0;
702704
const char *zIgnoreFlag, *zKeepFlag, *zCleanFlag;
703705
Glob *pIgnore, *pKeep, *pClean;
704706
int nRoot;
@@ -714,10 +716,11 @@
714716
}
715717
if( !dryRunFlag ){
716718
dryRunFlag = find_option("whatif",0,0)!=0;
717719
}
718720
disableUndo = find_option("disable-undo",0,0)!=0;
721
+ noPrompt = find_option("no-prompt",0,0)!=0;
719722
allFileFlag = allDirFlag = find_option("force","f",0)!=0;
720723
dirsOnlyFlag = find_option("dirsonly",0,0)!=0;
721724
emptyDirsFlag = find_option("emptydirs","d",0)!=0 || dirsOnlyFlag;
722725
if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL;
723726
if( find_option("temp",0,0)!=0 ) scanFlags |= SCAN_TEMP;
@@ -777,26 +780,29 @@
777780
int undoRc = UNDO_NONE;
778781
if( !disableUndo ){
779782
undoRc = undo_maybe_save(zName+nRoot, UNDO_SIZE_LIMIT);
780783
}
781784
if( undoRc!=UNDO_SAVED_OK ){
782
- Blob ans;
783785
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
+ }
791799
if( cReply=='a' || cReply=='A' ){
792800
allFileFlag = 1;
793801
}else if( cReply!='y' && cReply!='Y' ){
794
- blob_reset(&ans);
795802
continue;
796803
}
797
- blob_reset(&ans);
798804
}
799805
}
800806
if( dryRunFlag || file_delete(zName)==0 ){
801807
if( verboseFlag || dryRunFlag ){
802808
fossil_print("Removed unmanaged file: %s\n", zName+nRoot);
@@ -830,23 +836,26 @@
830836
" or \"keep-glob\")\n", zName+nRoot);
831837
}
832838
continue;
833839
}
834840
if( !allDirFlag && !dryRunFlag && !glob_match(pClean, zName+nRoot) ){
835
- Blob ans;
836841
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
+ }
841852
if( cReply=='a' || cReply=='A' ){
842853
allDirFlag = 1;
843854
}else if( cReply!='y' && cReply!='Y' ){
844
- blob_reset(&ans);
845855
continue;
846856
}
847
- blob_reset(&ans);
848857
}
849858
if( dryRunFlag || file_rmdir(zName)==0 ){
850859
if( verboseFlag || dryRunFlag ){
851860
fossil_print("Removed unmanaged directory: %s\n", zName+nRoot);
852861
}
853862
854863
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
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button