7 output
= fd
.readlines()
9 return [x
.strip() for x
in output
]
12 rc
= os
.system("%s > /dev/null 2>&1" % cmd
)
16 class YapError(Exception):
17 def __init__(self
, msg
):
23 def takes_options(options
):
25 func
.options
= options
30 def cmd_clone(self
, url
, directory
=""):
31 # XXX: implement in terms of init + remote add + fetch
32 os
.system("git clone '%s' %s" % (url
, directory
))
37 def cmd_add(self
, file):
38 if not os
.access(file, os
.R_OK
):
39 raise YapError("No such file: %s" % file)
40 x
= get_output("git ls-files '%s'" % file)
42 raise YapError("File '%s' already in repository" % file)
43 os
.system("git update-index --add '%s'" % file)
46 def cmd_stage(self
, file):
47 if not os
.access(file, os
.R_OK
):
48 raise YapError("No such file: %s" % file)
49 os
.system("git update-index --add '%s'" % file)
52 def cmd_unstage(self
, file):
53 if not os
.access(file, os
.R_OK
):
54 raise YapError("No such file: %s" % file)
55 if run_command("git rev-parse HEAD"):
56 os
.system("git update-index --force-remove '%s'" % file)
58 os
.system("git diff-index HEAD '%s' | git apply -R --cached" % file)
62 branch
= get_output("git symbolic-ref HEAD")[0]
63 branch
= branch
.replace('refs/heads/', '')
64 print "Current branch: %s" % branch
66 print "Files with staged changes:"
68 if run_command("git rev-parse HEAD"):
69 files
= get_output("git ls-files --cached")
71 files
= get_output("git diff-index --name-only HEAD")
77 print "Files with unstages changes:"
78 files
= get_output("git ls-files -m")
84 def cmd_version(self
):
85 print "Yap version 0.1"
88 print >> sys
.stderr
, "usage: %s <command>" % sys
.argv
[0]
89 print >> sys
.stderr
, " valid commands: version"
99 debug
= os
.getenv('YAP_DEBUG')
102 meth
= self
.__getattribute
__("cmd_"+command
)
104 if "option" in meth
.__dict
__:
105 flags
, args
= getopt
.getopt(args
, meth
.options
)
111 except (TypeError, getopt
.GetoptError
):
114 print "%s %s %s" % (sys
.argv
[0], command
, meth
.__doc
__)
116 print >> sys
.stderr
, e
118 except AttributeError: