Skip to content

Commit

Permalink
Allow git cp to create destination folder automatically (#1091)
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
weiw005 authored Oct 25, 2023
1 parent 263dcb4 commit 90221f2
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions bin/git-cp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 90221f2

Please sign in to comment.