-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow git cp
to create destination folder automatically
#1091
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like there is a race and an extra subshell here. What about something like this?:
DESTINATION_FILENAME=${DESTINATION_FILENAME%/}
if ! mkdir -p "${DESTINATION_FILENAME%/*}"; then
echo 1>&2 "Failed to create destination directory: $DESTINATION_DIR"
exit 80
fi
Thanks! Removed the subprocess command. PTAL. (BTW my knowledge with shell script is very limited, so open to further suggestions) |
bin/git-cp
Outdated
exit 80 | ||
fi | ||
DESTINATION_DIR="${DESTINATION_FILENAME%/*}" | ||
if [ ! -d "$DESTINATION_DIR" ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use mkdir -p
directly as the cmd won't return error if the dir exists?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sense. Removed this check.
bin/git-cp
Outdated
echo 1>&2 "$DESTINATION_FILENAME is not a file path." | ||
exit 80 | ||
fi | ||
DESTINATION_DIR="${DESTINATION_FILENAME%/*}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the DESTINATION_FILENAME doesn't contain the directory, like ./foo
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question! Although the code still works for ./foo
(because DESTINATION_DIR
will simply be ./
and creating it is a harmless no-op), another case that I tested did lead to incorrect behavior which is when the DESTINATION_FILENAME
is just a filename. The previous revision would create a folder of that name, and make a copy of the source file into that folder (rather than copy to a file of that name).
I've now switched the condition to be checking whether DESTINATION_FILENAME
contains any slash characters - if not the folder creation is skipped.
… path contains slash(s)
@hyperupcall |
The new revision looks good to me - fixed that big. My only comment is that it seems |
@spacewander @hyperupcall Thanks for the review! Would either of you be able to click the merge button for me? I don't have write access to this repo. |
@weiw005 @spacewander will be able to do it |
Merged. Thanks! |
fixed #1089