Show More
@@ -38,39 +38,19 b' from rhodecode.lib.vcs.exceptions import' | |||||
38 | log = logging.getLogger(__name__) |
|
38 | log = logging.getLogger(__name__) | |
39 |
|
39 | |||
40 |
|
40 | |||
41 | def get_scm(path, search_path_up=False, explicit_alias=None): |
|
41 | def get_scm(path): | |
42 | """ |
|
42 | """ | |
43 | Returns one of alias from ``ALIASES`` (in order of precedence same as |
|
43 | Returns one of alias from ``ALIASES`` (in order of precedence same as | |
44 |
shortcuts given in ``ALIASES``) and |
|
44 | shortcuts given in ``ALIASES``) and working dir path for the given | |
45 | argument. If no scm-specific directory is found or more than one scm is |
|
45 | argument. If no scm-specific directory is found or more than one scm is | |
46 | found at that directory, ``VCSError`` is raised. |
|
46 | found at that directory, ``VCSError`` is raised. | |
47 |
|
||||
48 | :param search_path_up: if set to ``True``, this function would try to |
|
|||
49 | move up to parent directory every time no scm is recognized for the |
|
|||
50 | currently checked path. Default: ``False``. |
|
|||
51 | :param explicit_alias: can be one of available backend aliases, when given |
|
|||
52 | it will return given explicit alias in repositories under more than one |
|
|||
53 | version control, if explicit_alias is different than found it will raise |
|
|||
54 | VCSError |
|
|||
55 | """ |
|
47 | """ | |
56 | if not os.path.isdir(path): |
|
48 | if not os.path.isdir(path): | |
57 | raise VCSError("Given path %s is not a directory" % path) |
|
49 | raise VCSError("Given path %s is not a directory" % path) | |
58 |
|
50 | |||
59 | def get_scms(path): |
|
51 | found_scms = [(scm, path) for scm in get_scms_for_path(path)] | |
60 | return [(scm, path) for scm in get_scms_for_path(path)] |
|
|||
61 |
|
||||
62 | found_scms = get_scms(path) |
|
|||
63 | while not found_scms and search_path_up: |
|
|||
64 | newpath = os.path.abspath(os.path.join(path, os.pardir)) |
|
|||
65 | if newpath == path: |
|
|||
66 | break |
|
|||
67 | path = newpath |
|
|||
68 | found_scms = get_scms(path) |
|
|||
69 |
|
52 | |||
70 | if len(found_scms) > 1: |
|
53 | if len(found_scms) > 1: | |
71 | for scm in found_scms: |
|
|||
72 | if scm[0] == explicit_alias: |
|
|||
73 | return scm |
|
|||
74 | found = ', '.join((x[0] for x in found_scms)) |
|
54 | found = ', '.join((x[0] for x in found_scms)) | |
75 | raise VCSError( |
|
55 | raise VCSError( | |
76 | 'More than one [%s] scm found at given path %s' % (found, path)) |
|
56 | 'More than one [%s] scm found at given path %s' % (found, path)) |
General Comments 0
You need to be logged in to leave comments.
Login now