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