Ejemplo n.º 1
0
        public bool TryInit()
        {
            Verify.State.IsTrue(View != null, "Controller is not attached to a view.");

            var repositoryPath = View.RepositoryPath.Value.Trim();

            if (!GitControllerUtility.ValidateAbsolutePath(repositoryPath, View.RepositoryPath, View.ErrorNotifier))
            {
                return(false);
            }
            string template = null;

            if (View.UseCustomTemplate.Value)
            {
                template = View.Template.Value.Trim();
                if (!GitControllerUtility.ValidateAbsolutePath(template, View.Template, View.ErrorNotifier))
                {
                    return(false);
                }
            }
            bool bare = View.Bare.Value;

            try
            {
                if (!Directory.Exists(repositoryPath))
                {
                    Directory.CreateDirectory(repositoryPath);
                }
            }
            catch (Exception exc) when(!exc.IsCritical())
            {
                GitterApplication.MessageBoxService.Show(
                    View as IWin32Window,
                    exc.Message,
                    Resources.ErrFailedToCreateDirectory,
                    MessageBoxButton.Close,
                    MessageBoxIcon.Error);
                return(false);
            }
            try
            {
                using (View.ChangeCursor(MouseCursor.WaitCursor))
                {
                    Repository.Init(GitRepositoryProvider.GitAccessor, repositoryPath, template, bare);
                }
            }
            catch (GitException exc)
            {
                GitterApplication.MessageBoxService.Show(
                    View as IWin32Window,
                    exc.Message,
                    Resources.ErrFailedToInit,
                    MessageBoxButton.Close,
                    MessageBoxIcon.Error);
                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
        public bool TryClone()
        {
            Verify.State.IsTrue(View != null, "Controller is not attached to a view.");

            var url = View.Url.Value;

            if (!GitControllerUtility.ValidateUrl(url, View.Url, View.ErrorNotifier))
            {
                return(false);
            }
            var path = View.RepositoryPath.Value.Trim();

            if (!GitControllerUtility.ValidateAbsolutePath(path, View.RepositoryPath, View.ErrorNotifier))
            {
                return(false);
            }
            var remoteName = View.RemoteName.Value;

            if (!GitControllerUtility.ValidateRemoteName(remoteName, View.RemoteName, View.ErrorNotifier))
            {
                return(false);
            }
            url = url.Trim();
            bool   shallow  = View.ShallowClone.Value;
            int    depth    = shallow ? View.Depth.Value : -1;
            string template = View.UseTemplate.Value ? View.TemplatePath.Value.Trim() : null;

            if (!string.IsNullOrWhiteSpace(template) && !GitControllerUtility.ValidateAbsolutePath(template, View.TemplatePath, View.ErrorNotifier))
            {
                return(false);
            }

            bool bare       = View.Bare.Value;
            bool mirror     = bare && View.Mirror.Value;
            bool noCheckout = View.NoCheckout.Value;
            bool recursive  = View.Recursive.Value;

            var status = GuiCommands.Clone(View as IWin32Window,
                                           GitRepositoryProvider.GitAccessor,
                                           url, path, template, remoteName,
                                           shallow, depth, bare, mirror, recursive, noCheckout);

            return(status == GuiCommandStatus.Completed);
        }