Edgewall Software

Opened 12 years ago

Closed 11 years ago

Last modified 11 years ago

#10598 closed defect (fixed)

GitPlugin: PyGIT._get_branches fails with ValueError on commit messages with line feeds — at Version 3

Reported by: Peter Suter Owned by: Jun Omae
Priority: lowest Milestone: 1.0.2
Component: plugin/git Version:
Severity: normal Keywords:
Cc: Ryan J Ollos Branch:
Release Notes:

fix ValueError in Storage._get_branches() if a branch head has carriage returns in the commit log

API Changes:
Internal Changes:

Description

Created as part of the move of GitPlugin. Tickets originally reported for th:GitPlugin: th:#8639

Quoting Carsten Klein:

I have a commit here that includes a subject line that includes ^M characters. This will cause get_branches to fail when trying to unpack the malformed lines resulting from splitting on linefeed boundary.

Here is a proposed fast solution that will replace all ^M characters so that retrieving the branch information does not fail

--- /trunk/tracopt/versioncontrol/git/PyGIT.py
+++ /trunk/tracopt/versioncontrol/git/PyGIT.py
    def _get_branches(self):
        "returns list of (local) branches, with active (= HEAD) one being the first item"

        result = []
-        for e in self.repo.branch("-v", "--no-abbrev").splitlines():
+        for e in self.repo.branch("-v", "--no-abbrev").replace('\r', '/CTRL-R').splitlines():
            bname, bsha = e[1:].strip().split()[:2]
            if e.startswith('*'):
                result.insert(0, (bname, bsha))
            else:
                result.append((bname, bsha))

        return result

Change History (3)

comment:1 by Christian Boos, 11 years ago

Milestone: next-stable-1.0.x
Priority: normallowest

Link to a git repos demonstrating the issue welcome.

comment:2 by Jun Omae, 11 years ago

Owner: set to Jun Omae
Status: newassigned

Reproduced with CRs in the center of commit log. In [cac08aede/jomae.git], added the fix and unit tests.

comment:3 by Jun Omae, 11 years ago

Milestone: next-stable-1.0.x1.0.2
Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed

Fixed in [11802].

Note: See TracTickets for help on using tickets.