BACKWARDS INCOMPATIBLE CHANGES:

* Using $BASEDIR to pass the location of the repo hasn't worked for a
  while. It has been removed.  Simply cd into the vcs repo before
  running a command.
BUG FIXES:
* .gitignore was being created in subdirectories instead of VCS root.
MINOR CHANGES
* _blackbox_common.sh: Replace change_to_root with change_to_vcs_root
* confidence_test.sh: Added more assertions and tests.
This commit is contained in:
tlimoncelli@stackexchange.com
2015-03-10 21:16:27 +00:00
parent ccba841cd8
commit 225d38ee11
6 changed files with 25 additions and 25 deletions

View File

@@ -27,7 +27,7 @@ function _determine_vcs_base_and_type() {
#find topmost dir with .svn sub-dir #find topmost dir with .svn sub-dir
parent="" parent=""
grandparent="." grandparent="."
mydir=$(pwd) mydir="$(pwd)"
while [ -d "$grandparent/.svn" ]; do while [ -d "$grandparent/.svn" ]; do
parent=$grandparent parent=$grandparent
grandparent="$parent/.." grandparent="$parent/.."
@@ -35,7 +35,7 @@ function _determine_vcs_base_and_type() {
if [ ! -z "$parent" ]; then if [ ! -z "$parent" ]; then
cd "$parent" cd "$parent"
echo "$(pwd)" pwd
else else
exit 1 exit 1
fi fi
@@ -256,6 +256,15 @@ function enumerate_subdirs() {
done <"$listfile" | sort -u done <"$listfile" | sort -u
} }
# chdir to the base of the repo.
function change_to_vcs_root() {
if [[ $REPOBASE = '' ]]; then
echo 'ERROR: _determine_vcs_base_and_type failed to set REPOBASE.'
exit 1
fi
cd "$REPOBASE"
}
# Output the path of a file relative to the repo base # Output the path of a file relative to the repo base
function vcs_relative_path() { function vcs_relative_path() {
# Usage: vcs_relative_path file # Usage: vcs_relative_path file
@@ -378,7 +387,6 @@ function vcs_commit_svn() {
} }
# Remove file from repo, even if it was deleted locally already. # Remove file from repo, even if it was deleted locally already.
# If it doesn't exist yet in the repo, it should be a no-op. # If it doesn't exist yet in the repo, it should be a no-op.
function vcs_remove() { function vcs_remove() {
@@ -396,17 +404,3 @@ function vcs_remove_git() {
function vcs_remove_svn() { function vcs_remove_svn() {
svn delete """$@""" svn delete """$@"""
} }
function change_to_root() {
# If BASEDIR is not set, use REPOBASE.
if [[ "$BASEDIR" = "" ]]; then
BASEDIR="$REPOBASE"
fi
if [[ "$BASEDIR" = "/dev/null" ]]; then
echo 'WARNING: Not in a VCS repo. Not changing directory.'
else
echo "CDing to $BASEDIR"
cd "$BASEDIR"
fi
}

View File

@@ -22,15 +22,14 @@ if [[ $1 != 'yes' ]]; then
fi fi
fi fi
echo cd "$REPOBASE" change_to_vcs_root
cd "$REPOBASE"
echo VCS_TYPE: $VCS_TYPE echo VCS_TYPE: $VCS_TYPE
if [[ $VCS_TYPE = "git" || $VCS_TYPE = "hg" ]]; then if [[ $VCS_TYPE = "git" || $VCS_TYPE = "hg" ]]; then
# Update .gitignore or .hgignore # Update .gitignore or .hgignore
IGNOREFILE=".${VCS_TYPE}ignore" IGNOREFILE="${REPOBASE}/.${VCS_TYPE}ignore"
if ! grep -sx >/dev/null 'pubring.gpg~' "$IGNOREFILE" ; then if ! grep -sx >/dev/null 'pubring.gpg~' "$IGNOREFILE" ; then
echo 'pubring.gpg~' >>"$IGNOREFILE" echo 'pubring.gpg~' >>"$IGNOREFILE"
fi fi

View File

@@ -23,7 +23,7 @@ else
FILE_GROUP="$1" FILE_GROUP="$1"
fi fi
change_to_root change_to_vcs_root
prepare_keychain prepare_keychain
# Decrypt: # Decrypt:

View File

@@ -50,9 +50,11 @@ fi
# TODO(tlim): This should be moved to _blackbox_common.sh in a # TODO(tlim): This should be moved to _blackbox_common.sh in a
# VCS-independent way. # VCS-independent way.
IGNOREFILE=".${VCS_TYPE}ignore" IGNOREFILE="${REPOBASE}/.${VCS_TYPE}ignore"
if [[ $VCS_TYPE = 'git' ]]; then if [[ $VCS_TYPE = 'git' ]]; then
ignored_file="$(echo "$unencrypted_file" | sed 's/\([\*\?]\)/\\\1/g' | sed 's/^\([!#]\)/\\\1/')" relfile="$(vcs_relative_path "$unencrypted_file")"
relfileb="${relfile/\$\//}"
ignored_file="$(echo "${relfileb}" | sed 's/\([\*\?]\)/\\\1/g' | sed 's/^\([!#]\)/\\\1/')"
if ! grep -Fsx >/dev/null "$ignored_file" "$IGNOREFILE"; then if ! grep -Fsx >/dev/null "$ignored_file" "$IGNOREFILE"; then
echo "$ignored_file" >>"$IGNOREFILE" echo "$ignored_file" >>"$IGNOREFILE"
COMMIT_FILES+=("$IGNOREFILE") COMMIT_FILES+=("$IGNOREFILE")

View File

@@ -19,7 +19,7 @@ set -e
blackbox_home=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) blackbox_home=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source "${blackbox_home}/_blackbox_common.sh" source "${blackbox_home}/_blackbox_common.sh"
change_to_root change_to_vcs_root
echo '========== FILES BEING SHREDDED:' echo '========== FILES BEING SHREDDED:'
for i in $(<"$BB_FILES") ; do for i in $(<"$BB_FILES") ; do

View File

@@ -214,6 +214,7 @@ PHASE 'She enrolls secrets.txt.'
blackbox_register_new_file secret.txt blackbox_register_new_file secret.txt
assert_file_missing secret.txt assert_file_missing secret.txt
assert_file_exists secret.txt.gpg assert_file_exists secret.txt.gpg
assert_line_exists 'secret.txt' .gitignore
PHASE 'She decrypts secrets.txt.' PHASE 'She decrypts secrets.txt.'
blackbox_edit_start secret.txt blackbox_edit_start secret.txt
@@ -297,6 +298,7 @@ blackbox_register_new_file mistake.txt
assert_file_missing mistake.txt assert_file_missing mistake.txt
assert_file_exists mistake.txt.gpg assert_file_exists mistake.txt.gpg
# NOTE: It is still in the history. That should be corrected someday. # NOTE: It is still in the history. That should be corrected someday.
assert_line_exists 'mistake.txt' .gitignore
PHASE 'Bob enrolls my/path/to/relsecrets.txt.' PHASE 'Bob enrolls my/path/to/relsecrets.txt.'
mkdir my my/path my/path/to mkdir my my/path my/path/to
@@ -305,6 +307,9 @@ cd my/path/to
blackbox_register_new_file relsecrets.txt blackbox_register_new_file relsecrets.txt
assert_file_missing relsecrets.txt assert_file_missing relsecrets.txt
assert_file_exists relsecrets.txt.gpg assert_file_exists relsecrets.txt.gpg
assert_file_missing .gitignore
assert_file_exists ../../../.gitignore
assert_line_exists 'my/path/to/relsecrets.txt' ../../../.gitignore
PHASE 'Bob decrypts relsecrets.txt.' PHASE 'Bob decrypts relsecrets.txt.'
cd .. cd ..
@@ -355,5 +360,5 @@ fi
find .git?* * -type f -ls find .git?* * -type f -ls
echo cd "$test_repository" echo cd "$test_repository"
echo rm "$test_repository" echo rm -rf "$test_repository"
echo DONE. echo DONE.