src/eric7/Plugins/VcsPlugins/vcsGit/git.py

branch
eric7
changeset 10491
acabc60b19a2
parent 10489
1800956305ca
child 10621
f5631f40c4d9
equal deleted inserted replaced
10490:527d47826e97 10491:acabc60b19a2
21 from eric7.EricWidgets import EricFileDialog, EricMessageBox 21 from eric7.EricWidgets import EricFileDialog, EricMessageBox
22 from eric7.EricWidgets.EricApplication import ericApp 22 from eric7.EricWidgets.EricApplication import ericApp
23 from eric7.QScintilla.MiniEditor import MiniEditor 23 from eric7.QScintilla.MiniEditor import MiniEditor
24 from eric7.SystemUtilities import FileSystemUtilities, PythonUtilities 24 from eric7.SystemUtilities import FileSystemUtilities, PythonUtilities
25 from eric7.VCS.RepositoryInfoDialog import VcsRepositoryInfoDialog 25 from eric7.VCS.RepositoryInfoDialog import VcsRepositoryInfoDialog
26 from eric7.VCS.VersionControl import VersionControl 26 from eric7.VCS.VersionControl import VersionControl, VersionControlState
27 27
28 from .GitDialog import GitDialog 28 from .GitDialog import GitDialog
29 29
30 30
31 class Git(VersionControl): 31 class Git(VersionControl):
1066 """ 1066 """
1067 Public method used to get the registered state of a file in the vcs. 1067 Public method used to get the registered state of a file in the vcs.
1068 1068
1069 @param name filename to check 1069 @param name filename to check
1070 @type str 1070 @type str
1071 @return registered state (one of canBeCommited and canBeAdded) 1071 @return registered state
1072 @rtype int 1072 @rtype VersionControlState
1073 """ 1073 """
1074 if name.endswith(os.sep): 1074 if name.endswith(os.sep):
1075 name = name[:-1] 1075 name = name[:-1]
1076 name = os.path.normcase(name) 1076 name = os.path.normcase(name)
1077 dname, fname = self.splitPath(name) 1077 dname, fname = self.splitPath(name)
1078 1078
1079 if fname == "." and os.path.exists(os.path.join(dname, self.adminDirOrFile)): 1079 if fname == "." and os.path.exists(os.path.join(dname, self.adminDirOrFile)):
1080 return self.canBeCommitted 1080 return VersionControlState.Controlled
1081 1081
1082 if name in self.statusCache: 1082 if name in self.statusCache:
1083 return self.statusCache[name] 1083 return self.statusCache[name]
1084 1084
1085 # find the root of the repo 1085 # find the root of the repo
1111 if absname.endswith(("/", "\\")): 1111 if absname.endswith(("/", "\\")):
1112 absname = absname[:-1] 1112 absname = absname[:-1]
1113 if flag not in "?!": 1113 if flag not in "?!":
1114 if fname == ".": 1114 if fname == ".":
1115 if absname.startswith(dname + os.path.sep): 1115 if absname.startswith(dname + os.path.sep):
1116 return self.canBeCommitted 1116 return VersionControlState.Controlled
1117 if absname == dname: 1117 if absname == dname:
1118 return self.canBeCommitted 1118 return VersionControlState.Controlled
1119 else: 1119 else:
1120 if absname == name: 1120 if absname == name:
1121 return self.canBeCommitted 1121 return VersionControlState.Controlled
1122 else: 1122 else:
1123 return self.canBeCommitted 1123 return VersionControlState.Controlled
1124 1124
1125 return self.canBeAdded 1125 return VersionControlState.Uncontrolled
1126 1126
1127 def vcsAllRegisteredStates(self, names, dname, shortcut=True): # noqa: U100 1127 def vcsAllRegisteredStates(self, names, dname, shortcut=True): # noqa: U100
1128 """ 1128 """
1129 Public method used to get the registered states of a number of files 1129 Public method used to get the registered states of a number of files
1130 in the vcs. 1130 in the vcs.
1137 @type dict 1137 @type dict
1138 @param dname directory to check in 1138 @param dname directory to check in
1139 @type str 1139 @type str
1140 @param shortcut flag indicating a shortcut should be taken 1140 @param shortcut flag indicating a shortcut should be taken
1141 @type bool 1141 @type bool
1142 @return the received dictionary completed with a combination of 1142 @return the received dictionary completed with the VCS state or None in
1143 canBeCommited and canBeAdded or None in order to signal an error 1143 order to signal an error
1144 @rtype dict 1144 @rtype dict
1145 """ 1145 """
1146 if dname.endswith(os.sep): 1146 if dname.endswith(os.sep):
1147 dname = dname[:-1] 1147 dname = dname[:-1]
1148 dname = os.path.normcase(dname) 1148 dname = os.path.normcase(dname)
1149 1149
1150 # revert the logic because git status doesn't show unchanged files 1150 # revert the logic because git status doesn't show unchanged files
1151 for name in names: 1151 for name in names:
1152 names[name] = self.canBeCommitted 1152 names[name] = VersionControlState.Controlled
1153 1153
1154 found = False 1154 found = False
1155 for name in self.statusCache: 1155 for name in self.statusCache:
1156 if name in names: 1156 if name in names:
1157 found = True 1157 found = True
1187 if name.startswith(dname) and flag in "?!": 1187 if name.startswith(dname) and flag in "?!":
1188 isDir = name.endswith(("/", "\\")) 1188 isDir = name.endswith(("/", "\\"))
1189 if isDir: 1189 if isDir:
1190 name = name[:-1] 1190 name = name[:-1]
1191 if name in names: 1191 if name in names:
1192 names[name] = self.canBeAdded 1192 names[name] = VersionControlState.Uncontrolled
1193 if isDir: 1193 if isDir:
1194 # it's a directory 1194 # it's a directory
1195 for nname in names: 1195 for nname in names:
1196 if nname.startswith(name): 1196 if nname.startswith(name):
1197 names[nname] = self.canBeAdded 1197 names[nname] = VersionControlState.Uncontrolled
1198 if flag not in "?!": 1198 if flag not in "?!":
1199 self.statusCache[name] = self.canBeCommitted 1199 self.statusCache[name] = VersionControlState.Controlled
1200 self.statusCache[dirName] = self.canBeCommitted 1200 self.statusCache[dirName] = VersionControlState.Controlled
1201 else: 1201 else:
1202 self.statusCache[name] = self.canBeAdded 1202 self.statusCache[name] = VersionControlState.Uncontrolled
1203 if dirName not in self.statusCache: 1203 if dirName not in self.statusCache:
1204 self.statusCache[dirName] = self.canBeAdded 1204 self.statusCache[
1205 dirName
1206 ] = VersionControlState.Uncontrolled
1205 1207
1206 return names 1208 return names
1207 1209
1208 def clearStatusCache(self): 1210 def clearStatusCache(self):
1209 """ 1211 """

eric ide

mercurial