You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dotbare/scripts/funtrack

105 lines
4.0 KiB
Plaintext

4 years ago
#!/usr/bin/env bash
4 years ago
#
# untrack selected files
#
# @params
# Globals
# ${mydir}: current dir of the script
# ${track_type}: what method to use for untrack, untrack, update, retrack
# ${confirm}: use confirm status
# ${selected_files}: user selected_files for operation
4 years ago
# Arguments
# -h: display help message and exit
# -s: temporarily untrack files
# -S: resume track of temp untracked files
4 years ago
# -y: confirm action by default and skip confirmation
4 years ago
set -e
set -f
mydir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4 years ago
source "${mydir}"/../helper/set_variable.sh
source "${mydir}"/../helper/git_query.sh
source "${mydir}"/../helper/get_confirmation.sh
function usage() {
4 years ago
echo -e "Usage: dotbare funtrack [-h] [-s] [-S] ...\n"
4 years ago
echo -e "Untrack selected files from git\n"
4 years ago
echo -e "Default: the untrack will remove the file from index while"
4 years ago
echo -e "keeping the file in your current system (git rm --cached filename)"
echo -e "however, when your other computer pull down the changes, the file will be removed"
echo -e "make sure to run dotbare fbackup before pulling down the changes, alternativly"
echo -e "use the -s flag (git update-index --assume-unchanged [path])\n"
echo -e "optional arguments:"
4 years ago
echo -e " -h\t\tshow this help message and exit"
echo -e " -s\t\ttemporarily ignore changes of selected files"
echo -e " \t\tuse -S flag to resume tracking changes of selected_files"
echo -e " -S\t\tresume tracking changes of selected files"
echo -e " -y\t\tconfirm action by default and skip confirmation"
4 years ago
}
track_type="untrack"
4 years ago
while getopts ":hsSy" opt
4 years ago
do
case "$opt" in
s)
track_type="update"
;;
S)
track_type="retrack"
;;
4 years ago
y)
confirm='y'
;;
4 years ago
h)
usage
exit 0
;;
*)
echo "Invalid option: ${OPTARG}" >&2
usage
exit 1
;;
esac
done
selected_files=$(get_git_file "select files to untrack" | tr "\n" " ")
[[ -z "${selected_files}" ]] && exit 1
if [[ "${track_type}" == "update" ]]; then
echo "(dryrun) dotbare update-index --assume-unchanged ${selected_files}"
4 years ago
[[ -z "${confirm}" ]] && confirm=$(get_confirmation "Files will be temporarily stop being tracked for changes, continue?")
[[ "${confirm}" != 'y' ]] && exit 1
# shellcheck disable=SC2086
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" update-index --assume-unchanged ${selected_files}
echo -e " "
echo "Selected files are temporarily untracked by git, use -S to continue tracking changes."
echo "dotbare funtrack -s is not the recommanded way to untrack files, although it won't delete"
echo "the files on other machines, please refer to git update-index official"
echo "documentation for more information"
elif [[ "${track_type}" == "retrack" ]]; then
echo "(dryrun) dotbare update-index --no-assume-unchanged ${selected_files}"
4 years ago
[[ -z "${confirm}" ]] && confirm=$(get_confirmation "Files will resume being tracked by git, continue?")
[[ "${confirm}" != 'y' ]] && exit 1
# shellcheck disable=SC2086
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" update-index --no-assume-unchanged ${selected_files}
echo " "
echo "Selected files are being resumed for track by git."
echo "dotbare funtrack -s not the recommanded way to untrack files, although it won't delete"
echo "the files on other machines, please refer to git update-index official"
echo "documentation for more information"
else
echo "(dryrun) dotbare rm --cached ${selected_files}"
4 years ago
[[ -z "${confirm}" ]] && confirm=$(get_confirmation "Untrack the selected files?")
[[ "${confirm}" != 'y' ]] && exit 1
# shellcheck disable=SC2086
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" rm --cached ${selected_files}
echo -e " "
echo "Selected files are being untracked by git, make sure to run dotbare fbackup"
echo "on your other systems. When other system pull down this change, selected files"
echo "will be removed, this is the default behavior of git rm --cached, more information"
echo "refer to dotbare funtrack -h or README"
fi