Ensure directory exists before changing in popen

If the directory does not exist, we want to ensure that it does.

Forking repos will fail in some situations because of this issue.