Skip to content

Commit

Permalink
For #115: Update link file with newline test.
Browse files Browse the repository at this point in the history
 - IFS manipulation did not appear to be doing anything helpful, so I
   removed it.
 - Linking files with a newline is not actually fixed, but the
   behavior did change slightly, so I updated the test.
  • Loading branch information
dougborg committed Oct 13, 2014
1 parent f577ea5 commit 3b5fcb8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
16 changes: 6 additions & 10 deletions lib/commands/link.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ function symlink {
ignore 'ignored' "$castle"
return $EX_SUCCESS
fi
oldIFS=$IFS
IFS=$'\n'
for filename in $(get_repo_files "$repo/home"); do
IFS=$oldIFS
remote="$repo/home/$filename"
local=$HOME/$filename
local="$HOME/$filename"

if [[ -e $local || -L $local ]]; then
# $local exists (but may be a dead symlink)
Expand Down Expand Up @@ -71,8 +68,6 @@ function get_repo_dirs {
local root=$1
# Check if this is the root invocation.
if [[ -n $2 ]]; then
# The path to the current repo we are looking at:
repo_dir="$root/$2"
# The relative path to the submodule:
relpath="$2/"
else
Expand Down Expand Up @@ -100,7 +95,6 @@ function get_repo_files {
# of a repository and makes the paths returned by `git ls-files`
# relative to the root repo.
# All directory paths are computed as well.

# The root of repo we are looking at, will not change.
local root=$1
# Check if this is the root invocation.
Expand All @@ -114,6 +108,7 @@ function get_repo_files {
local repo_dir=$root
local relpath=''
fi
pending "list files" "$repo_dir" >&2
(
# Get files (+ submodule path prefix).
local path
Expand All @@ -122,12 +117,13 @@ function get_repo_files {
done < <(cd "$repo_dir" && git ls-files)

# Get all directories (+ submodule path prefix).
get_repo_files "$repo_dir" "$submodule"
get_repo_dirs "$root" "$relpath"

# Recurse on all submodule children (not descendants, i.e. immediate
# children), passing the relative path to the submodule as the 2nd arg.
for submodule in $(cd "$root"; git submodule --quiet foreach 'printf "%s\n" "$path"'); do
get_repo_files "$repo_dir" "$submodule"
for submodule in $(cd "$repo_dir"; git submodule --quiet foreach 'printf "%s\n" "$path"'); do
get_repo_files "$root" "$relpath$submodule"
done
) | sort | uniq
success "list files" "$repo_dir" >&2
}
15 changes: 7 additions & 8 deletions test/suites/link.bats
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,16 @@ EOF
castle 'dotfiles'
mkdir -p $HOME/.config/bar.dir
cat > $HOME/.config/foo.conf <<EOF
#I am just a regular foo.conf file
#I am just a regular foo.conf file
[foo]
A=True
EOF
cat > $HOME/.config/bar.dir/bar.conf <<EOF
#I am just a regular bar.conf file
#I am just a regular bar.conf file
[bar]
A=True
EOF

[ -f "$HOME/.config/foo.conf" ]
#.config/foo.conf should be overwritten by a directory of the same name
[ -d "$HOME/.config/bar.dir" ]
Expand Down Expand Up @@ -161,14 +161,13 @@ EOF

@test 'fail when linking file with newline' {
castle 'rc-files'
touch "$HOMESICK/repos/rc-files/home/filename
test_filename="filename
newline"
touch "$HOMESICK/repos/rc-files/home/$test_filename"
commit_repo_state $HOMESICK/repos/rc-files
$HOMESHICK_FN --batch link rc-files
[ -L "$HOME/\"filename" ]
[ -L "$HOME/newline\"" ]
is_symlink $HOMESICK/repos/rc-files/home/\"filename $HOME/\"filename
is_symlink $HOMESICK/repos/rc-files/home/newline\" $HOME/newline\"
[ -L "$HOME/\"filenamennewline\"" ]
is_symlink "$HOMESICK/repos/rc-files/home/\"filenamennewline\"" "$HOME/\"filenamennewline\""
}

@test 'files ignored by git should not be linked' {
Expand Down

0 comments on commit 3b5fcb8

Please sign in to comment.