• Kirill Smelkov's avatar
    Don't be fooled by strings.Split(..., "\n") result always having empty "" last element · 3ba6cf73
    Kirill Smelkov authored
    By definition of strings.Split(..., sep) it "slices s into all substrings
    separated by sep and returns a slice of the substrings between those
    separators". That means that
    
        string.Split("hello\nworld\n", "\n") -> ["hello", "world", ""])     # NOTE the last ""
    
    when parsing file by lines, it is handy though to do not get last empty
    "" after last "\n". #6 shows how we missed to do that filtering-out for
    case of empty backup.refs file and errored-out because of that.
    
    To fix let's introduce a helper - splitlines(), which does the job of
    filtering-out last empty entry after last separator. By using this
    helper everywhere we can hopefully avoid problems while pulling only
    empty repositories (#6 case), and also similar ones.
    
    Fixes #6
    /reported-by @iv
    3ba6cf73
git-backup.go 35.1 KB