forked from charleso/git-cc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstatus.py
69 lines (64 loc) · 1.95 KB
/
status.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from common import *
from os.path import join, dirname, islink
from os import readlink, listdir
class Status:
def __init__(self, files):
self.setFile(files[0])
def setFile(self, file):
self.file = file
def cat(self):
blob = git_exec(['cat-file', 'blob', getBlob(self.id, self.file)], decode=False)
write(join(CC_DIR, self.file), blob)
def stageDirs(self, t):
dir = dirname(self.file)
dirs = []
while not exists(join(CC_DIR, dir)):
dirs.append(dir)
dir = dirname(dir)
self.dirs = dirs
t.stageDir(dir)
def commitDirs(self, t):
while len(self.dirs) > 0:
dir = self.dirs.pop();
if not exists(join(CC_DIR, dir)):
cc_exec(['mkelem', '-nc', '-eltype', 'directory', dir])
t.add(dir)
class Modify(Status):
#TODO: modify symlinks?
def stage(self, t):
t.stage(self.file)
def commit(self, t):
self.cat()
class Add(Status):
def stage(self, t):
self.stageDirs(t)
def commit(self, t):
self.commitDirs(t)
## This works but should be uncommented once the symlink modify support is in place
# if islink(self.file):
# target = readlink(self.file)
# cc_exec(['ln', '-s', target, self.file])
# else:
self.cat()
cc_exec(['mkelem', '-nc', self.file])
t.add(self.file)
class Delete(Status):
def stage(self, t):
t.stageDir(dirname(self.file))
def commit(self, t):
cc_exec(['rm', self.file])
class Rename(Status):
def __init__(self, files):
self.old = files[0]
self.new = files[1]
self.setFile(self.new)
def stage(self, t):
t.stageDir(dirname(self.old))
t.stage(self.old)
self.stageDirs(t)
def commit(self, t):
self.commitDirs(t)
cc_exec(['mv', '-nc', self.old, self.new])
t.checkedout.remove(self.old)
t.add(self.new)
self.cat()