@@ -37,7 +37,7 @@ __git_funcs() {
3737 local stash_name
3838 stash_name=" $( cat /dev/urandom | base32 | tr -dc ' A-Z0-9' | head -c 16) "
3939 git stash push --message " ${stash_name} " || return 1
40- if git branch --list main > /dev/null ; then
40+ if [[ $( git branch --list main) ]] ; then
4141 git fetch origin main:main
4242 git rebase origin/main
4343 else
@@ -60,10 +60,35 @@ __git_funcs() {
6060 fi
6161 }
6262
63+ # Copy changes from one clone to another
64+ # @param {string} $1 The original/old git root
65+ # @param {string} $2 The new git root
66+ gcopy () {
67+ git -C " $1 " status --porcelain=v1 | while read -r state file; do
68+ if [[ " ${state} " == * D* ]]; then
69+ # Copy deletions
70+ echo -e " \033[91mX\033[0m ${file} "
71+ rm -rf " ${2:? } /${file} "
72+ elif [[ " ${state} " == * R* ]]; then
73+ # Copy renames
74+ before=" ${file% -> * } "
75+ after=" ${file#* -> } "
76+ echo -e " \033[95m>\033[0m ${before} -> ${after} "
77+ git -C " $2 " mv --force " ${before} " " ${after} "
78+ cp " $1 /${after} " " $2 /${after} "
79+ else
80+ # Copy modifications
81+ echo -e " \033[92m*\033[0m ${file} "
82+ mkdir -p " $2 /$( dirname " ${file} " ) "
83+ cp " $1 /${file} " " $2 /${file} "
84+ fi
85+ done
86+ }
87+
6388 gupdate () {
6489 git pull > /dev/null
6590
66- if git branch --list main > /dev/null ; then
91+ if [[ $( git branch --list main) ]] ; then
6792 git fetch origin main:main
6893 git merge --no-edit origin/main
6994 else
0 commit comments