Skip to content

Commit 90221f2

Browse files
authored
Allow git cp to create destination folder automatically (tj#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)
1 parent 263dcb4 commit 90221f2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

bin/git-cp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ else
3838
exit 40
3939
fi
4040

41+
if [[ "$DESTINATION_FILENAME" == */ ]]; then
42+
echo 1>&2 "$DESTINATION_FILENAME is not a file path."
43+
exit 80
44+
fi
45+
if [[ "$DESTINATION_FILENAME" == */* ]]; then
46+
DESTINATION_DIR="${DESTINATION_FILENAME%/*}"
47+
if ! mkdir -p "$DESTINATION_DIR"; then
48+
echo 1>&2 "Failed to create destination directory: $DESTINATION_DIR"
49+
exit 160
50+
fi
51+
fi
52+
4153
MERGE_OPT=
4254
ff=$(git config --get merge.ff)
4355
if [[ "$ff" == "only" ]]; then

0 commit comments

Comments
 (0)