Example #1
0
        /// <summary>
        /// Start scanning at the time the form is first shown
        /// </summary>
        private void FormNewRepoScanAddShown(object sender, EventArgs e)
        {
            enableAdd = true;
            int count = 1;

            // Create each of the repos for the selected directories
            foreach (var d in dirs)
            {
                if (enableAdd == false)
                {
                    return;
                }
                try
                {
                    // Update progress bar and make sure it gets painted
                    progressBar.Value = count++;
                    Thread.Sleep(1);

                    textRepo.Text = d;
                    Application.DoEvents();
                    Directory.SetCurrentDirectory(d);
                    if (ClassGit.Run("init").Success() == false)
                    {
                        throw new ClassException("init failed.");
                    }
                    App.Repos.Add(d);
                }
                catch (Exception ex)
                {
                    App.PrintLogMessage("Unable to add repo: " + ex.Message, MessageType.Error);
                    App.PrintStatusMessage(ex.Message, MessageType.Error);
                }
            }
            DialogResult = DialogResult.OK;
        }
Example #2
0
        /// <summary>
        /// Callback on the command line text ready.
        /// We execute a custom (immediate) command which can be either a direct git
        /// command or a shell (command prompt?) command.
        /// Several commands may be separated by "&&" token. This accomodates Gerrit
        /// code review process and its shortcuts that can be easily pasted.
        /// </summary>
        private void CmdBoxTextReady(object sender, string cmd)
        {
            foreach (string command in cmd.Split(new[] { " && " }, StringSplitOptions.RemoveEmptyEntries))
            {
                // Print out the command itself
                App.PrintStatusMessage(command, MessageType.Command);

                // If the command text started with a command 'git', remove it
                string[] tokens = command.Split(' ');
                string   args   = String.Join(" ", tokens, 1, tokens.Count() - 1);

                // We are guaranteed to have at least one token (by the TextBoxEx control)
                string run;
                if (tokens[0].ToLower() == "git")
                {
                    // Command is a git command: execute it
                    run = ClassGit.Run(args).ToString();
                }
                else
                {
                    // Command is an arbitrary (command line type) command
                    // Use the command shell to execute it
                    run = ClassUtils.ExecuteShellCommand(tokens[0], args);
                }
                App.PrintStatusMessage(run, MessageType.Output);
            }
        }
Example #3
0
        public ExecResult Run(string args, bool async)
        {
            ExecResult output = new ExecResult();

            try
            {
                Directory.SetCurrentDirectory(Root);

                // Set the HTTPS password
                string password = Remotes.GetPassword("");
                ClassUtils.AddEnvar("PASSWORD", password);

                // The Windows limit to the command line argument length is about 8K
                // We may hit that limit when doing operations on a large number of files.
                //
                // However, when sending a long list of files, git was hanging unless
                // the total length was much less than that, so I set it to about 2000 chars
                // which seemed to work fine.

                if (args.Length < 2000)
                {
                    return(ClassGit.Run(args, async));
                }

                // Partition the args into "[command] -- [set of file chunks < 2000 chars]"
                // Basically we have to rebuild the command into multiple instances with
                // same command but with file lists not larger than about 2K
                int    i   = args.IndexOf(" -- ") + 3;
                string cmd = args.Substring(0, i + 1);
                args = args.Substring(i);       // We separate git command up to and until the list of files

                App.PrintLogMessage("Processing large amount of files: please wait...", MessageType.General);

                // Add files individually up to the length limit using the starting " file delimiter
                string[] files = args.Split(new [] { " \"" }, StringSplitOptions.RemoveEmptyEntries);
                // Note: files in the list are now stripped from their initial " character!
                i = 0;
                do
                {
                    StringBuilder batch = new StringBuilder(2100);
                    while (batch.Length < 2000 && i < files.Length)
                    {
                        batch.Append("\"" + files[i++] + " ");
                    }

                    output = ClassGit.Run(cmd + batch, async);
                    if (output.Success() == false)
                    {
                        break;
                    }
                } while (i < files.Length);
            }
            catch (Exception ex)
            {
                App.PrintLogMessage(ex.Message, MessageType.Error);
            }

            return(output);
        }
Example #4
0
        /// <summary>
        /// Sets or removes a global git configuration value.
        /// If the value is null or empty string, the key will be removed (unset).
        /// </summary>
        public static void SetGlobal(string key, string value)
        {
            string setkey = string.IsNullOrEmpty(value) ? "--unset " : "";
            string val    = string.IsNullOrEmpty(value) ? "" : " \"" + value + "\"";
            string cmd    = setkey + key + val;

            if (ClassGit.Run("config --global " + cmd).Success() == false)
            {
                App.PrintLogMessage("Error setting global git config parameter!", MessageType.Error);
            }
        }
Example #5
0
        /// <summary>
        /// Returns a value of a global git configuration key
        /// </summary>
        public static string GetGlobal(string key)
        {
            ExecResult result = ClassGit.Run("config --global --get " + key);

            if (result.Success())
            {
                return(result.stdout);
            }

            App.PrintLogMessage("Error getting global git config parameter!", MessageType.Error);
            return(String.Empty);
        }
Example #6
0
        static int Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // Upgrade application settings across the version increment
            ClassUtils.UpgradeApplicationSettingsIfNecessary();

            // Make sure the application data folder directory exists
            Directory.CreateDirectory(AppHome);

            // Get and process command line arguments
            Arguments commandLine = new Arguments(args);

            // If the processing requested program termination,
            // return using the error code created by that class
            if (ClassCommandLine.Execute(commandLine) == false)
                return ClassCommandLine.ReturnCode;

            // Check that only one application instance is running
            bool mAcquired;
            Mutex mAppMutex = new Mutex(true, "gitforce", out mAcquired);
            if (!mAcquired && Properties.Settings.Default.WarnMultipleInstances)
            {
                if (MessageBox.Show("GitForce is already running.\nDo you want to open a new instance?", "Warning",
                    MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.No)
                    return -1;
            }

            // Initialize logging and git execute support
            Log = new FormLog();
            Log.ShowWindow(Properties.Settings.Default.ShowLogWindow);

            Git = new ClassGit();

            // Before we can start, we need to have a functional git executable);
            if (Git.Initialize())
            {
                // Initialize external diff program
                Diff = new ClassDiff();
                if( Diff.Initialize())
                {
                    Merge = new ClassMerge();
                    // Initialize external Merge program
                    if (Merge.Initialize())
                    {
                        // Add known text editors
                        Settings.Panels.ControlViewEdit.AddKnownEditors();

                        // Instantiate PuTTY support only on Windows OS
                        if (!ClassUtils.IsMono())
                            Putty = new ClassPutty();

                        GitPasswd = new ClassGitPasswd();   // Create HTTPS password helper file
                        Repos = new ClassRepos();           // Create repository canvas
                        Version = new ClassVersion();       // Start the new version check process
                        MainForm = new FormMain();          // Create the main form
                        MainForm.Show();                    // Show the main window so the handles get created
                        MainForm.Initialize();              // Load repos, custom tools etc.
                        DoRefresh();                        // Initial global refresh
                        Application.Run(MainForm);          // Run the main form

                        Properties.Settings.Default.Save();

                        GC.KeepAlive(mAppMutex);
                        return 0;
                    }
                }
            }
            return -1;
        }
Example #7
0
        static int Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // Upgrade application settings across the version increment
            ClassUtils.UpgradeApplicationSettingsIfNecessary();

            // Make sure the application data folder directory exists
            Directory.CreateDirectory(AppHome);

            // Get and process command line arguments
            Arguments commandLine = new Arguments(args);

            // If the processing requested program termination,
            // return using the error code created by that class
            if (ClassCommandLine.Execute(commandLine) == false)
            {
                return(ClassCommandLine.ReturnCode);
            }

            // Check that only one application instance is running
            bool  mAcquired;
            Mutex mAppMutex = new Mutex(true, "gitforce", out mAcquired);

            if (!mAcquired && Properties.Settings.Default.WarnMultipleInstances)
            {
                if (MessageBox.Show("GitForce is already running.\n\nDo you want to open a new instance?", "Warning",
                                    MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.No)
                {
                    return(-1);
                }
            }

            // Check if the application has been run as Admin/root
            if (ClassUtils.IsAdmin())
            {
                if (MessageBox.Show("GitForce has been run with elevated privileges which is not a recomended way to run it.\n\nDo you still want to continue?", "Warning",
                                    MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.No)
                {
                    return(-1);
                }
            }

            // Initialize logging and git execute support
            Log = new FormLog();
            Log.ShowWindow(Properties.Settings.Default.ShowLogWindow);

            Git = new ClassGit();

            // Before we can start, we need to have a functional git executable);
            if (Git.Initialize())
            {
                // Initialize external diff program
                Diff = new ClassDiff();
                if (Diff.Initialize())
                {
                    Merge = new ClassMerge();
                    // Initialize external Merge program
                    if (Merge.Initialize())
                    {
                        // Add known text editors
                        Settings.Panels.ControlViewEdit.AddKnownEditors();

                        if (ClassUtils.IsMono())
                        {
                            Ssh = new ClassSSH();           // Instantiate SSH support only on Linux (Mono)
                        }
                        else
                        {
                            Putty = new ClassPutty();         // Instantiate PuTTY support only on Windows
                        }
                        HttpsPasswd = new ClassHttpsPasswd(); // Create HTTPS password helper file
                        Repos       = new ClassRepos();       // Create repository canvas
                        Version     = new ClassVersion();     // Start the new version check process
                        MainForm    = new FormMain();         // Create the main form
                        MainForm.Show();                      // Show the main window so the handles get created
                        if (MainForm.Initialize())            // Load repos, custom tools etc.
                        {
                            DoRefresh();                      // Initial global refresh
                            Application.Run(MainForm);        // Run the main form

                            Properties.Settings.Default.Save();

                            GC.KeepAlive(mAppMutex);
                            return(0);
                        }
                    }
                }
            }
            return(-1);
        }