Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/src/sage/dev/git_error.py
8815 views
1
r"""
2
Git errors
3
4
This module provides subclasses of ``RuntimeError`` to indicate error
5
conditions when calling git.
6
7
AUTHORS:
8
9
- Julian Rueth: initial version
10
11
"""
12
#*****************************************************************************
13
# Copyright (C) 2013 Julian Rueth <[email protected]>
14
#
15
# Distributed under the terms of the GNU General Public License (GPL)
16
# as published by the Free Software Foundation; either version 2 of
17
# the License, or (at your option) any later version.
18
# http://www.gnu.org/licenses/
19
#*****************************************************************************
20
class GitError(RuntimeError):
21
r"""
22
Error raised when git exits with a non-zero exit code.
23
24
EXAMPLES::
25
26
sage: from sage.dev.git_error import GitError
27
sage: raise GitError(128, "git foo", None, None)
28
Traceback (most recent call last):
29
...
30
GitError: git returned with non-zero exit code (128) for "git foo".
31
32
"""
33
def __init__(self, exit_code, cmd, stdout, stderr, explain=None, advice=None):
34
r"""
35
Initialization.
36
37
TESTS::
38
39
sage: from sage.dev.git_error import GitError
40
sage: type(GitError(128, "git foo", None, None))
41
<class 'sage.dev.git_error.GitError'>
42
"""
43
self.exit_code = exit_code
44
self.cmd = cmd
45
self.stdout = stdout
46
self.stderr = stderr
47
self.explain = explain
48
self.advice = advice
49
50
msg = ['git returned with non-zero exit code ({0}) for "{1}".'.format(exit_code, cmd)]
51
if stdout:
52
msg.append("output to stdout:" + "\n".join( " " + l for l in stdout.splitlines() ))
53
if stderr:
54
msg.append("output to stderr:" + "\n".join( " " + l for l in stderr.splitlines() ))
55
56
RuntimeError.__init__(self, "\n".join(msg))
57
58
class DetachedHeadError(RuntimeError):
59
r"""
60
Error raised when a git command can not be executed because the repository
61
is in a detached HEAD state.
62
63
EXAMPLES::
64
65
sage: from sage.dev.git_error import DetachedHeadError
66
sage: raise DetachedHeadError()
67
Traceback (most recent call last):
68
...
69
DetachedHeadError: unexpectedly, git is in a detached HEAD state
70
71
"""
72
def __init__(self):
73
r"""
74
Initialization.
75
76
TESTS::
77
78
sage: from sage.dev.git_error import DetachedHeadError
79
sage: type(DetachedHeadError())
80
<class 'sage.dev.git_error.DetachedHeadError'>
81
"""
82
RuntimeError.__init__(self, "unexpectedly, git is in a detached HEAD state")
83
84
class InvalidStateError(RuntimeError):
85
r"""
86
Error raised when a git command can not be executed because the repository
87
is not in a clean state.
88
89
EXAMPLES::
90
91
sage: from sage.dev.git_error import InvalidStateError
92
sage: raise InvalidStateError()
93
Traceback (most recent call last):
94
...
95
InvalidStateError: unexpectedly, git is in an unclean state
96
97
"""
98
def __init__(self):
99
r"""
100
Initialization.
101
102
TESTS::
103
104
sage: from sage.dev.git_error import InvalidStateError
105
sage: type(InvalidStateError())
106
<class 'sage.dev.git_error.InvalidStateError'>
107
"""
108
RuntimeError.__init__(self, "unexpectedly, git is in an unclean state")
109
110