# # # add_file "tests/t_restricted_commands_consistent.at" # # patch "ChangeLog" # from [012316a22aa364034903caa6fa70d1cc342c0ffd] # to [db6077186860565a385fd952f184ce11639e9e73] # # patch "app_state.cc" # from [85d71171b53f38bca6f070200f2edaf7aaf99018] # to [1694f8a2eb1312ffd11d27c0df397ceb5d8f97ba] # # patch "app_state.hh" # from [f4879c31f936326c7e402139b7a5a5179467876f] # to [a0af6f1a90b233e4c7a7eab3298b427e572ae3ba] # # patch "commands.cc" # from [67c6e0b7843df6c466dbb3ef9def38498684478d] # to [08a96a78a1e79cd3bf487f742440d4a991783acd] # # patch "restrictions.hh" # from [5779a2e7cd59e34200501b14c0328fc40b72a8c3] # to [a339763159f6bb2b0842dd3d8492131c46f81a0c] # # patch "tests/t_restricted_commands_consistent.at" # from [] # to [a8a896d3209ec673f8197488d639226d62b18158] # # patch "testsuite.at" # from [7eb046ec5e8c90996e72969051e77e2a9be82e0e] # to [9dd9a5a0489c79191698a273276039b7a69e421f] # ============================================================ --- ChangeLog 012316a22aa364034903caa6fa70d1cc342c0ffd +++ ChangeLog db6077186860565a385fd952f184ce11639e9e73 @@ -1,3 +1,15 @@ +2006-01-05 Derek Scherger + + * app_state.{cc,hh} (set_restriction): remove "respect_ignore" + flag and don't complain about ignored files + * commands.cc (status, list, diff): allow --exclude option for + restrictions + * restrictions.hh: add a comment about restricted command + consistency + * tests/t_restricted_commands_consistent.at: new test to give that + bark some bite + * testsuite.at: call it + 2005-12-29 Nathaniel Smith * NEWS: Write up for 0.25. ============================================================ --- app_state.cc 85d71171b53f38bca6f070200f2edaf7aaf99018 +++ app_state.cc 1694f8a2eb1312ffd11d27c0df397ceb5d8f97ba @@ -142,9 +142,7 @@ } void -app_state::set_restriction(path_set const & valid_paths, - vector const & paths, - bool respect_ignore) +app_state::set_restriction(path_set const & valid_paths, vector const & paths) { static file_path root = file_path_internal(""); restrictions.clear(); @@ -153,13 +151,8 @@ { file_path p = file_path_external(*i); - if (respect_ignore && lua.hook_ignore_file(p)) - { - L(F("'%s' ignored by restricted path set\n") % p); - continue; - } - - N(p == root || valid_paths.find(p) != valid_paths.end(), + N(lua.hook_ignore_file(p) || + p == root || valid_paths.find(p) != valid_paths.end(), F("unknown path '%s'\n") % p); L(F("'%s' added to restricted path set\n") % p); @@ -171,13 +164,8 @@ { file_path p = file_path_external(*i); - if (respect_ignore && lua.hook_ignore_file(p)) - { - L(F("'%s' ignored by excluded path set\n") % p); - continue; - } - - N(p == root || valid_paths.find(p) != valid_paths.end(), + N(lua.hook_ignore_file(p) || + p == root || valid_paths.find(p) != valid_paths.end(), F("unknown path '%s'\n") % p); L(F("'%s' added to excluded path set\n") % p); ============================================================ --- app_state.hh f4879c31f936326c7e402139b7a5a5179467876f +++ app_state.hh a0af6f1a90b233e4c7a7eab3298b427e572ae3ba @@ -89,8 +89,7 @@ void create_working_copy(system_path const & dir); void set_restriction(path_set const & valid_paths, - std::vector const & paths, - bool respect_ignore = true); + std::vector const & paths); bool restriction_includes(file_path const & path); // Set the branch name. If you only invoke set_branch, the branch ============================================================ --- commands.cc 67c6e0b7843df6c466dbb3ef9def38498684478d +++ commands.cc 08a96a78a1e79cd3bf487f742440d4a991783acd @@ -1273,7 +1273,7 @@ } CMD(status, N_("informative"), N_("[PATH]..."), N_("show status of working copy"), - OPT_DEPTH % OPT_BRIEF) + OPT_DEPTH % OPT_EXCLUDE % OPT_BRIEF) { revision_set rs; manifest_map m_old, m_new; @@ -1645,7 +1645,6 @@ { revision_set rev; manifest_map m_old, m_new; - //path_set known, unknown, ignored; path_set known; calculate_restricted_revision(app, args, rev, m_old, m_new); @@ -1730,7 +1729,7 @@ "missing"), N_("show database objects, or the current working copy manifest,\n" "or unknown, intentionally ignored, or missing state files"), - OPT_DEPTH) + OPT_DEPTH % OPT_EXCLUDE) { if (args.size() == 0) throw usage(name); @@ -2320,7 +2319,8 @@ CMD(commit, N_("working copy"), N_("[PATH]..."), N_("commit working copy to database"), - OPT_BRANCH_NAME % OPT_MESSAGE % OPT_MSGFILE % OPT_DATE % OPT_AUTHOR % OPT_DEPTH % OPT_EXCLUDE) + OPT_BRANCH_NAME % OPT_MESSAGE % OPT_MSGFILE % OPT_DATE % OPT_AUTHOR % + OPT_DEPTH % OPT_EXCLUDE) { string log_message(""); revision_set rs; @@ -2676,7 +2676,7 @@ "If one revision is given, the diff between the working directory and\n" "that revision is shown. If two revisions are given, the diff between\n" "them is given. If no format is specified, unified is used by default."), - OPT_REVISION % OPT_DEPTH % + OPT_REVISION % OPT_DEPTH % OPT_EXCLUDE % OPT_UNIFIED_DIFF % OPT_CONTEXT_DIFF % OPT_EXTERNAL_DIFF % OPT_EXTERNAL_DIFF_ARGS) { @@ -3417,7 +3417,8 @@ CMD(revert, N_("working copy"), N_("[PATH]..."), - N_("revert file(s), dir(s) or entire working copy (\".\")"), OPT_DEPTH % OPT_EXCLUDE % OPT_MISSING) + N_("revert file(s), dir(s) or entire working copy (\".\")"), + OPT_DEPTH % OPT_EXCLUDE % OPT_MISSING) { manifest_map m_old; revision_id old_revision_id; @@ -3461,7 +3462,7 @@ if (args_copy.size() == 0) return; } - app.set_restriction(valid_paths, args_copy, false); + app.set_restriction(valid_paths, args_copy); restrict_path_rearrangement(work, included, excluded, app); ============================================================ --- restrictions.hh 5779a2e7cd59e34200501b14c0328fc40b72a8c3 +++ restrictions.hh a339763159f6bb2b0842dd3d8492131c46f81a0c @@ -6,6 +6,23 @@ // licensed to the public under the terms of the GNU GPL (>= 2) // see the file COPYING for details +// the following commands accept file arguments and --exclude and --depth +// options used to define a restriction on the files that will be processed: +// +// ls unknown +// ls ignored +// ls missing +// ls known +// status +// diff +// commit +// revert +// +// it is important that these commands operate on the same set of files given +// the same restriction specification. this allows for destructive commands +// (commit and revert) to be "tested" first with non-destructive commands +// (ls unknown/ignored/missing/known, status, diff) + #include "app_state.hh" #include "change_set.hh" #include "vocab.hh" ============================================================ --- tests/t_restricted_commands_consistent.at +++ tests/t_restricted_commands_consistent.at a8a896d3209ec673f8197488d639226d62b18158 @@ -0,0 +1,241 @@ +AT_SETUP([restricted commands are consistent]) +MONOTONE_SETUP + +# the following commands accept file arguments and --exclude and --depth +# options used to define a restriction on the files that will be processed: +# +# ls unknown +# ls ignored +# ls missing +# ls known +# status +# diff +# commit +# revert +# + +# this test ensures that these commands operate on the same set of files given +# the same restriction specification. maintaining consistency across these +# commands allows for destructive commands (commit and revert) to be "tested" +# first with non-destructive commands (ls unknown/ignored/missing/known, status, +# diff) + +# macros for running and verifying tests + +m4_define([PATCH_FILES], [ +AT_DATA(file1, [file1 $1 +]) +AT_DATA(file2, [file2 $1 +]) +AT_DATA(foo/foo1, [foo1 $1 +]) +AT_DATA(foo/foo2, [foo2 $1 +]) +AT_DATA(foo/bar/bar1, [bar1 $1 +]) +AT_DATA(foo/bar/bar2, [bar2 $1 +]) +]) + +# $1 the monotone command and associated arguments to run +m4_define([RUN], [ +AT_CHECK(MONOTONE $1, [], [stdout], [stderr]) +]) + +# $1 0 or 1 to indicate whether grep should find find words in the output or not +# $2 list of words to grep output for +m4_define([GREP], [ +for i in $2 +do +AT_CHECK(grep $i output, [$1], [ignore], [ignore]) +done +]) + +# $1 stdout or stderr to be copied to output for grep +# $2 list of words that must exist in output +# $3 list of words that must not exist in output +m4_define([CHECK], [ +AT_CHECK(cp $1 output) +GREP(0, $2) +GREP(1, $3) +]) + +# $1 the monotone command and arguments to run +# $2 stderr or stdout to grep against +# $3 list of words that must exist in output +# $4 list of words that must not exist in output +m4_define([TEST], [ +RUN($1) +CHECK($2, $3, $4) +]) + +# test restrictions and associated lists of included/excluded files + +ROOT_ARGS="." +ROOT_INCLUDED="file1 file2 foo/foo1 foo/foo2 foo/bar/bar1 foo/bar/bar2" +ROOT_EXCLUDED="" + +INCLUDE_ARGS="file1 foo/foo1 foo/bar/bar1" +INCLUDE_INCLUDED="file1 foo/foo1 foo/bar/bar1" +INCLUDE_EXCLUDED="file2 foo/foo2 foo/bar/bar2" + +EXCLUDE_ARGS=". --exclude file1 --exclude foo/foo1 --exclude foo/bar/bar1" +EXCLUDE_INCLUDED="file2 foo/foo2 foo/bar/bar2" +EXCLUDE_EXCLUDED="file1 foo/foo1 foo/bar/bar1" + +BOTH_ARGS="foo --exclude foo/foo1 --exclude foo/bar/bar1" +BOTH_INCLUDED="foo/foo2 foo/bar/bar2" +BOTH_EXCLUDED="file1 file2 foo/foo1 foo/bar/bar1" + +DEPTH_ARGS=". --depth 1" +DEPTH_INCLUDED="file1 file2 foo/foo1 foo/foo2" +DEPTH_EXCLUDED="foo/bar/bar1 foo/bar/bar2" + +# setup working copy + +AT_CHECK(mkdir foo) +AT_CHECK(mkdir foo/bar) + +PATCH_FILES(initial addition of files) +AT_CHECK(MONOTONE add file1 file2 foo, [], [ignore], [ignore]) +COMMIT(testbranch) + +# check that ls unknown/ignored/missing/known, status, diff, revert and commit +# all agree on what is included/excluded by various restrictions + +# ls unknown + +# dropped files are valid for restriction but are unknown in the post-state +AT_CHECK(MONOTONE drop file1 file2 foo/foo1 foo/foo2 foo/bar/bar1 foo/bar/bar2, [], [ignore], [ignore]) +TEST(ls unknown $ROOT_ARGS, stdout, $ROOT_INCLUDED, $ROOT_EXCLUDED) +TEST(ls unknown $INCLUDE_ARGS, stdout, $INCLUDE_INCLUDED, $INCLUDE_EXCLUDED) +TEST(ls unknown $EXCLUDE_ARGS, stdout, $EXCLUDE_INCLUDED, $EXCLUDE_EXCLUDED) +TEST(ls unknown $BOTH_ARGS, stdout, $BOTH_INCLUDED, $BOTH_EXCLUDED) +TEST(ls unknown $DEPTH_ARGS, stdout, $DEPTH_INCLUDED, $DEPTH_EXCLUDED) +AT_CHECK(MONOTONE revert ., [], [ignore], [ignore]) + +# ls ignored + +AT_DATA(ignore.lua, [ +function ignore_file(name) + if (string.find(name, "1$")) then return true end + if (string.find(name, "2$")) then return true end + return false +end +]) + +# only unknown files are considered by ls ignored +AT_CHECK(MONOTONE drop file1 file2 foo/foo1 foo/foo2 foo/bar/bar1 foo/bar/bar2, [], [ignore], [ignore]) +TEST(ls ignored --rcfile ignore.lua $ROOT_ARGS, stdout, $ROOT_INCLUDED, $ROOT_EXCLUDED) +TEST(ls ignored --rcfile ignore.lua $INCLUDE_ARGS, stdout, $INCLUDE_INCLUDED, $INCLUDE_EXCLUDED) +TEST(ls ignored --rcfile ignore.lua $EXCLUDE_ARGS, stdout, $EXCLUDE_INCLUDED, $EXCLUDE_EXCLUDED) +TEST(ls ignored --rcfile ignore.lua $BOTH_ARGS, stdout, $BOTH_INCLUDED, $BOTH_EXCLUDED) +TEST(ls ignored --rcfile ignore.lua $DEPTH_ARGS, stdout, $DEPTH_INCLUDED, $DEPTH_EXCLUDED) +AT_CHECK(MONOTONE revert ., [], [ignore], [ignore]) + +# ls missing + +AT_CHECK(rm file1 file2 foo/foo1 foo/foo2 foo/bar/bar1 foo/bar/bar2, [], [ignore], [ignore]) +TEST(ls missing $ROOT_ARGS, stdout, $ROOT_INCLUDED, $ROOT_EXCLUDED) +TEST(ls missing $INCLUDE_ARGS, stdout, $INCLUDE_INCLUDED, $INCLUDE_EXCLUDED) +TEST(ls missing $EXCLUDE_ARGS, stdout, $EXCLUDE_INCLUDED, $EXCLUDE_EXCLUDED) +TEST(ls missing $BOTH_ARGS, stdout, $BOTH_INCLUDED, $BOTH_EXCLUDED) +TEST(ls missing $DEPTH_ARGS, stdout, $DEPTH_INCLUDED, $DEPTH_EXCLUDED) +AT_CHECK(MONOTONE revert ., [], [ignore], [ignore]) + +PATCH_FILES(changes for testing ls known, status, diff) + +# ls known + +TEST(ls known $ROOT_ARGS, stdout, $ROOT_INCLUDED, $ROOT_EXCLUDED) +TEST(ls known $INCLUDE_ARGS, stdout, $INCLUDE_INCLUDED, $INCLUDE_EXCLUDED) +TEST(ls known $EXCLUDE_ARGS, stdout, $EXCLUDE_INCLUDED, $EXCLUDE_EXCLUDED) +TEST(ls known $BOTH_ARGS, stdout, $BOTH_INCLUDED, $BOTH_EXCLUDED) +TEST(ls known $DEPTH_ARGS, stdout, $DEPTH_INCLUDED, $DEPTH_EXCLUDED) + +# status + +TEST(status $ROOT_ARGS, stdout, $ROOT_INCLUDED, $ROOT_EXCLUDED) +TEST(status $INCLUDE_ARGS, stdout, $INCLUDE_INCLUDED, $INCLUDE_EXCLUDED) +TEST(status $EXCLUDE_ARGS, stdout, $EXCLUDE_INCLUDED, $EXCLUDE_EXCLUDED) +TEST(status $BOTH_ARGS, stdout, $BOTH_INCLUDED, $BOTH_EXCLUDED) +TEST(status $DEPTH_ARGS, stdout, $DEPTH_INCLUDED, $DEPTH_EXCLUDED) + +# diff + +TEST(diff $ROOT_ARGS, stdout, $ROOT_INCLUDED, $ROOT_EXCLUDED) +TEST(diff $INCLUDE_ARGS, stdout, $INCLUDE_INCLUDED, $INCLUDE_EXCLUDED) +TEST(diff $EXCLUDE_ARGS, stdout, $EXCLUDE_INCLUDED, $EXCLUDE_EXCLUDED) +TEST(diff $BOTH_ARGS, stdout, $BOTH_INCLUDED, $BOTH_EXCLUDED) +TEST(diff $DEPTH_ARGS, stdout, $DEPTH_INCLUDED, $DEPTH_EXCLUDED) + +# revert + +PATCH_FILES(revert root) +TEST(revert $ROOT_ARGS, stderr, $ROOT_INCLUDED, $ROOT_EXCLUDED) + +PATCH_FILES(revert include) +TEST(revert $INCLUDE_ARGS, stderr, $INCLUDE_INCLUDED, $INCLUDE_EXCLUDED) + +PATCH_FILES(revert exclude) +TEST(revert $EXCLUDE_ARGS, stderr, $EXCLUDE_INCLUDED, $EXCLUDE_EXCLUDED) + +PATCH_FILES(revert both) +TEST(revert $BOTH_ARGS, stderr, $BOTH_INCLUDED, $BOTH_EXCLUDED) + +PATCH_FILES(revert depth) +TEST(revert $DEPTH_ARGS, stderr, $DEPTH_INCLUDED, $DEPTH_EXCLUDED) + +# commit + +OLD=`BASE_REVISION` +PATCH_FILES(commit root) +RUN(commit -m root $ROOT_ARGS) +NEW=`BASE_REVISION` + +AT_CHECK(MONOTONE status, [], [stdout], [stderr]) +CHECK(stdout, $ROOT_EXCLUDED, $ROOT_INCLUDED) +AT_CHECK(MONOTONE diff -r $OLD -r $NEW, [], [stdout], [ignore]) +CHECK(stdout, $ROOT_INCLUDED, $ROOT_EXCLUDED) + +OLD=`BASE_REVISION` +PATCH_FILES(commit includes) +RUN(commit -m includes $INCLUDE_ARGS) +NEW=`BASE_REVISION` + +AT_CHECK(MONOTONE diff -r $OLD -r $NEW, [], [stdout], [ignore]) +CHECK(stdout, $INCLUDE_INCLUDED, $INCLUDE_EXCLUDED) +AT_CHECK(MONOTONE diff -r $OLD -r $NEW, [], [stdout], [ignore]) +CHECK(stdout, $INCLUDE_INCLUDED, $INCLUDE_EXCLUDED) + +OLD=`BASE_REVISION` +PATCH_FILES(commit excludes) +RUN(commit -m excludes $EXCLUDE_ARGS) +NEW=`BASE_REVISION` + +AT_CHECK(MONOTONE status, [], [stdout], [ignore]) +CHECK(stdout, $EXCLUDE_EXCLUDED, $EXCLUDE_INCLUDED) +AT_CHECK(MONOTONE diff -r $OLD -r $NEW, [], [stdout], [ignore]) +CHECK(stdout, $EXCLUDE_INCLUDED, $EXCLUDE_EXCLUDED) + +OLD=`BASE_REVISION` +PATCH_FILES(commit both) +RUN(commit -m both $BOTH_ARGS) +NEW=`BASE_REVISION` + +AT_CHECK(MONOTONE status, [], [stdout], [ignore]) +CHECK(stdout, $BOTH_EXCLUDED, $BOTH_INCLUDED) +AT_CHECK(MONOTONE diff -r $OLD -r $NEW, [], [stdout], [ignore]) +CHECK(stdout, $BOTH_INCLUDED, $BOTH_EXCLUDED) + +OLD=`BASE_REVISION` +PATCH_FILES(commit depth) +RUN(commit -m depth $DEPTH_ARGS) +NEW=`BASE_REVISION` + +AT_CHECK(MONOTONE status, [], [stdout], [ignore]) +CHECK(stdout, $DEPTH_EXCLUDED, $DEPTH_INCLUDED) +AT_CHECK(MONOTONE diff -r $OLD -r $NEW, [], [stdout], [ignore]) +CHECK(stdout, $DEPTH_INCLUDED, $DEPTH_EXCLUDED) + +AT_CLEANUP ============================================================ --- testsuite.at 7eb046ec5e8c90996e72969051e77e2a9be82e0e +++ testsuite.at 9dd9a5a0489c79191698a273276039b7a69e421f @@ -754,3 +754,4 @@ m4_include(tests/t_update_switch_branch.at) m4_include(tests/t_mixed_case_pwd.at) m4_include(tests/t_read_privkey.at) +m4_include(tests/t_restricted_commands_consistent.at)