Allow git cp to create destination folder automatically (#1091)

* Allow `git cp` to create destination folder automatically

* Replace subshell command with builtin operation to infer DESTINATION_DIR

* Remove destination folder existence check and only create it when the path contains slash(s)
This commit is contained in:
Wei Wu 2023-10-24 21:03:36 -07:00 committed by GitHub
parent 263dcb4a79
commit 90221f2149
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -38,6 +38,18 @@ else
exit 40
fi
if [[ "$DESTINATION_FILENAME" == */ ]]; then
echo 1>&2 "$DESTINATION_FILENAME is not a file path."
exit 80
fi
if [[ "$DESTINATION_FILENAME" == */* ]]; then
DESTINATION_DIR="${DESTINATION_FILENAME%/*}"
if ! mkdir -p "$DESTINATION_DIR"; then
echo 1>&2 "Failed to create destination directory: $DESTINATION_DIR"
exit 160
fi
fi
MERGE_OPT=
ff=$(git config --get merge.ff)
if [[ "$ff" == "only" ]]; then