emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Richard Lawrence <richard.lawrence@berkeley.edu>
To: emacs-orgmode@gnu.org
Cc: Xebar Saram <zeltakc@gmail.com>
Subject: Re: Advice needed: Cant find a decent way to autosync my work TODO org file between laptop and work pc
Date: Sat, 24 May 2014 09:49:41 -0700	[thread overview]
Message-ID: <87ha4fktp6.fsf@berkeley.edu> (raw)
In-Reply-To: CAOQHXPoxvoFd4VcFXdARZnhYH4eELca+S-m8bj9eCRz=8vG68g@mail.gmail.com

Hi Xebar,

Xebar Saram <zeltakc@gmail.com> writes:

> i mainly used git over the last 6 months but that forces me to
> pull/commit/push manually each time i add something to either machine and
> that is really annoying. plus i get merge conflicts all the time
>
> I have tried dropbox at the past but again this causes conflicts,
> isntreliable to me (on my
> linux laptop it doesn't always resume sync after sleep)

If neither git nor Dropbox works for you, I'm not sure this will be
helpful, but...

I personally use git for this.  To keep the effort of syncing and
merging low, I have a cron job set up to automatically commit in certain
repositories containing my Org files every hour.  It's just a
quick-and-dirty hack, but here it is:

#+BEGIN_SRC bash
#!/bin/bash
# Add org file changes to the repository
ROOT=$HOME
REPOS="org Documents/philosophy/dissertation Documents/philosophy/teaching Documents/philosophy/reading src/emacs"

commit_and_push()
{
  for REPO in $REPOS
  do
      echo "Repository: $ROOT/$REPO"
      cd $ROOT/$REPO

      if [ ! -d .git ]; then
	  echo "Not a git repository; skipping"
	  continue
      fi
      if [ ! -r autocommits ]; then
	  echo "No autocommits file found; skipping"
	  continue
      fi

      # Remove deleted files
      git ls-files --deleted -z | xargs -0 git rm >/dev/null 2>&1

      # Add files on whitelist to commit for current branch
      while read FILE
      do
	  git add $FILE
      done < autocommits

      git commit -m "$(date) from $(hostname) by autocommit.sh"
      STATUS=$?
      if [ $STATUS != 0 ]; then
	  echo "git commit failed with exit status $STATUS"
      fi

      # Push the current branch
      # requires branch.<name>.remote to be specified in git config
      # and ideally push.default = tracking 
      git push --porcelain
      STATUS=$?
      if [ $STATUS != 0 ]; then
	  echo "git push failed with exit status $STATUS"
      fi

  done
}

pull()
{
  for REPO in $REPOS
  do
      echo "Repository: $REPO"
      cd $ROOT/$REPO

      git status | grep 'modified:'
      if [ $? == 0 ]; then
	  echo "modified files present; fetching, but not pulling."
	  CMD="fetch"
      else
	  CMD="pull"
      fi

      git $CMD
      STATUS=$?
      if [ $STATUS != 0 ]; then
	  echo "git $CMD failed with exit status $STATUS"
      fi
  done
}

case "$1" in
  commit)
      commit_and_push
      ;;
  pull)
      pull
      ;;
  *)
      echo "Usage: $0 {commit|pull}"
      exit 1
      ;;
esac

exit 0
#+END_SRC

This script requires a file called "autocommits" in each repository in
$REPOS which is a whitelist of files to autocommit changes in.  Most of
my Org files are on such a list.

I run this from Cron like:
#+BEGIN_SRC cron
0 * * * * ~/bin/autocommits.sh commit >/dev/null 2>&1 
#+END_SRC

To make sure my changes are saved before this script runs, I have in my .emacs:
#+BEGIN_SRC elisp
(run-at-time "00:59" 3600 'org-save-all-org-buffers) ; cron commits on the hour
(add-hook 'before-save-hook 'org-update-all-dblocks)
#+END_SRC

And finally, to pull the autocommitted changes on a new machine:
$ autocommits.sh pull

So you still have to manually pull and fix any merge conflicts, but I
find that committing often generally keeps the work involved here
minimal (because I can't usually work on two machines at once!).

Hope that helps!

Best,
Richard

  reply	other threads:[~2014-05-24 16:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-24  5:11 Advice needed: Cant find a decent way to autosync my work TODO org file between laptop and work pc Xebar Saram
2014-05-24 16:49 ` Richard Lawrence [this message]
     [not found]   ` <CAHxk2pAX=dM_iAJEpTUaeYjPKVm8wELYBgkHZd=cPK__KPmDBw@mail.gmail.com>
2014-05-24 21:51     ` Richard Lawrence
2014-05-24 22:30       ` Melleus
2014-05-26  7:42         ` Samuel Loury
2014-05-24 22:54 ` Ken Mankoff
     [not found]   ` <CAHxk2pAR-8jAdtS1BdxxsCtfHo--km2HDhaWVQmA8RfcB+kKJQ@mail.gmail.com>
2014-05-25 12:44     ` Fwd: " Martin Schöön
2014-05-25 12:13 ` Josh Berry
2014-05-26 18:08 ` Thierry Banel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ha4fktp6.fsf@berkeley.edu \
    --to=richard.lawrence@berkeley.edu \
    --cc=emacs-orgmode@gnu.org \
    --cc=zeltakc@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).