diff --git a/completions/try.bash b/completions/try.bash index 258870db..60f95298 100755 --- a/completions/try.bash +++ b/completions/try.bash @@ -20,13 +20,12 @@ _try() { case "${cmd}" in try) - opts="-n -y -v -h -D -U summary commit explore" + opts="-n -y -v -h -i -D -U summary commit explore" if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 fi case "${prev}" in - -D) COMPREPLY=($(compgen -d "${cur}")) return 0 diff --git a/docs/try.1.md b/docs/try.1.md index 7dcf906c..4148bf6c 100644 --- a/docs/try.1.md +++ b/docs/try.1.md @@ -6,7 +6,7 @@ try - run a command in an overlay # SYNOPSIS -| try [-n] [-D DIR] CMD [ARG ...] +| try [-ny] [-i PATTERN] [-D DIR] [-U PATH] CMD [ARG ...] | try summary [DIR] | try commit [DIR] | try explore @@ -40,6 +40,10 @@ While using *try* you can choose to commit the result to the filesystem or compl ## Options +-i PATTERN + +: Ignore paths that match PATTERN on summary and commit. This option can be passed multiple times; the patterns given will be used in as arguments to `-e` in a call to `grep -v`. + -D *DIR* : Specifies DIR as the overlay directory (implies -n). The use of -D also implies that *DIR* already exists. diff --git a/test/run_tests.sh b/test/run_tests.sh index 94c7f55f..20ff622b 100755 --- a/test/run_tests.sh +++ b/test/run_tests.sh @@ -317,10 +317,24 @@ test_mkdir_on_file() diff -qr expected target } +test_ignore_flag() +{ + local try_workspace=$1 + cd "$try_workspace/" + + touch expected.bar + + ## Ignore changes to foo + "$try" -y -i foo1 -i foo2 "touch foo1.txt; touch foo2.txt; touch bar.txt" + + diff -q expected.bar bar.txt && + [ ! -f foo1.txt ] && + [ ! -f foo2.txt ] +} + test_dev() { local try_workspace=$1 - cp $RESOURCE_DIR/file.txt.gz "$try_workspace/" cd "$try_workspace/" "$try" -y "head -c 5 /dev/urandom > target" @@ -353,6 +367,7 @@ if [ "$#" -eq 0 ]; then run_test test_explore run_test test_empty_summary run_test test_mkdir_on_file + run_test test_ignore_flag run_test test_dev # uncomment this to force a failure diff --git a/try b/try index f4cce711..e27f0e99 100755 --- a/try +++ b/try @@ -253,7 +253,7 @@ summary() { fi ## Finds all potential changes - changed_files=$(find_upperdir_changes "$SANDBOX_DIR") + changed_files=$(find_upperdir_changes "$SANDBOX_DIR" "$IGNORE_FILE") summary_output=$(process_changes "$SANDBOX_DIR" "$changed_files") if [ -z "$summary_output" ] @@ -296,7 +296,7 @@ commit() { exit 1 fi - changed_files=$(find_upperdir_changes "$SANDBOX_DIR") + changed_files=$(find_upperdir_changes "$SANDBOX_DIR" "$IGNORE_FILE") summary_output=$(process_changes "$SANDBOX_DIR" "$changed_files") while IFS= read -r summary_line; do @@ -328,15 +328,16 @@ is_whiteout_file() { } ## Defines which changes we want to ignore in the summary and commit -## TODO: Make this be parametrizable, through a file for example ignore_changes() { - grep -v -e .rkr -e Rikerfile + ignore_file="$1" + grep -v -f "$ignore_file" } ## Lists all upperdir changes in raw format find_upperdir_changes() { sandbox_dir="$1" - find "$sandbox_dir/upperdir/" -type f -o \( -type c -size 0 \) -o -type d | ignore_changes + ignore_file="$2" + find "$sandbox_dir/upperdir/" -type f -o \( -type c -size 0 \) -o -type d | ignore_changes "$ignore_file" } @@ -415,10 +416,11 @@ sandbox_valid_or_empty() { usage() { cmd="$(basename $0)" cat >&2 <>"$IGNORE_FILE";; (D) if ! [ -d "$OPTARG" ] then printf "%s: no such directory $OPTARG\n" "$(basename $0)" >&2