public void AssertValidGitRepository()
{
var git = _container.GetInstance<IGitHelpers>();
if (!Directory.Exists(_globals.GitDir))
{
if (_globals.GitDirSetByUser)
{
throw new Exception("This command must be run inside a git repository!\nGIT_DIR=" + _globals.GitDir + " explicitly set, but it is not a directory.");
}
var gitDir = _globals.GitDir;
_globals.GitDir = null;
string cdUp = null;
git.WrapGitCommandErrors("This command must be run inside a git repository!\nAlready at top level, but " + gitDir + " not found.",
() =>
{
cdUp = git.CommandOneline("rev-parse", "--show-cdup");
if (string.IsNullOrEmpty(cdUp))
gitDir = ".";
else
cdUp = cdUp.TrimEnd();
if (string.IsNullOrEmpty(cdUp))
cdUp = ".";
});
Environment.CurrentDirectory = cdUp;
if (!Directory.Exists(gitDir))
{
throw new Exception("This command must be run inside a git repository!\n" + gitDir + " still not found after going to " + cdUp);
}
_globals.GitDir = gitDir;
}
_globals.Repository = git.MakeRepository(_globals.GitDir);
}