magit-{git-dir,get-top-dir}: make sure file is non-nil

Before using file functions on "the directory" , make sure it
actually is non-nil.  If we are not inside a repository it is nil.
These functions expect a string, when the are confronted with nil
they raise an error.