Show More
@@ -1,25 +1,26 b'' | |||
|
1 | 1 | import os |
|
2 | 2 | |
|
3 | 3 | |
|
4 | 4 | def get_current_revision(quiet=False): |
|
5 | 5 | """ |
|
6 | 6 | Returns tuple of (number, id) from repository containing this package |
|
7 | 7 | or None if repository could not be found. |
|
8 | 8 | |
|
9 | 9 | :param quiet: prints error for fetching revision if True |
|
10 | 10 | """ |
|
11 | 11 | |
|
12 | 12 | try: |
|
13 | 13 | from rhodecode.lib.vcs import get_repo |
|
14 | 14 | from rhodecode.lib.vcs.utils.helpers import get_scm |
|
15 | 15 | repopath = os.path.join(os.path.dirname(__file__), '..', '..') |
|
16 | 16 | scm = get_scm(repopath)[0] |
|
17 | 17 | repo = get_repo(path=repopath, alias=scm) |
|
18 | tip = repo.get_changeset() | |
|
19 | return (tip.revision, tip.short_id) | |
|
18 | wk_dir = repo.workdir | |
|
19 | cur_rev = wk_dir.get_changeset() | |
|
20 | return (cur_rev.revision, cur_rev.short_id) | |
|
20 | 21 | except Exception, err: |
|
21 | 22 | if not quiet: |
|
22 | 23 | print ("WARNING: Cannot retrieve rhodecode's revision. " |
|
23 | 24 | "disregard this if you don't know what that means. " |
|
24 | 25 | "Original error was: %s" % err) |
|
25 | 26 | return None |
@@ -1,31 +1,31 b'' | |||
|
1 | 1 | import re |
|
2 | 2 | from rhodecode.lib.vcs.backends.base import BaseWorkdir |
|
3 | 3 | from rhodecode.lib.vcs.exceptions import RepositoryError |
|
4 | 4 | from rhodecode.lib.vcs.exceptions import BranchDoesNotExistError |
|
5 | 5 | |
|
6 | 6 | |
|
7 | 7 | class GitWorkdir(BaseWorkdir): |
|
8 | 8 | |
|
9 | 9 | def get_branch(self): |
|
10 | 10 | headpath = self.repository._repo.refs.refpath('HEAD') |
|
11 | 11 | try: |
|
12 | 12 | content = open(headpath).read() |
|
13 | 13 | match = re.match(r'^ref: refs/heads/(?P<branch>.+)\n$', content) |
|
14 | 14 | if match: |
|
15 | 15 | return match.groupdict()['branch'] |
|
16 | 16 | else: |
|
17 | 17 | raise RepositoryError("Couldn't compute workdir's branch") |
|
18 | 18 | except IOError: |
|
19 | 19 | # Try naive way... |
|
20 | 20 | raise RepositoryError("Couldn't compute workdir's branch") |
|
21 | 21 | |
|
22 | 22 | def get_changeset(self): |
|
23 | return self.repository.get_changeset( | |
|
24 | self.repository._repo.refs.as_dict().get('HEAD')) | |
|
23 | wk_dir_id = self.repository._repo.refs.as_dict().get('HEAD') | |
|
24 | return self.repository.get_changeset(wk_dir_id) | |
|
25 | 25 | |
|
26 | 26 | def checkout_branch(self, branch=None): |
|
27 | 27 | if branch is None: |
|
28 | 28 | branch = self.repository.DEFAULT_BRANCH_NAME |
|
29 | 29 | if branch not in self.repository.branches: |
|
30 | 30 | raise BranchDoesNotExistError |
|
31 | 31 | self.repository.run_git_command(['checkout', branch]) |
@@ -1,21 +1,22 b'' | |||
|
1 | 1 | from rhodecode.lib.vcs.backends.base import BaseWorkdir |
|
2 | 2 | from rhodecode.lib.vcs.exceptions import BranchDoesNotExistError |
|
3 | 3 | |
|
4 | 4 | from rhodecode.lib.vcs.utils.hgcompat import hg_merge |
|
5 | 5 | |
|
6 | 6 | |
|
7 | 7 | class MercurialWorkdir(BaseWorkdir): |
|
8 | 8 | |
|
9 | 9 | def get_branch(self): |
|
10 | 10 | return self.repository._repo.dirstate.branch() |
|
11 | 11 | |
|
12 | 12 | def get_changeset(self): |
|
13 | return self.repository.get_changeset() | |
|
13 | wk_dir_id = self.repository._repo[None].parents()[0].hex() | |
|
14 | return self.repository.get_changeset(wk_dir_id) | |
|
14 | 15 | |
|
15 | 16 | def checkout_branch(self, branch=None): |
|
16 | 17 | if branch is None: |
|
17 | 18 | branch = self.repository.DEFAULT_BRANCH_NAME |
|
18 | 19 | if branch not in self.repository.branches: |
|
19 | 20 | raise BranchDoesNotExistError |
|
20 | 21 | |
|
21 | 22 | hg_merge.update(self.repository._repo, branch, False, False, None) |
General Comments 0
You need to be logged in to leave comments.
Login now