Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 47 lines (33 sloc) 1.627 kb
c5221607 »
2012-03-20 point
1 #!/usr/bin/env python
2
3 import os
4
5 from fabric.api import local
6 from fabric.context_managers import lcd
7 from fabric.utils import abort
8
9 import mirror
10
11 def setup():
12 """Initial setup. Run once after cloning."""
13 local("git clone git@github.com:josharian/xkcdmirror.git data")
14 with lcd("data"):
15 local("git checkout -t origin/data")
16
17
18 def _is_clean_repo(repo_dir):
19 """Check whether a particular git repo has any uncommitted modifications."""
20 # this conflates return_code of 1 (has modifications) with other return_codes
21 # (error occurred), but for our purposes, that's ok -- we just want confidence
22 # that everything is kosher
23
24 check_commands = ("git diff-index --quiet --cached HEAD", # check for changes in the index
25 "git diff-files --quiet", # check for changes in the working dir
26 )
27
28 modified = any(bool(local(check_command).return_code) for check_command in check_commands)
29
30 untracked_files = local("git ls-files --others", capture=True) # check for untracked (new) files
31 has_untracked = bool(untracked_files.strip())
32
33 return not modified and not has_untracked
34
35
36 def update(mirror_dir="data"):
1163019c »
2012-03-20 more goo
37 # update ourselves to origin/data first
38 # with lcd(mirror_dir):
39 # if not _is_clean_repo(mirror_dir):
40 # abort("Git repo in {d} must be clean before updating (no untracked files, no uncommitted changes).".format(d=mirror_dir))
41 # local("git fetch")
42 # local("git checkout -f data")
43 # local("git clean -f")
44 # local("git reset --hard origin/data")
45
c5221607 »
2012-03-20 point
46 mirror.update(mirror_dir)
Something went wrong with that request. Please try again.