feat(finit): added option to clone submodules for finit, Closes #8

pull/18/head
kevin zhuang 4 years ago
parent 3ff3f485ad
commit 868cf2d80b

@ -11,6 +11,7 @@ Noteble changes are documentated in this file.
- Added drop-in functionality [#6](https://github.com/kazhala/dotbare/pull/6)
- User can now place custom fzf scripts into scripts folder
- Added bash completion capabilities [#7](https://github.com/kazhala/dotbare/pull/7)
- Added option to clone submodule [#8](https://github.com/kazhala/dotbare/issues/8)
### Fixed

@ -22,7 +22,7 @@ source "${mydir}"/../helper/set_variable.sh
source "${mydir}"/../helper/git_query.sh
function usage() {
echo -e "Usage: dotbare fbackup [-h] [-s] [-p PATH] ...\n"
echo -e "Usage: dotbare fbackup [-h] [-m] [-s] [-p PATH] ...\n"
echo -e "Backup files to ${DOTBARE_BACKUP}"
echo -e "This is useful when untracking files or migrating on new machines\n"
echo -e "Default: backup every tracked files using cp to ${DOTBARE_BACKUP} directory\n"

@ -6,9 +6,11 @@
# Globals
# ${mydir}: current dir of the script
# ${confirm}: confirm status of the user
# ${post_hooks}: post checkout actions to perform
# Arguments
# -h: show help message and exit
# -u: specify remote dotfiles url to init
# -s: clone submodules after checkout
# -y: confirm action by default and skip confirmation
set -e
@ -19,7 +21,7 @@ source "${mydir}"/../helper/set_variable.sh
source "${mydir}"/../helper/get_confirmation.sh
function usage() {
echo -e "Usage: dotbare finit [-h] [-u URL] ...\n"
echo -e "Usage: dotbare finit [-h] [-y] [-s] [-u URL] ...\n"
echo -e "Init the git bare repository if doesn't exist"
# shellcheck disable=SC2016
echo -e 'The bare repository will be initialised under $DOTBARE_DIR, default to $HOME/.cfg if not set'
@ -29,12 +31,18 @@ function usage() {
echo -e "optional arguments:"
echo -e " -h\t\tshow this help message and exit"
echo -e " -u URL\tmigrate existing dotfiles from the git URL to current system"
echo -e " -s\t\tclone submodules after checkout"
echo -e " -y\t\tconfirm action by default and skip confirmation"
}
remote_url=""
while getopts ":hu:y" opt; do
post_hooks=()
while getopts ":hu:ys" opt; do
case "$opt" in
s)
[[ ! "${post_hooks[*]}" =~ "submodule" ]] && \
post_hooks+=("submodule")
;;
u)
remote_url="${OPTARG}"
;;
@ -89,6 +97,17 @@ else
/usr/bin/git --git-dir "${DOTBARE_DIR}" --work-tree "${DOTBARE_TREE}" \
config --local status.showUntrackedFiles no
echo "File checkout succeeded"
for hook in "${post_hooks[@]}"; do
case "${hook}" in
submodule)
echo "Cloning submodules ..."
/usr/bin/git --git-dir "${DOTBARE_DIR}" --work-tree "${DOTBARE_TREE}" \
submodule update --init --recursive
;;
esac
done
echo "Migration completed"
exit 0
fi

@ -31,7 +31,7 @@ migration() {
@test "finit help" {
run help
[ "${status}" -eq 0 ]
[ "${lines[0]}" = "Usage: dotbare finit [-h] [-u URL] ..." ]
[ "${lines[0]}" = "Usage: dotbare finit [-h] [-y] [-s] [-u URL] ..." ]
}
@test "finit init dotbare" {

Loading…
Cancel
Save