|
|
|
@ -6,18 +6,17 @@
|
|
|
|
|
# @params
|
|
|
|
|
# Globals
|
|
|
|
|
# ${mydir}: current directory of the script
|
|
|
|
|
# ${reset_type}: reset type, modified files, all files or commit
|
|
|
|
|
# ${reset_type}: reset type, modified files or commit
|
|
|
|
|
# ${reset_option}: git reset flag, --mixed | --soft | --hard
|
|
|
|
|
# ${selected_files}: selected file to unstage
|
|
|
|
|
# ${selected_files}: selected file to reset
|
|
|
|
|
# ${selected_commit}: selected commit to reset
|
|
|
|
|
# ${confirm}: confirmation status of the user
|
|
|
|
|
# Arguments
|
|
|
|
|
# -h: show help message and quit
|
|
|
|
|
# -a: select files and select a commit to reset the fiel back to selected commit
|
|
|
|
|
# -c: reset commit
|
|
|
|
|
# -S: use --soft flag
|
|
|
|
|
# -H: use --hard flag
|
|
|
|
|
# -y: confirm action by default and skip confirmation
|
|
|
|
|
# -h|--help: show help message and quit
|
|
|
|
|
# -c|--commit: reset commit
|
|
|
|
|
# -S|--soft: use --soft flag
|
|
|
|
|
# -H|--hard: use --hard flag
|
|
|
|
|
# -y|--yes: confirm action by default and skip confirmation
|
|
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
set -f
|
|
|
|
@ -31,40 +30,43 @@ function usage() {
|
|
|
|
|
echo -e "Usage: dotbare freset [-h] [-a] [-c] [-S] [-H] ...\n"
|
|
|
|
|
echo -e "Reset/Unstage the selected staged file"
|
|
|
|
|
echo -e "Or reset the HEAD to certain commits by using -c flag\n"
|
|
|
|
|
echo -e "Default: unstage the selected files from\n"
|
|
|
|
|
echo -e "Default: unstage the selected files\n"
|
|
|
|
|
echo -e "optional arguments:"
|
|
|
|
|
echo -e " -h\t\tshow this help message and exit"
|
|
|
|
|
echo -e " -c\t\treset commit to certain commit, default --mixed flag, reset HEAD to certain commit put all changes into modified states"
|
|
|
|
|
echo -e " -S\t\treset commit using --soft flag, reset HEAD to certain commit without modify working tree"
|
|
|
|
|
echo -e " -H\t\treset commit using --hard flag, reset HEAD to certain commit dicard all changes from the working tree"
|
|
|
|
|
echo -e " -y\t\tconfirm action by default and skip confirmation"
|
|
|
|
|
echo -e " -h, --help\t\tshow this help message and exit"
|
|
|
|
|
echo -e " -c, --commit\t\treset commit to certain commit, default --mixed flag, reset HEAD to certain commit put all changes into modified state"
|
|
|
|
|
echo -e " -S, --soft\t\treset commit using --soft flag, reset HEAD to certain commit without modify working tree"
|
|
|
|
|
echo -e " -H, --hard\t\treset commit using --hard flag, reset HEAD to certain commit dicard all changes from the working tree"
|
|
|
|
|
echo -e " -y, --yes\t\tconfirm action by default and skip confirmation"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reset_option="--mixed"
|
|
|
|
|
reset_type="modified"
|
|
|
|
|
selected_files=()
|
|
|
|
|
|
|
|
|
|
while getopts ":hacSHy" opt
|
|
|
|
|
do
|
|
|
|
|
case "$opt" in
|
|
|
|
|
c)
|
|
|
|
|
while [[ "$#" -gt 0 ]]; do
|
|
|
|
|
case "$1" in
|
|
|
|
|
-c|--commit)
|
|
|
|
|
reset_type="commit"
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
S)
|
|
|
|
|
-S|--soft)
|
|
|
|
|
reset_option="--soft"
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
H)
|
|
|
|
|
-H|--hard)
|
|
|
|
|
reset_option="--hard"
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
y)
|
|
|
|
|
-y|--yes)
|
|
|
|
|
confirm='y'
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
h)
|
|
|
|
|
-h|--help)
|
|
|
|
|
usage
|
|
|
|
|
exit 0
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
echo "Invalid option: ${OPTARG}" >&2
|
|
|
|
|
*)
|
|
|
|
|
echo "Invalid option: $1" >&2
|
|
|
|
|
usage
|
|
|
|
|
exit 1
|
|
|
|
|
;;
|
|
|
|
|