From ed72af63782c455ece6568b96849a29c43c79f1b Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Mon, 8 Jun 2015 13:40:47 +0200 Subject: git-update: Improve error message for non-blob objects When a repository contains a directory, a user is currently faced with the following error message: remote: Traceback (most recent call last): remote: File "hooks/update", line 194, in remote: if repo[treeobj.id].size > 250000: remote: AttributeError: '_pygit2.Tree' object has no attribute 'size' remote: error: hook declined to update refs/heads/master Explicitly check for directories and other non-blob objects and display a more intuitive message. Signed-off-by: Lukas Fleischer --- git-interface/git-update.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'git-interface') diff --git a/git-interface/git-update.py b/git-interface/git-update.py index 073e650..4177e53 100755 --- a/git-interface/git-update.py +++ b/git-interface/git-update.py @@ -191,7 +191,16 @@ for commit in walker: die_commit("missing .SRCINFO", commit.id) for treeobj in commit.tree: - if repo[treeobj.id].size > 250000: + blob = repo[treeobj.id] + + if isinstance(blob, pygit2.Tree): + die_commit("the repository must not contain subdirectories", + commit.id) + + if not isinstance(blob, pygit2.Blob): + die_commit("not a blob object: %s" % (treeobj), commit.id) + + if blob.size > 250000: die_commit("maximum blob size (250kB) exceeded", commit.id) srcinfo_raw = repo[commit.tree['.SRCINFO'].id].data.decode() -- cgit v1.2.3-54-g00ecf