Exemple #1
0
        private void ButtonFetch_Click(object sender, EventArgs e)
        {
            RepoDetails local = ReposConfig.GetInstance().GetSelected();

            if (local == null)
            {
                DialogUtil.Message("Please select a repository before fetching.");
                return;
            }

            ServerDetails remote = ServersConfig.GetInstance().GetServerDetailsByName(local.GetServer());

            if (remote == null)
            {
                DialogUtil.Message("Server \"" + local.GetServer() + "\" is not available.");
                return;
            }

            // build and execute script
            ScriptBuilder.FetchScript(local, remote);
            Executable exe = new Executable("expect.exe", "fetch.lua").Start();

            exe.WaitForExit();                            // hold thread till update

            EventManager.Fire(EventCode.REFRESH_CHANGES); // refresh changelist
        }
Exemple #2
0
        /// <summary>
        /// Creates and executes a push script to upload commits to the repository's server
        /// TODO: add notification to inform about queued commits
        /// </summary>
        private void ButtonPushCommits_Click(object sender, EventArgs e)
        {
            RepoDetails local = ReposConfig.GetInstance().GetSelected();

            if (local == null)
            {
                DialogUtil.Message("Push Error", "Please select a repository to push commits to.");
                return;
            }

            ServerDetails remote = ServersConfig.GetInstance().GetServerDetailsByName(local.GetServer());

            if (remote == null)
            {
                DialogUtil.Message("Push Error", "Server \"" + local.GetServer() + "\" is not available");
                return;
            }

            ScriptBuilder.PushScript(local, remote);
            Executable exe = new Executable("expect.exe", "push.lua").Start();

            exe.WaitForExit();

            EventManager.Fire(EventCode.REFRESH_CHANGES);
        }
Exemple #3
0
        /// <summary>
        /// Creates and executes a commit script based on the currently selected repository.
        /// </summary>
        private void ButtonCommitChanges_Click(object sender, EventArgs e)
        {
            string commitmsg = TextBoxCommitMessage.Text;

            if (commitmsg.Equals("") || commitmsg.Equals(ApplicationConstant.COMMIT_GREYTEXT))
            {
                DialogUtil.Message("Commit Error", "Please add a commit message before committing.");
                return;
            }

            RepoDetails repo = ReposConfig.GetInstance().GetSelected();

            if (repo == null)
            {
                DialogUtil.Message("Commit Error", "Please select a repository to commit to.");
                return;
            }

            ScriptBuilder.CommitScript(repo, TextBoxCommitMessage.Text);
            Executable exe = new Executable("expect.exe", "commit.lua").Start();

            exe.WaitForExit();

            TextBoxCommitMessage.Text = ""; // will not show greytext
            TextBoxCommitMessage_Validate(TextBoxCommitMessage, e);
            EventManager.Fire(EventCode.REFRESH_CHANGES);
        }
Exemple #4
0
        /// <summary>
        ///
        /// </summary>
        private void ListBoxRepoChanges_SelectedIndexChanged(object sender, EventArgs e)
        {
            var item = ListBoxRepoChanges.SelectedItem;

            if (item == null)
            {
                return;
            }

            string      selectedFile = item.ToString();
            RepoDetails rd           = ReposConfig.GetInstance().GetSelected();
            //string selectedPath = rd.GetLocal().Replace(@"\","/") + "/" + selectedFile;

            // get changes in the selected file
            Repository    rep   = new Repository(rd);
            List <string> lines = rep.FileDelta(selectedFile);

            // reset the textbox
            // color the removed lines red and the new lines green
            RichTextBoxDeltaDetails.Text = "";
            foreach (string line in lines)
            {
                if (line.StartsWith("+"))
                {
                    RichTextBoxDeltaDetails.SelectionColor = Color.Green;
                }

                if (line.StartsWith("-"))
                {
                    RichTextBoxDeltaDetails.SelectionColor = Color.Red;
                }

                RichTextBoxDeltaDetails.SelectedText = line + Environment.NewLine;
            }
        }
 /// <summary>
 /// clones a remote repository to the provided git workspace
 /// </summary>
 public static string CloneScript(RepoDetails rd, ServerDetails sd)
 {
     string[] lines = new string[]
     {
         "cd /D " + rd.GetLocal(),      // jump to local workspace
         "git clone " + rd.GetRemote(), // clone remote repo
         "exit"
     };
     FileUtil.WriteToFileUTF8("clone.bat", lines);
     return(DefaultLogin("clone", sd));
 }
 /// <summary>
 /// push commits to remote repository
 /// </summary>
 public static string PushScript(RepoDetails rd, ServerDetails sd)
 {
     string[] lines = new string[]
     {
         "cd /D " + rd.GetLocal(),               // jump to folder
         "git push " + rd.GetName() + " master", // upload to repository
         "exit"
     };
     FileUtil.WriteToFileUTF8("push.bat", lines);
     return(DefaultLogin("push", sd));
 }
 /// <summary>
 /// In its default mode, "git pull" is shorthand for "git fetch" followed by "git merge FETCH_HEAD"
 /// </summary>
 public static string PullScript(RepoDetails rd, ServerDetails sd)
 {
     string[] lines = new string[]
     {
         "cd /D " + rd.GetLocal(),
         "git pull " + rd.GetName() + " master",
         "exit"
     };
     FileUtil.WriteToFileUTF8("pull.bat", lines);
     return(DefaultLogin("pull", sd));
 }
 /// <summary>
 /// scans a file in the repo for differences compared to last commit
 /// </summary>
 public static string DifferenceFileScript(RepoDetails rd, string file)
 {
     string[] lines = new string[]
     {
         "cd /D " + rd.GetLocal(), // jump to local workspace
         "git diff -- " + file,    // scan file differences
         "exit"
     };
     FileUtil.WriteToFileUTF8("diff-file.bat", lines);
     return(DefaultExecution("diff-file"));
 }
        /// <summary>
        /// refreshes the repo listbox
        /// </summary>
        private void RefreshList()
        {
            ListBoxRepos.Items.Clear();
            ReposConfig            cnf  = ReposConfig.GetInstance();
            Iterator <RepoDetails> itsd = cnf.GetRepoDetails();

            while (itsd.HasNext())
            {
                RepoDetails sd = itsd.GetNext();
                ListBoxRepos.Items.Add(sd.GetName());
            }
        }
 /// <summary>
 /// new a script to create a new local repository
 /// </summary>
 public static string NewScript(RepoDetails rd)
 {
     string[] lines = new string[]
     {
         "cd /D " + rd.GetLocal(),                                // jump to folder
         "git init",                                              // initialize the folder as a git repository
         "git remote add " + rd.GetName() + " " + rd.GetRemote(), // add a reference to the remote repository
         "exit"
     };
     FileUtil.WriteToFileUTF8("new.bat", lines);
     return(DefaultExecution("new"));
 }
 /// <summary>
 /// commit all changes and push to remote repository
 /// </summary>
 public static string CommitAndPushScript(RepoDetails rd, ServerDetails sd, string message)
 {
     string[] lines = new string[]
     {
         "cd /D " + rd.GetLocal(),               // jump to folder
         "git add -A",                           // add all untracked, might make this optional later on
         "git commit -am \"" + message + "\"",   // commit all changes with a message
         "git push " + rd.GetName() + " master", // upload to repository
         "exit"
     };
     FileUtil.WriteToFileUTF8("commitpush.bat", lines);
     return(DefaultLogin("commitpush", sd));
 }
 /// <summary>
 /// Restores missing files. Synchronizes with the remote repository.
 /// </summary>
 public static string FetchScript(RepoDetails rd, ServerDetails sd)
 {
     string[] lines = new string[]
     {
         "cd /D " + rd.GetLocal(),            // jump to folder
         "git fetch --prune " + rd.GetName(), // or origin
         "git reset --hard master",
         "git clean -f -d",
         "exit"
     };
     FileUtil.WriteToFileUTF8("fetch.bat", lines);
     return(DefaultLogin("fetch", sd));
 }
 /// <summary>
 /// commit all changes
 /// </summary>
 public static string CommitScript(RepoDetails rd, string message)
 {
     string[] lines = new string[]
     {
         "cd /D " + rd.GetLocal(), // jump to folder
         "git add -A",             // stages all changes. "git add -A" is equivalent to "git add ." followed by "git add -u"
         //"git add .", // stages new files and modifications, without deletions
         //"git add -u", // stages modifications and deletions, without new files
         "git commit -am \"" + message + "\"", // commit all changes with a message
         "exit"
     };
     FileUtil.WriteToFileUTF8("commit.bat", lines);
     return(DefaultExecution("commit"));
 }
Exemple #14
0
        // =================================================================
        //              Global Events - Threaded
        // =================================================================

        public void OnEvent(EventData ed)
        {
            switch (ed.EventCode)
            {
            // refreshes the repository list
            case EventCode.REFRESH_REPOS:
                ComboBoxAvailableRepos.Invoke(new MethodInvoker(delegate
                {
                    ComboBoxAvailableRepos.Items.Clear();
                    var cnf = ReposConfig.GetInstance();

                    Iterator <RepoDetails> itsd = cnf.GetRepoDetails();
                    while (itsd.HasNext())
                    {
                        RepoDetails sd = itsd.GetNext();
                        ComboBoxAvailableRepos.Items.Add(sd.GetName());
                    }
                }));
                break;

            case EventCode.REFRESH_CHANGES:
                // clear the change details. they're possibly invalid
                RichTextBoxDeltaDetails.Invoke(new MethodInvoker(delegate
                {
                    RichTextBoxDeltaDetails.Text = "";
                }));

                var repdetails = ReposConfig.GetInstance().GetSelected();

                // get the repository from the manager
                // if the repo doesnt
                Repository    rep    = new Repository(repdetails);
                List <string> deltas = rep.RepoDelta();

                // update repository
                ListBoxRepoChanges.Invoke(new MethodInvoker(delegate
                {
                    ListBoxRepoChanges.Items.Clear();
                    Iterator <string> it = new Iterator <string>(deltas);
                    while (it.HasNext())
                    {
                        ListBoxRepoChanges.Items.Add(it.GetNext());
                    }
                }));
                break;

            default: break;
            }
        }
        private void ComboBoxAvailableServers_SelectedIndexChanged(object sender, EventArgs e)
        {
            int           i    = ComboBoxAvailableServers.SelectedIndex;
            ServersConfig cnf  = ServersConfig.GetInstance();
            ServerDetails serv = cnf.GetServerDetailsByIndex(i);

            if (serv == null)
            {
                return;
            }
            cnf.SetSelectedByIndex(i);
            ReposConfig rcnf = ReposConfig.GetInstance();
            RepoDetails repo = rcnf.GetSelected();

            if (repo == null)
            {
                return;
            }
            repo.SetServer(cnf.GetSelected().GetName());
        }
        // =================================================================
        //              UI Events
        // =================================================================

        private void ButtonAccept_Click(object sender, EventArgs e)
        {
            // error checks
            string repoName = TextBoxRepoName.Text;

            if (repoName == null)
            {
                return;
            }
            if (repoName.Equals(""))
            {
                return;
            }
            if (repoName.Equals("Repository Name"))
            {
                return;
            }

            string localDir = TextBoxLocalDirectory.Text;

            if (localDir == null)
            {
                return;
            }
            if (localDir.Equals(""))
            {
                return;
            }
            localDir = localDir.Replace(@"\", "/");

            string server = ComboBoxSelectServer.GetItemText(ComboBoxSelectServer.SelectedItem);

            if (server == null)
            {
                return;
            }
            if (server.Equals(""))
            {
                return;
            }


            // get server details
            ListItem      listitem = (ListItem)(ComboBoxSelectServer.SelectedItem);
            ServerDetails sd       = listitem.Details;

            // check to see if sevrer is available
            RemoteManager rman   = RemoteManager.GetInstance();
            IRemote       remote = rman.Connect(sd);

            if (!remote.IsConnected()) // error
            {
                DialogUtil.Message("Error: Cannot connect to remote repository");
                return;
            }

            // make and run the script for downloading the selected repository
            string      remoteDir = sd.GetServerLoginString() + "/" + repoName;
            RepoDetails repo      = new RepoDetails(repoName, sd.GetName(), remoteDir, localDir);
            string      script    = ScriptBuilder.CloneScript(repo, sd);
            Executable  exe       = new Executable("expect.exe", script).Start();

            exe.WaitForExit();

            // add new repo to configuration
            ReposConfig.GetInstance().AddRepoDetails(repo, false);
            ReposConfig.GetInstance().Save();

            // done. now close and fire refresh event
            EventManager.Fire(EventCode.REFRESH_REPOS);
            ProperClose();
        }
Exemple #17
0
 public Repository(RepoDetails rd)
 {
     details = rd;
     buffer  = new List <string>();
 }
        // =================================================================
        //              UI Events
        // =================================================================

        /// <summary>
        /// When creating a new repository two things need to happen. The
        /// server needs to setup a bare repo and the local directory needs
        /// to be linked to the remote repo.
        /// </summary>
        private void ButtonAccept_Click(object sender, EventArgs e)
        {
            // error checks
            string repoName = TextBoxRepoName.Text;

            if (repoName == null)
            {
                return;
            }
            if (repoName.Equals(""))
            {
                return;
            }
            if (repoName.Equals("Repository Name"))
            {
                return;
            }

            string localDir = TextBoxLocalDirectory.Text;

            if (localDir == null)
            {
                return;
            }
            if (localDir.Equals(""))
            {
                return;
            }

            string server = ComboBoxSelectServer.GetItemText(ComboBoxSelectServer.SelectedItem);

            if (server == null)
            {
                return;
            }
            if (server.Equals(""))
            {
                return;
            }
            localDir = localDir.Replace(@"\", "/") + "/" + repoName;

            // get server details
            ListItem      listitem = (ListItem)(ComboBoxSelectServer.SelectedItem);
            ServerDetails sd       = listitem.Details;

            // connect to server to setup the remote repo
            RemoteManager rman   = RemoteManager.GetInstance();
            IRemote       remote = rman.Connect(sd);

            if (!remote.IsConnected()) // error
            {
                DialogUtil.Message("Error: Cannot connect to remote repository");
                return;
            }

            IStream stream  = remote.GetStream();
            string  repoLoc = sd.GetLocation() + "/" + repoName;

            stream.Execute("mkdir -p " + repoLoc);
            stream.Execute("cd " + repoLoc);
            bool success = stream.Execute("git init --bare");

            if (!success) // error
            {
                DialogUtil.Message("Error: Could not execute command");
                return;
            }

            // make local directory
            Directory.CreateDirectory(localDir);

            if (!Directory.Exists(localDir)) // error
            {
                DialogUtil.Message("Error: Could not create local repository");
                return;
            }

            // make and run the script for initializing a new local repo
            string      remoteDir = sd.GetServerLoginString() + "/" + repoName;
            RepoDetails repo      = new RepoDetails(repoName, sd.GetName(), remoteDir, localDir);
            string      script    = ScriptBuilder.NewScript(repo);
            Executable  exe       = new Executable("expect.exe", script).Start();

            exe.WaitForExit();

            // add new repo to configuration
            ReposConfig.GetInstance().AddRepoDetails(repo, false);
            ReposConfig.GetInstance().Save();

            // done. now close and fire refresh event
            EventManager.Fire(EventCode.REFRESH_REPOS);
            ProperClose();
        }