-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVersionControl.py
More file actions
69 lines (58 loc) · 2.17 KB
/
VersionControl.py
File metadata and controls
69 lines (58 loc) · 2.17 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
import sublime, os
from glob import glob
from .st3_CommandsBase.WindowCommand import stWindowCommand
# from .SvnRepository import SvnRepositoryCommand
from .GitRepository import GitRepositoryCommand
from .menu import Menu, menu
class VersionControlCommand(stWindowCommand, Menu):
def _DetermineVersionControlSystem(Self):
repositories = []
path = Self.window.active_view().file_name()
while True:
# if glob(path + "\\.svn") != []:
# repositories += [SvnRepositoryCommand(Self.window, path)]
# if glob(path + "\\.hg") != []:
# repositories += [SvnRepositoryCommand(Self.window, path)]
if glob(os.path.join(path, ".git")) != []:
git_rep = GitRepositoryCommand(Self.window)
git_rep.path = path
repositories += [git_rep]
newpath = os.path.dirname(path)
if newpath == path:
break
path = newpath
return repositories
def run(Self):
repositories = Self._DetermineVersionControlSystem()
if len(repositories) == 0:
Self.create_repository()(None, None)
return
if len(repositories) == 1:
repositories[0].run()
return
Self.SelectItem(
[v.Name() + ": " + v.path for v in repositories],
lambda index: repositories[index].run())
@menu()
def create_repository(self):
if not self.window.active_view().file_name():
return []
return [
(
'Create GIT repository...',
self.chooseRepositoryPath(GitRepositoryCommand)
),
]
@menu()
def chooseRepositoryPath(self, repository):
path = os.path.dirname(self.window.active_view().file_name())
paths = [path]
while path != os.path.dirname(path):
path = os.path.dirname(path)
paths.append(path)
return [
(
path,
repository(self.window).createRepository(path)
) for path in paths
]