-
-
Save quickshiftin/8809435 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash | |
# author: Thomas Aylott SubtleGradient.com | |
# author: Nathan Nobbe quickshiftin.com | |
# Find out where HEAD is pointing | |
head_ref=$(git show-ref --head -s | head -n 1) | |
# Check to see if transmit tag exists, and get transmit tag hash | |
_transmit_ref=$(git show-ref --verify -s refs/tags/transmit) | |
# If there's not transmit tag, create it for the first time. | |
if [ $? -gt 0 ]; then | |
# This won't work well for projects with multiple roots, | |
# but for the typical case it will find the first commit | |
# and tag that for the initial push. | |
first_commit=$(git rev-list --max-parents=0 HEAD) | |
echo 'Creating initial transmit tag' | |
git tag -m 'Creating transmit tag' transmit $first_commit | |
fi | |
# Find out where the tag is pointing | |
# @note Probably a cleaner way to do this ... | |
transmit_ref=$(git cat-file tag $_transmit_ref | head -n 1 | sed 's/^object //') | |
# If the transmit tag is the same commit as HEAD, | |
# there's nothing to do | |
if [ "$transmit_ref" == "$head_ref" ]; then | |
echo 'No changes to push' | |
exit 0 | |
fi | |
# Iterate over all the files that changed, adding then to Transmit | |
echo 'Transmitting' | |
for i in $(git diff --name-only transmit HEAD); do | |
if [[ -e "$i" ]]; then | |
echo "Adding $i to Transmit" | |
open -a Transmit "$i" | |
fi | |
done | |
# Update the tag so we know where the last push occurred | |
echo 'Updating transmit tag' | |
git tag -d transmit | |
git tag -m 'Updating transmit tag' transmit HEAD |
How do I install this script?
@adaptifyDesigns if you have configured DockSend then it should just work when you run the script. The key is this line in the if loop:
open -a Transmit "$i"
That will pass the current file from the loop to Transmit, at which point DockSend will kick in, since it's coming from a known local path, and pass it on to the associated remote path.
As for Git, there are a lot of resources like http://git-scm.com/book
In a nutshell, Git version controls your code locally, and BitBucket (like GitHub) is a remote repository for it: basically a remote place that holds a copy of your local repository. You would run this script from your local copy, not from BitBucket
@adaptifyDesigns @saerts to install this script just copy the contents down to a file (ideally somewhere in your PATH env variable). In this example we'll call it "git-transmit". Make sure you are in the same directory that the code file that you pulled down is, then use the command:
chmod +x git-transmit
This will make the script executable.
Then simply run the script from the directory you set up in the DockSend.
I did run into a problem on OS X Mavericks, where the Gatekeeper protection kicked in for files that didn't have an extension (like htaccess and LICENSE files). You may need to keep an eye on the app during the initial push to press ok a couple dozen times.
Hi guys, for the motivation to this gist, please see this StackOverflow thread. Essentially, these are the commands you need to follow to install the script:
- save the script to your desktop as git-transmit (with no extension)
- cp git-transit /usr/sbin/
- cd /usr/sbin
- chmod a+x git-transmit
- Setup drop send for your live app
- Run git-transmit in your git repository.
Can I in someway specify a commit for upload? Usually have to a site already up and running and I would rather not upload it again, only my minor changes.
@jannejava That's the whole idea behind this script. It will only push what has changed since the last time you pushed.
On OSX 10.11.2 this is what I get, trying to copy the file to /usr/sbin/ (btw: there's a typo in your cp line @quickshiftin)
sudo cp git-transmit /usr/sbin/
cp: /usr/sbin/git-transmit: Operation not permitted
Hi @reibejoy. It looks like need to use sudo
.
Same problem as @reibejoy, solved using /usr/local/sbin/
instead.
forgive my inexperience, but how would I implement this script?
I'm using BitBucket to track file changes, and transmit to upload them. I've configured DocSend so that I can drag-n-drop files onto the dock icon to upload.
If I understand this Gist correctly, it is for automating the uploading of only the changed files, right?
Since I'm using a Git client (BitBucket) to contribute to the repo, and I don't really understand how Git works fundamentally, is there a way to implement this Gist with BitBucket?
this is new territory for me, thanks for any help or explanation.