Ejemplo n.º 1
0
        private void RemoveSubmoduleClick(object sender, EventArgs e)
        {
            if (Submodules.SelectedRows.Count != 1 ||
                MessageBox.Show(this, _removeSelectedSubmodule.Text, _removeSelectedSubmoduleCaption.Text, MessageBoxButtons.YesNo) !=
                DialogResult.Yes)
                return;

            Cursor.Current = Cursors.WaitCursor;
            Settings.Module.RunGitCmd("rm --cached \"" + SubModuleName.Text + "\"");

            var modules = new ConfigFile(Settings.WorkingDir + ".gitmodules");
            modules.RemoveConfigSection("submodule \"" + SubModuleName.Text + "\"");
            if (modules.GetConfigSections().Count > 0)
                modules.Save();
            else
                Settings.Module.RunGitCmd("rm --cached \".gitmodules\"");

            var configFile = Settings.Module.GetLocalConfig();
            configFile.RemoveConfigSection("submodule \"" + SubModuleName.Text + "\"");
            configFile.Save();

            Initialize();
            Cursor.Current = Cursors.Default;
        }
        private void ConflictedFiles_DoubleClick(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            if (ConflictedFiles.SelectedRows.Count != 1)
                return;

            string filename = GetFileName();
            string[] filenames = Settings.Module.GetConflictedFiles(filename);

            try
            {
                if (Directory.Exists(Settings.WorkingDir + filename) && !File.Exists(Settings.WorkingDir + filename))
                {
                    /* BEGIN REPLACED WITH FASTER, BUT DIRTIER SUBMODULE CHECK
                    IList<IGitSubmodule> submodules = (new GitCommands.GitCommands()).GetSubmodules();
                    foreach (IGitSubmodule submodule in submodules)
                    {
                        if (submodule.LocalPath.Equals(filename))
                        {
                            if (MessageBox.Show(this, mergeConflictIsSubmodule.Text, mergeConflictIsSubmoduleCaption.Text, MessageBoxButtons.YesNo) == DialogResult.Yes)
                            {
                                stageFile(filename);
                                Initialize();
                            }
                            return;
                        }
                    }*/
                    var submoduleConfig = new ConfigFile(Settings.WorkingDir + ".gitmodules");
                    if (submoduleConfig.GetConfigSections().Any(configSection => configSection.GetValue("path").Trim().Equals(filename.Trim())))
                    {
                        if (MessageBox.Show(this, mergeConflictIsSubmodule.Text, mergeConflictIsSubmoduleCaption.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
                        {
                            stageFile(filename);
                        }
                        return;
                    }
                    //END: REPLACED WITH FASTER, BUT DIRTIER SUBMODULE CHECK
                }

                string arguments = mergetoolCmd;

                if (CheckForLocalRevision(filename) &&
                    CheckForRemoteRevision(filename))
                {
                    if (TryMergeWithScript(filename, filenames[0], filenames[2], filenames[1]))
                    {
                        Cursor.Current = Cursors.Default;
                        return;
                    }

                    if (FileHelper.IsBinaryFile(filename))
                    {
                        if (MessageBox.Show(this, string.Format(fileIsBinary.Text, mergetool), _binaryFileWarningCaption.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.No)
                        {
                            BinairyFilesChooseLocalBaseRemote(filename);
                            return;
                        }
                    }

                    //Check if there is a base file. If not, ask user to fall back to 2-way merge.
                    //git doesn't support 2-way merge, but we can try to adjust attributes to fix this.
                    //For kdiff3 this is easy; just remove the 3rd file from the arguments. Since the
                    //filenames are quoted, this takes a little extra effort. We need to remove these
                    //quotes also. For tortoise and araxis a little bit more magic is needed.
                    if (filenames[0] == null)
                    {
                        DialogResult result = MessageBox.Show(this, string.Format(noBaseRevision.Text, filename), _noBaseFileMergeCaption.Text, MessageBoxButtons.YesNoCancel);
                        if (result == DialogResult.Yes)
                        {
                            arguments = arguments.Replace("-merge -3", "-merge");
                            arguments = arguments.Replace("/base:\"$BASE\"", "");
                            arguments = arguments.Replace("/mine:\"$LOCAL\"", "/base:\"$LOCAL\"");
                            arguments = arguments.Replace("\"$BASE\"", "");
                        }

                        if (result == DialogResult.Cancel)
                        {
                            return;
                        }
                    }

                    arguments = arguments.Replace("$BASE", filenames[0]);
                    arguments = arguments.Replace("$LOCAL", filenames[1]);
                    arguments = arguments.Replace("$REMOTE", filenames[2]);
                    arguments = arguments.Replace("$MERGED", filename + "");

                    //get timestamp of file before merge. This is an extra check to verify if merge was successful
                    DateTime lastWriteTimeBeforeMerge = DateTime.Now;
                    if (File.Exists(Settings.WorkingDir + filename))
                        lastWriteTimeBeforeMerge = File.GetLastWriteTime(Settings.WorkingDir + filename);

                    int exitCode;
                    Settings.Module.RunCmd(mergetoolPath, "" + arguments + "", out exitCode);

                    DateTime lastWriteTimeAfterMerge = lastWriteTimeBeforeMerge;
                    if (File.Exists(Settings.WorkingDir + filename))
                        lastWriteTimeAfterMerge = File.GetLastWriteTime(Settings.WorkingDir + filename);

                    //Check exitcode AND timestamp of the file. If exitcode is success and
                    //time timestamp is changed, we are pretty sure the merge was done.
                    if (exitCode == 0 && lastWriteTimeBeforeMerge != lastWriteTimeAfterMerge)
                    {
                        stageFile(filename);
                    }

                    //If the exitcode is 1, but the file is changed, ask if the merge conflict is solved.
                    //If the exitcode is 0, but the file is not changed, ask if the merge conflict is solved.
                    if ((exitCode == 1 && lastWriteTimeBeforeMerge != lastWriteTimeAfterMerge) ||
                        (exitCode == 0 && lastWriteTimeBeforeMerge == lastWriteTimeAfterMerge))
                    {
                        if (MessageBox.Show(this, askMergeConflictSolved.Text, askMergeConflictSolvedCaption.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            stageFile(filename);
                        }
                    }
                }
            }
            finally
            {
                if (filenames[0] != null && File.Exists(filenames[0])) File.Delete(filenames[0]);
                if (filenames[1] != null && File.Exists(filenames[1])) File.Delete(filenames[1]);
                if (filenames[2] != null && File.Exists(filenames[2])) File.Delete(filenames[2]);
                Cursor.Current = Cursors.Default;
                Initialize();
            }
        }
Ejemplo n.º 3
0
        public static IEnumerable<ReleaseVersion> Parse(string versionsStr)
        {
            ConfigFile cfg = new ConfigFile("", true);
            cfg.LoadFromString(versionsStr);
            var sections = cfg.GetConfigSections("Version");

            return sections.Select(FromSection).Where(version => version != null);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// This is a faster function to get the names of all submodules then the 
        /// GetSubmodules() function. The command @git submodule is very slow.
        /// </summary>
        public static IList<string> GetSubmodulesNames()
        {
            IList<string> submodulesNames = new List<string>();
            var configFile = new ConfigFile(Settings.WorkingDir + ".gitmodules");
            foreach (ConfigSection configSection in configFile.GetConfigSections())
            {
                submodulesNames.Add(configSection.SubSection);
            }

            return submodulesNames;
        }
Ejemplo n.º 5
0
        public string FindGitSuperprojectPath(out string submoduleName)
        {
            submoduleName = null;
            if (String.IsNullOrEmpty(_workingdir))
                return null;

            string superprojectPath = null;

            string currentPath = Path.GetDirectoryName(_workingdir); // remove last slash
            if (!string.IsNullOrEmpty(currentPath))
            {
                string path = Path.GetDirectoryName(currentPath);
                if (!string.IsNullOrEmpty(path))
                {
                    for (int i = 0; i < 3; i++)
                    {
                        if (File.Exists(path + Settings.PathSeparator.ToString() + ".gitmodules") &&
                            ValidWorkingDir(path + Settings.PathSeparator.ToString()))
                        {
                            superprojectPath = path + Settings.PathSeparator.ToString();
                            break;
                        }
                        // Check upper directory
                        path = Path.GetDirectoryName(path);
                    }
                }
            }

            if (File.Exists(_workingdir + ".git") &&
                superprojectPath == null)
            {
                var lines = File.ReadAllLines(_workingdir + ".git");
                foreach (string line in lines)
                {
                    if (line.StartsWith("gitdir:"))
                    {
                        string gitpath = line.Substring(7).Trim();
                        int pos = gitpath.IndexOf("/.git/");
                        if (pos != -1)
                        {
                            gitpath = gitpath.Substring(0, pos + 1).Replace('/', '\\');
                            gitpath = Path.GetFullPath(_workingdir + gitpath);
                            if (File.Exists(gitpath + ".gitmodules") && ValidWorkingDir(gitpath))
                                superprojectPath = gitpath;
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(superprojectPath))
            {
                var localPath = currentPath.Substring(superprojectPath.Length);
                var configFile = new ConfigFile(superprojectPath + ".gitmodules", true);
                foreach (ConfigSection configSection in configFile.GetConfigSections())
                {
                    if (configSection.GetPathValue("path") == FixPath(localPath))
                    {
                        submoduleName = configSection.SubSection;
                        return superprojectPath;
                    }
                }
            }

            return null;
        }
Ejemplo n.º 6
0
 /// <summary>
 /// This is a faster function to get the names of all submodules then the 
 /// GetSubmodules() function. The command @git submodule is very slow.
 /// </summary>
 public IList<string> GetSubmodulesNames()
 {
     var configFile = new ConfigFile(_workingdir + ".gitmodules");
     return configFile.GetConfigSections().Select(configSection => configSection.SubSection).ToList();
 }
Ejemplo n.º 7
0
        /// <summary>
        /// This is a faster function to get the names of all submodules then the 
        /// GetSubmodules() function. The command @git submodule is very slow.
        /// </summary>
        public IList<string> GetSubmodulesNames()
        {
            IList<string> submodulesNames = new List<string>();
            ConfigFile configFile = new ConfigFile(Settings.WorkingDir + ".gitmodules");
            foreach (ConfigSection configSection in configFile.GetConfigSections())
            {
                submodulesNames.Add(configSection.SubSection);
            }

            return submodulesNames;
            /*
            var submodules = RunCmd(Settings.GitCommand, "submodule status").Split('\n');

            IList<IGitSubmodule> submoduleList = new List<IGitSubmodule>();

            string lastLine = null;

            foreach (var submodule in submodules)
            {
                if (submodule.Length < 43)
                    continue;

                if (submodule.Equals(lastLine))
                    continue;

                lastLine = submodule;

                submoduleList.Add(CreateGitSubmodule(submodule));
            }

            return submoduleList;*/
        }
Ejemplo n.º 8
0
 public void TestRemoveSection()
 {
     { //TESTDATA
         //Write test config
         File.WriteAllText(GetConfigFileName(), GetDefaultConfigFileContent(), Encoding.UTF8);
     }
     ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);
     Assert.IsTrue(configFile.GetConfigSections().Count == 3);
     configFile.RemoveConfigSection("section1");
     Assert.IsTrue(configFile.GetConfigSections().Count == 2);
 }
        private void ConflictedFiles_DoubleClick(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            if (ConflictedFiles.SelectedRows.Count != 1)
                return;

            string filename = GetFileName();
            string[] filenames = GitCommands.GitCommands.GetConflictedFiles(filename);

            if (Directory.Exists(Settings.WorkingDir + filename) && !File.Exists(Settings.WorkingDir + filename))
            {
                /* BEGIN REPLACED WITH FASTER, BUT DIRTIER SUBMODULE CHECK
                IList<IGitSubmodule> submodules = (new GitCommands.GitCommands()).GetSubmodules();
                foreach (IGitSubmodule submodule in submodules)
                {
                    if (submodule.LocalPath.Equals(filename))
                    {
                        if (MessageBox.Show(mergeConflictIsSubmodule.Text, mergeConflictIsSubmoduleCaption.Text, MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            stageFile(filename);
                            Initialize();
                        }
                        return;
                    }
                }*/
                ConfigFile submoduleConfig = new ConfigFile(Settings.WorkingDir + ".gitmodules");
                foreach (ConfigSection configSection in submoduleConfig.GetConfigSections())
                {
                    if (configSection.GetValue("path").Trim().Equals(filename.Trim()))
                    {
                        if (MessageBox.Show(mergeConflictIsSubmodule.Text, mergeConflictIsSubmoduleCaption.Text, MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            stageFile(filename);
                            Initialize();
                        }
                        return;
                    }
                }
                //END: REPLACED WITH FASTER, BUT DIRTIER SUBMODULE CHECK
            }

            bool file1 = File.Exists(filenames[0]);
            bool file2 = File.Exists(filenames[1]);
            bool file3 = File.Exists(filenames[2]);

            string arguments = mergetoolCmd;

            if (file1 && file2 && file3)
            {
                if (FileHelper.IsBinaryFile(filename))
                {
                    if (MessageBox.Show(string.Format(fileIsBinary.Text, mergetool)) == DialogResult.No)
                        return;
                }

                arguments = arguments.Replace("$BASE", filenames[0]);
                arguments = arguments.Replace("$LOCAL", filenames[1]);
                arguments = arguments.Replace("$REMOTE", filenames[2]);
                arguments = arguments.Replace("$MERGED", filename + "");

                GitCommands.GitCommands.RunCmd(mergetoolPath, "" + arguments + "");

                if (MessageBox.Show(askMergeConflictSolved.Text, askMergeConflictSolvedCaption.Text, MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    stageFile(filename);
                    Initialize();
                }
            }
            else
            {
                FormModifiedDeletedCreated frm = new FormModifiedDeletedCreated();
                if ((file1 && file2 && !file3) || (file1 && !file2 && file3))
                {
                    frm.Label.Text = useModifiedOrDeletedFile.Text;
                    frm.Created.Text = modifiedButton.Text;
                }
                else
                    if (!file1)
                    {
                        frm.Label.Text = useCreatedOrDeletedFile.Text;
                    }
                    else
                    {
                        if (File.Exists(filenames[0]))
                            File.Delete(filenames[0]);
                        if (File.Exists(filenames[1]))
                            File.Delete(filenames[1]);
                        if (File.Exists(filenames[2]))
                            File.Delete(filenames[2]);

                        Directory.SetCurrentDirectory(GitCommands.Settings.WorkingDir);
                        GitCommands.GitCommands.RunRealCmd(GitCommands.Settings.GitCommand, "mergetool \"" + filename + "\"");
                        Initialize();
                        return;
                    }

                frm.ShowDialog();

                if (frm.Aborted)
                {
                    if (File.Exists(filenames[0]))
                        File.Delete(filenames[0]);
                    if (File.Exists(filenames[1]))
                        File.Delete(filenames[1]);
                    if (File.Exists(filenames[2]))
                        File.Delete(filenames[2]);
                    return;
                }
                else
                    if (frm.Delete)
                        GitCommands.GitCommands.RunCmd(Settings.GitCommand, "rm -- \"" + filename + "\"");
                    else
                        if (!frm.Delete)
                            stageFile(filename);

                Initialize();
            }

            if (File.Exists(filenames[0]))
                File.Delete(filenames[0]);
            if (File.Exists(filenames[1]))
                File.Delete(filenames[1]);
            if (File.Exists(filenames[2]))
                File.Delete(filenames[2]);
            Cursor.Current = Cursors.Default;
        }