]> arthur.barton.de Git - bup.git/commitdiff
Add 'bup init' command.
authorAvery Pennarun <apenwarr@gmail.com>
Sun, 3 Jan 2010 04:58:45 +0000 (23:58 -0500)
committerAvery Pennarun <apenwarr@gmail.com>
Sun, 3 Jan 2010 04:59:25 +0000 (23:59 -0500)
Basically an alias for git init, but uses BUP_DIR instead of GIT_DIR
environment variable.

.gitignore
Makefile
cmd-init.py [new file with mode: 0755]
git.py

index a2577fc5dc35060b15d665a7323508b016ae7200..092f3a08ad83ad1b0597afc957484dccbed0451c 100644 (file)
@@ -2,6 +2,7 @@ bup
 bup-split
 bup-join
 bup-save
+bup-init
 randomgen
 *.o
 *.so
index a61b0ece0edcd5b97eb1cf5f4777034d64cdb44a..802e32a7b2e7d8ad5cdab0e5122777eebcf72421 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ CFLAGS=-Wall -g -O2 -Werror -I/usr/include/python2.5 -g -fPIC
 
 default: all
 
-all: bup-split bup-join bup-save bup randomgen chashsplit.so
+all: bup-split bup-join bup-save bup-init bup randomgen chashsplit.so
 
 randomgen: randomgen.o
 
@@ -53,5 +53,5 @@ bup-%: cmd-%.sh
 
 clean:
        rm -f *.o *.so *~ .*~ *.pyc */*.pyc */*~ \
-               bup bup-split bup-join bup-save randomgen \
+               bup bup-split bup-join bup-save bup-init randomgen \
                out[12] out2[tc] tags[12] tags2[tc] *.tmp
diff --git a/cmd-init.py b/cmd-init.py
new file mode 100755 (executable)
index 0000000..651541a
--- /dev/null
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+import git, options
+from helpers import *
+
+optspec = """
+[BUP_DIR=...] bup init
+"""
+o = options.Options('bup init', optspec)
+(opt, flags, extra) = o.parse(sys.argv[1:])
+
+if extra:
+    log("bup init: no arguments expected\n")
+    o.usage()
+
+exit(git.init_repo())
+
diff --git a/git.py b/git.py
index 832620e6666fe52fbbfec0fb63078b72eac0db2d..825ef295a94b88b88bd9ec46a94da0bc5fc4fb19 100644 (file)
--- a/git.py
+++ b/git.py
@@ -248,3 +248,12 @@ def _update_ref(refname, newval, oldval):
                          preexec_fn = _gitenv)
     p.wait()
     return newval
+
+
+def init_repo():
+    d = repodir()
+    if os.path.exists(d) and not os.path.isdir(os.path.join(d, '.')):
+        raise Exception('"%d" exists but is not a directory\n' % d)
+    p = subprocess.Popen(['git', 'init', '--bare'],
+                         preexec_fn = _gitenv)
+    return p.wait()