public
Description: Bridge for Git and Clearcase
Homepage:
Clone URL: git://github.com/charleso/git-cc.git
charleso (author)
Wed Jun 17 01:57:17 -0700 2009
commit  1c45190246fd7b951573fb1db963a00c3d4476ff
tree    35f74bf5cdda72154ab65ce292aac109043375b1
parent  39dee86e9c912a24cd899202a29495147f99565c
git-cc / tests / test-checkin.py
100644 140 lines (132 sloc) 4.808 kb
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
from __init__ import *
import checkin, common
import unittest, os
from os.path import join
from common import CC_DIR, CI_TAG
 
class CheckinTest(TestCaseEx):
    def setUp(self):
        TestCaseEx.setUp(self)
        self.expectedExec.append((['cleartool', 'update', '.'], ''))
        self.commits = []
    def checkin(self):
        self.expectedExec.insert(1,
            (['git', 'log', '--first-parent', '--reverse', '--pretty=format:%H%n%s%n%b', '%s..' % CI_TAG], '\n'.join(self.commits)),
        )
        checkin.main()
        self.assert_(not len(self.expectedExec))
    def commit(self, commit, message, files):
        nameStatus = []
        for type, file in files:
            nameStatus.append('%s\0%s' % (type, file))
        self.expectedExec.extend([
            (['git', 'diff', '--name-status', '-M', '-z', '%s^..%s' % (commit, commit)], '\n'.join(nameStatus)),
        ])
        types = {'M': MockModfy, 'A': MockAdd, 'D': MockDelete, 'R': MockRename}
        self.expectedExec.extend([
            (['git', 'merge-base', CI_TAG, 'HEAD'], 'abcdef'),
        ])
        for type, file in files:
            types[type](self.expectedExec, commit, message, file)
        self.expectedExec.extend([
            (['git', 'tag', '-f', CI_TAG, commit], ''),
        ])
        self.commits.extend([commit, message, ''])
    def testEmpty(self):
        self.checkin()
    def testSimple(self):
        self.commit('sha1', 'commit1', [('M', 'a.py')])
        self.commit('sha2', 'commit2', [('M', 'b.py')])
        self.commit('sha3', 'commit3', [('A', 'c.py')])
        self.checkin();
    def testFolderAdd(self):
        self.commit('sha4', 'commit4', [('A', 'a/b/c/d.py')])
        self.checkin();
    def testDelete(self):
        os.mkdir(join(CC_DIR, 'd'))
        self.commit('sha4', 'commit4', [('D', 'd/e.py')])
        self.checkin();
    def testRename(self):
        os.mkdir(join(CC_DIR, 'a'))
        self.commit('sha1', 'commit1', [('R', 'a/b.py\0c/d.py')])
        self.checkin();
 
class MockStatus:
    def lsTree(self, id, file, hash):
        return (['git', 'ls-tree', '-z', id, file], '100644 blob %s %s' % (hash, file))
    def catFile(self, file, hash):
        blob = "blob"
        return [
            (['git', 'cat-file', 'blob', hash], blob),
            (join(CC_DIR, file), blob),
        ]
    def hash(self, file):
        hash1 = 'hash1'
        return [
            (['git', 'hash-object', join(CC_DIR, file)], hash1 + '\n'),
            self.lsTree('abcdef', file, hash1),
        ]
    def co(self, file):
        return (['cleartool', 'co', '-reserved', '-nc', file], '')
    def ci(self, message, file):
        return (['cleartool', 'ci', '-identical', '-c', message, file], '')
    def mkelem(self, file):
        return (['cleartool', 'mkelem', '-nc', '-eltype', 'directory', file], '')
    def dir(self, file):
        return file[0:file.rfind('/')];
 
class MockModfy(MockStatus):
    def __init__(self, e, commit, message, file):
        hash2 = "hash2"
        e.append(self.co(file))
        e.extend(self.hash(file))
        e.append(self.lsTree(commit, file, hash2))
        e.extend(self.catFile(file, hash2))
        e.append(self.ci(message, file))
 
class MockAdd(MockStatus):
    def __init__(self, e, commit, message, file):
        hash = 'hash'
        files = []
        files.append(".")
        e.append(self.co("."))
        path = ""
        for f in file.split('/')[0:-1]:
            path = path + f + '/'
            f = path[0:-1]
            files.append(f)
            e.append(self.mkelem(f))
        e.append(self.lsTree(commit, file, hash))
        e.extend(self.catFile(file, hash))
        e.append((['cleartool', 'mkelem', '-nc', file], '.'))
        for f in files:
            e.append(self.ci(message, f))
        e.append(self.ci(message, file))
 
class MockDelete(MockStatus):
    def __init__(self, e, commit, message, file):
        dir = file[0:file.rfind('/')]
        e.extend([
            self.co(dir),
            (['cleartool', 'rm', file], ''),
            self.ci(message, dir),
        ])
 
class MockRename(MockStatus):
    def __init__(self, e, commit, message, file):
        a, b = file.split('\0')
        hash = 'hash'
        e.extend([
            self.co(self.dir(a)),
            self.co(a),
        ])
        e.extend(self.hash(a))
        e.extend([
            self.co("."),
            self.mkelem(self.dir(b)),
            (['cleartool', 'mv', '-nc', a, b], '.'),
            self.lsTree(commit, b, hash),
        ])
        e.extend(self.catFile(b, hash))
        e.extend([
            self.ci(message, self.dir(a)),
            self.ci(message, "."),
            self.ci(message, self.dir(b)),
            self.ci(message, b),
        ])
 
if __name__ == "__main__":
    unittest.main()