-
-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix issue #86 - detect dirty git workdirs even in the absence of tags
- Loading branch information
Showing
4 changed files
with
74 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
v1.13.1 | ||
======= | ||
|
||
* fix issue #86 - detect dirty git workdir without tags | ||
|
||
v1.13.0 | ||
======= | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,69 @@ | ||
from .utils import do, do_ex, trace | ||
from .utils import do_ex, trace | ||
from .version import meta | ||
from os.path import abspath, normcase, realpath | ||
|
||
|
||
FILES_COMMAND = 'git ls-files' | ||
DEFAULT_DESCRIBE = 'git describe --dirty --tags --long --match *.*' | ||
DEFAULT_DESCRIBE = 'git describe --tags --long --match *.*' | ||
|
||
|
||
def _normalized(path): | ||
return normcase(abspath(realpath(path))) | ||
|
||
|
||
class GitWorkdir(object): | ||
def __init__(self, path): | ||
self.path = path | ||
|
||
def do_ex(self, cmd): | ||
return do_ex(cmd, cwd=self.path) | ||
|
||
@classmethod | ||
def from_potential_worktree(cls, wd): | ||
real_wd, _, ret = do_ex('git rev-parse --show-toplevel', wd) | ||
if ret: | ||
return | ||
trace('real root', real_wd) | ||
if _normalized(real_wd) != _normalized(wd): | ||
return | ||
|
||
return cls(real_wd) | ||
|
||
def is_dirty(self): | ||
out, _, _ = self.do_ex("git status --porcelain") | ||
return bool(out) | ||
|
||
def node(self): | ||
rev_node, _, ret = self.do_ex('git rev-parse --verify --quiet HEAD') | ||
if not ret: | ||
return rev_node[:7] | ||
|
||
def count_all_nodes(self): | ||
revs, _, _ = self.do_ex('git rev-list HEAD') | ||
return revs.count('\n') + 1 | ||
|
||
|
||
def parse(root, describe_command=DEFAULT_DESCRIBE): | ||
real_root, _, ret = do_ex('git rev-parse --show-toplevel', root) | ||
if ret: | ||
return | ||
trace('real root', real_root) | ||
if (normcase(abspath(realpath(real_root))) != | ||
normcase(abspath(realpath(root)))): | ||
return | ||
rev_node, _, ret = do_ex('git rev-parse --verify --quiet HEAD', root) | ||
if ret: | ||
return meta('0.0') | ||
rev_node = rev_node[:7] | ||
wd = GitWorkdir(root) | ||
|
||
rev_node = wd.node() | ||
dirty = wd.is_dirty() | ||
|
||
if rev_node is None: | ||
return meta('0.0', dirty=dirty) | ||
|
||
out, err, ret = do_ex(describe_command, root) | ||
if '-' not in out and '.' not in out: | ||
revs = do('git rev-list HEAD', root) | ||
count = revs.count('\n') | ||
if ret: | ||
out = rev_node | ||
return meta('0.0', distance=count + 1, node=out) | ||
if ret: | ||
return | ||
dirty = out.endswith('-dirty') | ||
if dirty: | ||
out = out.rsplit('-', 1)[0] | ||
return meta( | ||
'0.0', | ||
distance=wd.count_all_nodes(), | ||
node=rev_node, | ||
dirty=dirty, | ||
) | ||
|
||
tag, number, node = out.rsplit('-', 2) | ||
number = int(number) | ||
if number: | ||
return meta(tag, distance=number, node=node, dirty=dirty) | ||
else: | ||
return meta(tag, dirty=dirty, node=node) | ||
return meta(tag, node=node, dirty=dirty) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters