mirror of
https://github.com/tj/git-extras.git
synced 2026-09-15 09:56:19 -04:00
Simplify the code.
This commit is contained in:
parent
b85fc019ca
commit
91b3e47243
30
bin/git-cp
30
bin/git-cp
|
|
@ -32,33 +32,9 @@ elif [[ "$CURRENT_FILENAME" == "" ]]; then
|
|||
usage
|
||||
exit 10 # Missing arguments CURRENT_FILENAME
|
||||
else
|
||||
if [ ! -e "$DESTINATION_FILENAME" ]; then
|
||||
echo 1>&2 "$DESTINATION_FILENAME already exists."
|
||||
echo 1>&2 "Make sure to remove the destination first."
|
||||
exit 40
|
||||
fi
|
||||
|
||||
echo "Coping $CURRENT_FILENAME into $DESTINATION_FILENAME"
|
||||
INTERMEDIATE_FILENAME="${CURRENT_FILENAME//\//__}-move-to-${DESTINATION_FILENAME//\//__}"
|
||||
cp -r "${CURRENT_FILENAME}" "${DESTINATION_FILENAME}"
|
||||
|
||||
# We keep the existing file on the side in a commit
|
||||
git mv "${CURRENT_FILENAME}" "${INTERMEDIATE_FILENAME}"
|
||||
git commit -nm "Keep $CURRENT_FILENAME"
|
||||
SAVED=$(git rev-parse HEAD)
|
||||
|
||||
# We come back to the previous state
|
||||
git reset --hard HEAD^ # Revert that change
|
||||
|
||||
# We move the file to its new destination
|
||||
git mv "${CURRENT_FILENAME}" "${DESTINATION_FILENAME}"
|
||||
git add "${DESTINATION_FILENAME}"
|
||||
git commit -nm "Copy $CURRENT_FILENAME into $DESTINATION_FILENAME"
|
||||
|
||||
# We get back our copy
|
||||
git merge "${SAVED}"
|
||||
git commit -a -m "Duplicate ${CURRENT_FILENAME} history." # Keeping both files
|
||||
|
||||
# We get back our original name
|
||||
git mv "${INTERMEDIATE_FILENAME}" "${CURRENT_FILENAME}"
|
||||
git commit -nm "Set back $CURRENT_FILENAME file."
|
||||
git add "$DESTINATION_FILENAME"
|
||||
git commit -m "Duplicate ${CURRENT_FILENAME} history in ${DESTINATION_FILENAME} history." -n
|
||||
fi
|
||||
|
|
|
|||
Loading…
Reference in a new issue