Skip to content

Commit

Permalink
fix(finit): fix the crash when migrating large dotfile repo. Closes #12
Browse files Browse the repository at this point in the history
  • Loading branch information
kazhala committed Jul 10, 2020
1 parent f8f577f commit c788007
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

Noteble changes are documentated in this file.

## dev

### Fixed

- Fixed the dotbare crash when migrating a dotfile repo with over 100 files [#12](https://github.com/kazhala/dotbare/issues/12)

## 1.2.1 (09/07/2020)

### Added
Expand Down
5 changes: 4 additions & 1 deletion scripts/fbackup
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ function dotbare_backup() {
while IFS= read -r line; do
dir_name=$(dirname "${line}")
[[ ! -d "${DOTBARE_BACKUP}/${dir_name}" ]] && mkdir -p "${DOTBARE_BACKUP}/${dir_name}"
command "${action_command}" -v "${line}" "${DOTBARE_BACKUP}/${line}"
command "${action_command}" "${line}" "${DOTBARE_BACKUP}/${line}"
# Purposly didn't use the -v flag above because in finit, error message were
# directed to /dev/null but the move info will still be printed, causing confusion.
echo "${line} -> ${DOTBARE_BACKUP}/${line}"
done <<< "${selected_files}"
exit 0
}
Expand Down
19 changes: 12 additions & 7 deletions scripts/finit
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,25 @@ else
[[ ! -d "${DOTBARE_TREE}" ]] && mkdir -p "${DOTBARE_TREE}"
cd "${DOTBARE_TREE}"
git clone --bare "${remote_url}" "${DOTBARE_DIR}"
if ! git --git-dir "${DOTBARE_DIR}" --work-tree "${DOTBARE_TREE}" checkout 2> /dev/null; then
echo "File checkout failed"
echo "Backing up pre-existing dotfiles ..."

set +e
while ! git --git-dir "${DOTBARE_DIR}" --work-tree "${DOTBARE_TREE}" checkout 2> /dev/null; do
echo "Resolving conflicts ..."
git --git-dir "${DOTBARE_DIR}" --work-tree "${DOTBARE_TREE}" checkout 2>&1 \
| awk '{
if ($0 ~ /[\t].*/) {
gsub(/^[\t]/, "", $0)
print $0
}
}' \
| xargs -I __ "${mydir}"/fbackup -p __ -m
echo "dotfiles backup succeeded, checkout continue"
git --git-dir "${DOTBARE_DIR}" --work-tree "${DOTBARE_TREE}" checkout
fi
| xargs -I __ "${mydir}"/fbackup -p __ -m 2> /dev/null
if git --git-dir "${DOTBARE_DIR}" --work-tree "${DOTBARE_TREE}" checkout 2> /dev/null; then
echo "All conflicts resolved"
break
fi
done
set -e

git --git-dir "${DOTBARE_DIR}" --work-tree "${DOTBARE_TREE}" \
config --local status.showUntrackedFiles no
echo "File checkout succeeded"
Expand Down

0 comments on commit c788007

Please sign in to comment.