Skip to content

Instantly share code, notes, and snippets.

@JoeyBurzynski
Forked from rafaelrinaldi/watch.sh
Created March 3, 2016 23:52
Show Gist options
  • Save JoeyBurzynski/2da2c2a4f470d933df93 to your computer and use it in GitHub Desktop.
Save JoeyBurzynski/2da2c2a4f470d933df93 to your computer and use it in GitHub Desktop.
Using bash and Dropbox to solve a problem with Git merge.

Using bash and Dropbox to solve a problem with Git merge.

The problem

In a small project I'm currently developing, we have this assets.fla file which was previously hosted under our Git repository. Due to bizarre problems with Git's merge tool and .fla file type (we were losing library symbols, for some reason), we decided to move assets.fla from our Git repository to the project's folder on Dropbox.
That was a smart move, problems with merge were gone and others could know everytime a update is made. But with the time (one day of working, lol) it was getting kind of annoying. Everytime I wanted to update some asset (generate the .swc file), I needed to edit the export path. There are three of us working on this file, and everybody needed to repeat the same thing every time a change was needed.

bash FTW

So, since I have a problem, where can be the solution? bash for sure!
Then I wrote a script to automatize this process and it now fits quite well on the project workflow.

To get things working, you need to configure a dotfile on the home folder, pointing to the local Git repository:

echo "/Users/[your_user_name]/[foo_project_path]" > ~/.foo-path

After that, you only need to execute a script which is located in the root of our Dropbox project folder. I'm calling it watch.

sh watch

Now all the guys working on this file don't need to worry about changing its export path everytime they want to make a change. Just leave the script running in background, do what you have to do, compile the file and commit the changes.

t3h c0deZ

I wanted to share this because it saved us some time and avoided a few problems.

The script basic stays running forever, looking for a hash change on the compiled file. As soon the file is changed, it moves the file from our Dropbox folder to the local Git repository.

I even created a JSFL kinda wizard to help somebody from the team who doesn't have familiarity with CLI. A one-click solution. Not the case to share it though, just mentioning it.

Check the script below and happy coding.

#!/bin/bash
# watch
#
# This script keeps watching the assets/fla folder on Dropbox.
# As soon as the .swc file is updated, it is moved to the Git repository.
#
# Author: Rafael Rinaldi (rafaelrinaldi.com)
# Since: Feb 23, 2013.
if [ ! -f ~/.foo-path ]; then
echo "You must setup your '.foo-path'!"
exit;
fi
# Git project path.
project_path=`cat ~/.foo-path`
echo "[watch] Watching '$project_path'"
# Script path (which is the root of the project on Dropbox).
script_path=`pwd`
# Path with the .swc file on Dropbox.
db_swc_path="$script_path/assets/fla"
# Path with all .swc files on the Git repository.
git_swc_path="$project_path/swc"
# SWC file.
swc_file="$db_swc_path/assets.swc"
# SWC hash.
swc_hash=""
# Move .swc file from Dropbox folder to Git local repository.
dropbox2git() {
echo "[watch] Moving '$swc_file' to Git local repository"
mv "$swc_file" "$git_swc_path"
}
while true; do
# Executes every 5 seconds.
sleep 5
if [ -f "$swc_file" ]; then
new_swc_hash=new_swc_hash=`md5 $swc_file`
if [ "$swc_hash" != "$new_swc_hash" ]; then
swc_hash=$new_swc_hash
dropbox2git
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment