Ticket #2522: git-safer-repo-validation.patch

File git-safer-repo-validation.patch, 1.6 KB (added by Goetz Pfeiffer, on 01/12/16 at 09:56:50)

Make RSBs check of a git repo more safe

  • source-builder/sb/git.py

    From: Goetz Pfeiffer <Goetz.Pfeiffer@helmholtz-berlin.de>
    Date: 1452530217 +0100
    Subject: Bugfix: A misconfiguration could update the wrong git working copy.
    A function in git.py checked the validity of a git repository by testing
    whether the path of the working copy existed. If it did, it called "git
    status" to see if the repository was valid. However, if the path existed but
    had no ".git" directory in it, "git status" would look in directories further
    up the directory hierarchy. If it found a git repository somewhere on the way
    it would work on this repository.
    In the end this could cause git.valid() returning True where it shouldn't.
    Other parts of the source builder then executed "git reset --hard" on the
    wrong local repository.
    Now the program checks first if a directory ".git" in the given path exists,
    and only then tries to execute "git status".
    diff -r b18eca73b9d1 -r fe308cb64dde source-builder/sb/git.py
    a b  
    144144        return not (len(_status) == 1 and 'branch' in _status)
    146146    def valid(self):
    147         if path.exists(self.path):
     147        # If self.path exists, but self.path+"/.git" does not, git looks for
     148        # the first ".git" directory further up the hierarchy. This is
     149        # definitely not what we want git to do, so we check for the existence
     150        # for self.path+"/.git" and not just self.path:
     151        if path.exists(os.path.join(self.path, ".git")):
    148152            ec, output = self._run(['status'])
    149153            return ec == 0
    150154        return False