|
35 | 35 |
|
36 | 36 |
|
37 | 37 | # Application version
|
38 |
| -ver = '0.9.9' |
| 38 | +ver = '0.9.10' |
39 | 39 |
|
40 | 40 | # Default paths to Mercurial and Git
|
41 | 41 | hg_cmd = 'hg'
|
@@ -600,15 +600,24 @@ def checkout(rev, clean=False):
|
600 | 600 | if not rev:
|
601 | 601 | return
|
602 | 602 | info("Checkout \"%s\" in %s" % (rev, os.path.basename(os.getcwd())))
|
603 |
| - popen([git_cmd, 'checkout', rev] + (['-f'] if clean else []) + ([] if very_verbose else ['-q'])) |
604 |
| - if Git.isdetached(): # try to find associated refs to avoid detached state |
605 |
| - refs = Git.getrefs(rev) |
606 |
| - for ref in refs: # re-associate with a local or remote branch (rev is the same) |
607 |
| - branch = re.sub(r'^(.*?)\/(.*?)$', r'\2', ref) |
| 603 | + branch = None |
| 604 | + refs = Git.getrefs(rev) |
| 605 | + for ref in refs: # re-associate with a local or remote branch (rev is the same) |
| 606 | + m = re.match(r'^(.*?)\/(.*?)$', ref) |
| 607 | + if m and m.group(2) != "HEAD": # matches origin/<branch> and isn't HEAD ref |
| 608 | + if not os.path.exists(os.path.join('.git', 'refs', 'heads', m.group(2))): # okay only if local branch with that name doesn't exist (git will checkout the origin/<branch> in that case) |
| 609 | + branch = m.group(2) |
| 610 | + elif ref != "HEAD": |
| 611 | + branch = ref # matches local branch and isn't HEAD ref |
| 612 | + |
| 613 | + if branch: |
608 | 614 | info("Revision \"%s\" matches a branch \"%s\" reference. Re-associating with branch" % (rev, branch))
|
609 | 615 | popen([git_cmd, 'checkout', branch] + ([] if very_verbose else ['-q']))
|
610 | 616 | break
|
611 | 617 |
|
| 618 | + if not branch: |
| 619 | + popen([git_cmd, 'checkout', rev] + (['-f'] if clean else []) + ([] if very_verbose else ['-q'])) |
| 620 | + |
612 | 621 | def update(rev=None, clean=False, clean_files=False, is_local=False):
|
613 | 622 | if clean:
|
614 | 623 | Git.discard(clean_files)
|
@@ -698,9 +707,9 @@ def getrev():
|
698 | 707 | return pquery([git_cmd, 'rev-parse', 'HEAD']).strip()
|
699 | 708 |
|
700 | 709 | # Gets current branch or returns empty string if detached
|
701 |
| - def getbranch(): |
| 710 | + def getbranch(rev='HEAD'): |
702 | 711 | try:
|
703 |
| - branch = pquery([git_cmd, 'rev-parse', '--symbolic-full-name', '--abbrev-ref', 'HEAD']).strip() |
| 712 | + branch = pquery([git_cmd, 'rev-parse', '--symbolic-full-name', '--abbrev-ref', rev]).strip() |
704 | 713 | except ProcessException:
|
705 | 714 | branch = "master"
|
706 | 715 | return branch if branch != "HEAD" else ""
|
|
0 commit comments