Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1from textwrap import dedent 

2from typing import TYPE_CHECKING, List, Tuple, Union 

3 

4import git 

5from errors.common.exception import DppError 

6 

7if TYPE_CHECKING: 

8 from taxonomy.taxonomy import Defect, MetaData 

9 

10 

11class DppGitError(DppError): 

12 pass 

13 

14 

15class DppGitCloneError(DppGitError): 

16 def __init__( 

17 self, 

18 metadata: "MetaData", 

19 path: str, 

20 command: Union[List[str], Tuple[str, ...], str], 

21 status: Union[str, int, None, Exception], 

22 stdout: Union[bytes, str, None], 

23 ): 

24 self.metadata = metadata 

25 self.path = path 

26 self.command = command 

27 self.status = status 

28 self.stdout = stdout 

29 super().__init__( 

30 dedent( 

31 """git-clone failed. 

32 Command: {} 

33 Status: {} 

34 Path: {} 

35 Metadata: {} 

36 """.format( 

37 " ".join(self.command), 

38 self.status, 

39 self.print_path(self.path), 

40 self.metadata.name, 

41 ) 

42 ) 

43 ) 

44 

45 

46class DppGitWorktreeError(DppGitError): 

47 def __init__(self, repo: git.Repo, path: str, defect: "Defect"): 

48 self.repo = repo 

49 self.path = path 

50 self.defect = defect 

51 super().__init__( 

52 dedent( 

53 """git-worktree failed. 

54 Path: {} 

55 Defect: {} 

56 """.format( 

57 self.print_path(self.path), self.defect 

58 ) 

59 ) 

60 ) 

61 

62 

63class DppGitCheckoutInvalidRepositoryError(DppGitError): 

64 def __init__(self, repo: git.Repo, path: str, defect: "Defect"): 

65 self.repo = repo 

66 self.path = path 

67 self.defect = defect 

68 super().__init__( 

69 dedent( 

70 """git-checkout failed (not a git repository). 

71 Path: {} 

72 Defect: {} 

73 """.format( 

74 self.print_path(self.path), self.defect 

75 ) 

76 ) 

77 ) 

78 

79 

80class DppGitCheckoutError(DppGitError): 

81 def __init__(self, repo: git.Repo, path: str, defect: "Defect"): 

82 self.repo = repo 

83 self.path = path 

84 self.defect = defect 

85 super().__init__( 

86 dedent( 

87 """git-checkout failed. 

88 Path: {} 

89 Defect: {} 

90 """.format( 

91 self.print_path(self.path), self.defect 

92 ) 

93 ) 

94 ) 

95 

96 

97class DppGitSubmoduleInitError(DppGitError): 

98 def __init__( 

99 self, 

100 repo: git.Repo, 

101 command: Union[List[str], Tuple[str, ...], str], 

102 status: Union[str, int, None, Exception], 

103 stdout: Union[bytes, str, None], 

104 ): 

105 self.repo = repo 

106 self.command = command 

107 self.status = status 

108 self.stdout = stdout 

109 super().__init__( 

110 dedent( 

111 """git-submodule failed. 

112 Command: {} 

113 Status: {} 

114 Output: {} 

115 """.format( 

116 " ".join(self.command), self.status, self.stdout 

117 ) 

118 ) 

119 ) 

120 

121 

122class DppGitApplyPatchError(DppGitError): 

123 def __init__( 

124 self, 

125 repo: git.Repo, 

126 patch: str, 

127 command: Union[List[str], Tuple[str, ...], str], 

128 status: Union[str, int, None, Exception], 

129 stdout: Union[bytes, str, None], 

130 ): 

131 self.repo = repo 

132 self.patch = patch 

133 self.command = command 

134 self.status = status 

135 self.stdout = stdout 

136 super().__init__( 

137 dedent( 

138 """git-am failed. 

139 Patch: {} 

140 Command: {} 

141 Status: {} 

142 Output: {} 

143 """.format( 

144 self.print_path(self.patch), 

145 " ".join(self.command), 

146 self.status, 

147 self.stdout, 

148 ) 

149 ) 

150 ) 

151 

152 

153class DppGitPatchNotAppliedError(DppGitError): 

154 def __init__(self, repo: git.Repo, patch: str): 

155 self.repo = repo 

156 self.patch = patch 

157 super().__init__( 

158 dedent( 

159 """git-am failed. 

160 Patch: {} 

161 """.format( 

162 self.print_path(self.patch) 

163 ) 

164 ) 

165 )