public GitRepositoryContext GetRepositoryContext()
        {
            args.Validate();

            var gitRootDirectory = Path.Combine(args.DestinationPath);
            var gitDirectory     = Path.Combine(gitRootDirectory, ".git");

            if (Directory.Exists(gitDirectory))
            {
                Log.WriteLine("Deleting existing .git folder from '{0}' to force new checkout from url", gitDirectory);
                DeleteGitDirectory(gitDirectory);
            }

            var credentials = args.Credentials;

            Log.WriteLine("Retrieving git info from url '{0}'", args.Url);

            var cloneOptions = new CloneOptions();

            cloneOptions.IsBare              = true;
            cloneOptions.Checkout            = false;
            cloneOptions.CredentialsProvider = (url, usernameFromUrl, types) => credentials;

            var repoPath    = Repository.Clone(args.Url, gitDirectory, cloneOptions);
            var repository  = new Repository(repoPath);
            var repoContext = new GitRepositoryContext(repository, credentials, true, args.Url);

            return(repoContext);
        }
        public GitRepositoryContext GetRepositoryContext()
        {
            args.Validate();

            var gitRootDirectory = Path.Combine(args.DestinationPath);
            var gitDirectory = Path.Combine(gitRootDirectory, ".git");
            if (Directory.Exists(gitDirectory))
            {
                Log.WriteLine("Deleting existing .git folder from '{0}' to force new checkout from url", gitDirectory);
                DeleteGitDirectory(gitDirectory);
            }

            var credentials = args.Credentials;

            Log.WriteLine("Retrieving git info from url '{0}'", args.Url);

            var cloneOptions = new CloneOptions();
            cloneOptions.IsBare = true;
            cloneOptions.Checkout = false;
            cloneOptions.CredentialsProvider = (url, usernameFromUrl, types) => credentials;

            var repoPath = Repository.Clone(args.Url, gitDirectory, cloneOptions);
            var repository = new Repository(repoPath);
            var repoContext = new GitRepositoryContext(repository, credentials, true, args.Url);
            return repoContext;
        }
        public GitRepositoryContext GetRepositoryContext()
        {
            args.Validate();

            var gitRootDirectory = Path.Combine(args.DestinationPath);
            var gitDirectory = Path.Combine(gitRootDirectory, ".git");

            var credentials = args.Credentials;

            if (fileSystem.DirectoryExists(gitDirectory))
            {
                Log.WriteLine("Git repository already exists, using existing instance from url '{0}'", args.Url);

                var repository = new Repository(gitDirectory);
                var repoContext = new GitRepositoryContext(repository, credentials, true, args.Url, fileSystem);
                return repoContext;
            }
            else
            {
                Log.WriteLine("Cloning git repository from url '{0}'", args.Url);

                var cloneOptions = new CloneOptions
                {
                    IsBare = true,
                    Checkout = false,
                    CredentialsProvider = (url, usernameFromUrl, types) => credentials
                };

                var repoPath = Repository.Clone(args.Url, gitDirectory, cloneOptions);
                var repository = new Repository(repoPath);
                var repoContext = new GitRepositoryContext(repository, credentials, true, args.Url, fileSystem);
                return repoContext;
            }
        }
        public GitRepositoryContext GetRepositoryContext()
        {
            // scan the working directory (default to current directory)
            var gitDirectory = GitDirFinder.TreeWalkForGitDir(workingDir);
            if (string.IsNullOrEmpty(gitDirectory))
            {
                throw new Exception("Failed to find a .git folder in the working directory.");
            }

            Log.WriteLine("Git directory found at {0}", gitDirectory);

            var gitRepo = new Repository(gitDirectory);
            var context = new GitRepositoryContext(gitRepo, null, false, string.Empty, fileSystem);
            return context;
        }
        public GitRepositoryContext GetRepositoryContext()
        {
            // scan the working directory (default to current directory)
            var gitDirectory = GitDirFinder.TreeWalkForGitDir(workingDir);

            if (string.IsNullOrEmpty(gitDirectory))
            {
                throw new Exception("Failed to find a .git folder in the working directory.");
            }

            Log.WriteLine("Git directory found at {0}", gitDirectory);

            var gitRepo = new Repository(gitDirectory);
            var context = new GitRepositoryContext(gitRepo, null, false, string.Empty);

            return(context);
        }