-
Notifications
You must be signed in to change notification settings - Fork 752
Dropbox, Google Drive, Onedrive, etc. as a CVS T^T
Sometimes you might have to collaborate with people still convinced that sharing a folder in a cloud storage and changing the name of the files once in a while is a perfectly acceptable CVS, except that they have no idea of what CVS means. (This happens more often than you think in certain academic circles.)
Here is a clobbered up script to ease the pain of dealing with such situations.
It uses rclone and execline but the latter could be replaced with any other
scripting language. The example is for Dropbox but the same principle can be
applied to any other remote supported by rclone.
-
setup the
rcloneremote (below it is referred to as__REMOTE_NAME__) -
make a folder in your repo to store a copy of the remote folder you want to access (below it is referred to as
__LOCAL_DIR__) -
add the following alias to your repo config adapting it to your setup :
[aliases]
dropbox = ["util", "exec", "--", "execlineb", "-s", "1", "-c", """
backtick -E root { jj root }
define remote __REMOTE_NAME__
define remote_dir __REMOTE_DIR__
define local_dir __LOCAL_DIR__
# optionally make local backups of remote files
#define local_backup ${local_dir}_backup
backtick -E when { date +%Y-%m-%dT%H-%M-%S }
execline-cd ${root}
case $1 {
pull {
backtick -E current_change { jj log --no-graph -r @ -T "self.change_id()" }
foreground { jj bookmark create ${current_change} -r@ }
foreground { jj new dropbox }
foreground { jj bookmark move dropbox --to=@ }
foreground { jj desc -m "Pull from dropbox ${when}" }
foreground { rclone sync ${remote}:${remote_dir} ./${local_dir} }
# to make local backups of remote files comment the above line and uncomment the next one
#foreground { rclone sync ${remote}:${remote_dir} ./${local_dir} --backup-dir=./${local_backup} --suffix=-${when} }
foreground { forbacktickx -E map { cat file_map }
multidefine -d : ${map} { a b }
foreground { cp -p ${local_dir}/${a} ${b} }
}
foreground { jj new ${current_change} dropbox }
foreground { jj bookmark delete ${current_change} }
foreground { jj abandon -r "empty() & @-" --retain-bookmarks }
foreground { jj simplify-parents }
}
push {
foreground { forbacktickx -E map { cat file_map }
multidefine -d : ${map} { a b }
foreground { cp -p ${b} ${local_dir}/${a} }
}
foreground { rclone sync ./${local_dir} ${remote}:${remote_dir} }
foreground { jj bookmark move dropbox --to=@ }
foreground { jj new }
foreground { jj abandon -r "empty() & @-" --retain-bookmarks }
}
}
"""
]
- create a file called
file_mapcontaining one line for each file you want to synchronize of the form:
remote/path/relative/to/__REMOTE_DIR__:local/path/relative/to/root/of/repo
These can also be artifacts not tracked by jj (e.g. compiled version of *.tex files).
You should now be able to sync via jj dropbox pull and jj dropbox push.