상속: IGitModule
예제 #1
0
        /// <summary>
        /// Gets the commit info for submodule.
        /// </summary>
        public static CommitData GetCommitData(GitModule module, string sha1, ref string error)
        {
            if (module == null)
                throw new ArgumentNullException("module");
            if (sha1 == null)
                throw new ArgumentNullException("sha1");

            //Do not cache this command, since notes can be added
            string arguments = string.Format(CultureInfo.InvariantCulture,
                    "log -1 --pretty=\"format:"+LogFormat+"\" {0}", sha1);
            var info = module.RunGitCmd(arguments, GitModule.LosslessEncoding);

            if (info.Trim().StartsWith("fatal"))
            {
                error = "Cannot find commit " + sha1;
                return null;
            }

            int index = info.IndexOf(sha1) + sha1.Length;

            if (index < 0)
            {
                error = "Cannot find commit " + sha1;
                return null;
            }
            if (index >= info.Length)
            {
                error = info;
                return null;
            }

            CommitData commitInformation = CreateFromFormatedData(info, module);

            return commitInformation;
        }
예제 #2
0
 public static bool IsBinaryFile(GitModule aModule, string fileName)
 {
     var t = IsBinaryAccordingToGitAttributes(aModule, fileName);
     if (t.HasValue)
         return t.Value;
     return HasMatchingExtension(BinaryExtensions, fileName);
 }
예제 #3
0
        public GitRef(GitModule module, string guid, string completeName, string remote)
        {
            Module = module;
            Guid = guid;
            Selected = false;
            CompleteName = completeName;
            Remote = remote;
            if (CompleteName.StartsWith("refs/heads/"))
            {
                IsHead = true;
            }
            else if (CompleteName.StartsWith("refs/tags/"))
            {
                IsTag = true;
            }
            else if (CompleteName.StartsWith("refs/remotes/"))
            {
                IsRemote = true;
            }
            else if (CompleteName.StartsWith("refs/bisect/"))
            {
                IsBisect = true;
            }

            ParseName();

            _remoteSettingName = String.Format("branch.{0}.remote", Name);
            _mergeSettingName = String.Format("branch.{0}.merge", Name);
        }
        public void GetSubmoduleNamesFromDiffTest()
        {
            GitModule testModule = new GitModule("D:\\Test\\SuperProject");

            // Submodule name without spaces in the name

            string text = "diff --git a/Externals/conemu-inside b/Externals/conemu-inside\nindex a17ea0c..b5a3d51 160000\n--- a/Externals/conemu-inside\n+++ b/Externals/conemu-inside\n@@ -1 +1 @@\n-Subproject commit a17ea0c8ebe9d8cd7e634ba44559adffe633c11d\n+Subproject commit b5a3d51777c85a9aeee534c382b5ccbb86b485d3\n";
            string fileName = "Externals/conemu-inside";

            GitSubmoduleStatus status = GitCommandHelpers.GetSubmoduleStatus(text, testModule, fileName);

            Assert.AreEqual(status.Commit, "b5a3d51777c85a9aeee534c382b5ccbb86b485d3");
            Assert.AreEqual(status.Name, fileName);
            Assert.AreEqual(status.OldCommit, "a17ea0c8ebe9d8cd7e634ba44559adffe633c11d");
            Assert.AreEqual(status.OldName, fileName);

            // Submodule name with spaces in the name

            text = "diff --git a/Assets/Core/Vehicle Physics core assets b/Assets/Core/Vehicle Physics core assets\nindex 2fb8851..0cc457d 160000\n--- a/Assets/Core/Vehicle Physics core assets\t\n+++ b/Assets/Core/Vehicle Physics core assets\t\n@@ -1 +1 @@\n-Subproject commit 2fb88514cfdc37a2708c24f71eca71c424b8d402\n+Subproject commit 0cc457d030e92f804569407c7cd39893320f9740\n";
            fileName = "Assets/Core/Vehicle Physics core assets";

            status = GitCommandHelpers.GetSubmoduleStatus(text, testModule, fileName);

            Assert.AreEqual(status.Commit, "0cc457d030e92f804569407c7cd39893320f9740");
            Assert.AreEqual(status.Name, fileName);
            Assert.AreEqual(status.OldCommit, "2fb88514cfdc37a2708c24f71eca71c424b8d402");
            Assert.AreEqual(status.OldName, fileName);
        }
예제 #5
0
        public static IRepositoryHostPlugin TryGetGitHosterForModule(GitModule aModule)
        {
            if (!aModule.ValidWorkingDir())
                return null;

            return GitHosters.FirstOrDefault(gitHoster => gitHoster.GitModuleIsRelevantToMe(aModule));
        }
예제 #6
0
 public GitUICommands(GitModule module)
 {
     Module = module;
     RepoChangedNotifier = new ActionNotifier(
         () => InvokeEvent(null, PostRepositoryChanged));
     Notifications = NotificationManager.Get(this);
 }
예제 #7
0
        private void InitClick(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Directory.Text))
            {
                MessageBox.Show(this, _chooseDirectory.Text,_chooseDirectoryCaption.Text);
                return;
            }

            if (File.Exists(Directory.Text))
            {
                MessageBox.Show(this, _chooseDirectoryNotFile.Text,_chooseDirectoryNotFileCaption.Text);
                return;
            }

            GitModule module = new GitModule(Directory.Text);

            if (!System.IO.Directory.Exists(module.WorkingDir))
                System.IO.Directory.CreateDirectory(module.WorkingDir);

            MessageBox.Show(this, module.Init(Central.Checked, Central.Checked), _initMsgBoxCaption.Text);

            if (GitModuleChanged != null)
                GitModuleChanged(this, new GitModuleEventArgs(module));

            Repositories.AddMostRecentRepository(Directory.Text);

            Close();
        }
예제 #8
0
        /// <summary>
        /// Gets branches which contain the given commit.
        /// If both local and remote branches are requested, remote branches are prefixed with "remotes/"
        /// (as returned by git branch -a)
        /// </summary>
        /// <param name="sha1">The sha1.</param>
        /// <param name="getLocal">Pass true to include local branches</param>
        /// <param name="getRemote">Pass true to include remote branches</param>
        /// <returns></returns>
        public static IEnumerable<string> GetAllBranchesWhichContainGivenCommit(GitModule module, string sha1, bool getLocal, bool getRemote)
        {
            string args = "--contains " + sha1;
            if (getRemote && getLocal)
                args = "-a "+args;
            else if (getRemote)
                args = "-r "+args;
            else if (!getLocal)
                return new string[]{};
            string info = module.RunGitCmd("branch " + args, GitModule.SystemEncoding);
            if (info.Trim().StartsWith("fatal") || info.Trim().StartsWith("error:"))
                return new List<string>();

            string[] result = info.Split(new[] { '\r', '\n', '*' }, StringSplitOptions.RemoveEmptyEntries);

            // Remove symlink targets as in "origin/HEAD -> origin/master"
            for (int i = 0; i < result.Length; i++)
            {
                string item = result[i].Trim();
                int idx;
                if (getRemote && ((idx = item.IndexOf(" ->")) >= 0))
                {
                    item = item.Substring(0, idx);
                }
                result[i] = item;
            }

            return result;
        }
        public static string GetSubmoduleText(GitModule superproject, string name, string hash)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("Submodule " + name);
            sb.AppendLine();
            GitModule module = superproject.GetSubmodule(name);
            if (module.IsValidGitWorkingDir())
            {
                string error = "";
                CommitData data = CommitData.GetCommitData(module, hash, ref error);
                if (data == null)
                {
                    sb.AppendLine("Commit hash:\t" + hash);
                    return sb.ToString();
                }

                string header = data.GetHeaderPlain();
                string body = "\n" + data.Body.Trim();
                sb.AppendLine(header);
                sb.Append(body);
            }
            else
                sb.AppendLine("Commit hash:\t" + hash);
            return sb.ToString();
        }
예제 #10
0
        public static bool RunScript(IWin32Window owner, GitModule aModule, string script, RevisionGrid revisionGrid)
        {
            if (string.IsNullOrEmpty(script))
                return false;

            ScriptInfo scriptInfo = ScriptManager.GetScript(script);

            if (scriptInfo == null)
            {
                MessageBox.Show(owner, "Cannot find script: " + script, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }

            if (string.IsNullOrEmpty(scriptInfo.Command))
                return false;

            string argument = scriptInfo.Arguments;
            foreach (string option in Options)
            {
                if (string.IsNullOrEmpty(argument) || !argument.Contains(option))
                    continue;
                if (!option.StartsWith("{s"))
                    continue;
                if (revisionGrid != null)
                    continue;
                MessageBox.Show(owner,
                    string.Format("Option {0} is only supported when started from revision grid.", option),
                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
            return RunScript(owner, aModule, scriptInfo, revisionGrid);
        }
예제 #11
0
 public void Execute(GitModule module)
 {
     if (Dto.Amend)
         Dto.Result = module.RunGitCmd("commit --amend -m \"" + Dto.Message + "\"");
     else
         Dto.Result = module.RunGitCmd("commit -m \"" + Dto.Message + "\"");
 }
예제 #12
0
        public CommonLogic(GitModule aModule)
        {
            Module = aModule;

            if (aModule != null)
            {
                var repoDistGlobalSettings = RepoDistSettings.CreateGlobal(false);
                var repoDistPulledSettings = RepoDistSettings.CreateDistributed(Module, false);
                var repoDistLocalSettings = RepoDistSettings.CreateLocal(Module, false);
                var repoDistEffectiveSettings = new RepoDistSettings(
                    new RepoDistSettings(repoDistGlobalSettings, repoDistPulledSettings.SettingsCache),
                    repoDistLocalSettings.SettingsCache);

                var configFileGlobalSettings = ConfigFileSettings.CreateGlobal(false);
                var configFileLocalSettings = ConfigFileSettings.CreateLocal(Module, false);
                var configFileEffectiveSettings = new ConfigFileSettings(configFileGlobalSettings, configFileLocalSettings.SettingsCache);

                RepoDistSettingsSet = new RepoDistSettingsSet(
                    repoDistEffectiveSettings,
                    repoDistLocalSettings,
                    repoDistPulledSettings,
                    repoDistGlobalSettings);

                ConfigFileSettingsSet = new ConfigFileSettingsSet(
                    configFileEffectiveSettings,
                    configFileLocalSettings,
                    configFileGlobalSettings);
            }
        }
예제 #13
0
        public FormDiff(GitModule module)
        {
            InitializeComponent();
            Translate();

            module_ = module;
            diffViewer.ExtraDiffArgumentsChanged += DiffViewerExtraDiffArgumentsChanged;
        }
        public void CheckIsCommitNewer(GitModule submodule)
        {
            if (submodule == null || !submodule.ValidWorkingDir())
                return;

            string baseCommit = submodule.GetMergeBase(Commit, OldCommit);
            IsCommitNewer = baseCommit == OldCommit;
        }
        public void GetAllBranchesWhichContainGivenCommitTestReturnsEmptyList()
        {
            var module = new GitModule("");
            var actualResult = module.GetAllBranchesWhichContainGivenCommit("fakesha1", false, false);

            Assert.IsNotNull(actualResult);
            Assert.IsTrue(!actualResult.Any());
        }
예제 #16
0
        public void CheckSubmoduleStatus(GitModule submodule)
        {
            Status = SubmoduleStatus.NewSubmodule;
            if (submodule == null)
                return;

            Status = submodule.CheckSubmoduleStatus(Commit, OldCommit);
        }
예제 #17
0
        public FormDiff(GitModule module, GitRevision revision)
        {
            InitializeComponent();
            Translate();

            module_ = module;
            RevisionGrid.SetSelectedRevision(revision);
        }
        public CommitData GetOldCommitData(GitModule submodule)
        {
            if (submodule == null || !submodule.ValidWorkingDir())
                return null;

            string error = "";
            return CommitData.GetCommitData(submodule, OldCommit, ref error);
        }
예제 #19
0
 public static new bool ShowDialog(IWin32Window owner, GitModule module, string arguments)
 {
     using (var formRemoteProcess = new FormRemoteProcess(module, arguments))
     {
         formRemoteProcess.ShowDialog(owner);
         return !formRemoteProcess.ErrorOccurred();
     }
 }
        private static void CheckWorkingDir(string path)
        {
            GitModule module = new GitModule(path);
            //Should not contain double slashes -> \\
            Assert.IsFalse(module.WorkingDir.Contains("\\\\"), "WorkingDir" + module.WorkingDir + "\n" + GetCurrentDir());

            //Should end with slash
            Assert.IsTrue(module.WorkingDir.EndsWith("\\"), "WorkingDir" + module.WorkingDir + "\n" + GetCurrentDir());
        }
예제 #21
0
        public void LoadModule(GitModule module)
        {
            if (UICommands != null && UICommands.Module == module)
            {
                return;
            }

            UICommands = new GitUICommands(module);
        }
예제 #22
0
 public static bool AbortCurrentAction(GitModule module)
 {
     if (ShowAbortMessage())
     {
         module.ResetHard("");
         return true;
     }
     return false;
 }
        public LocalSettingsSettingsPage(CommonLogic commonLogic, CheckSettingsLogic checkSettingsLogic, GitModule gitModule)
            : this()
        {
            _commonLogic = commonLogic;
            _checkSettingsLogic = checkSettingsLogic;
            _gitModule = gitModule;

            _commonLogic.FillEncodings(Local_FilesEncoding);
        }
        public FormMergeSubmodule(GitUICommands aCommands, string filename)
            : base(aCommands)
        {
            InitializeComponent();
            Translate();
            lbSubmodule.Text = filename;
            this.filename = filename;

            this.submodule = Module.GetSubmodule(filename);
        }
예제 #25
0
 public FormProcess(string process, string arguments, GitModule module, string input, bool useDialogSettings)
     : base(useDialogSettings)
 {
     ProcessCallback = processStart;
     AbortCallback = processAbort;
     ProcessString = process ?? Settings.GitCommand;
     WorkingDir = module == null ? Settings.WorkingDir : module.WorkingDir;
     ProcessArguments = arguments;
     Remote = "";
     ProcessInput = input;
 }
예제 #26
0
        private void FetchData()
        {
            Loading.Visible = true;

            CommitCount.Text = "";
            var dict = new Dictionary<string, HashSet<string>>();
            var items = CommitCounter.GroupAllCommitsByContributor().Item1;
            if (cbIncludeSubmodules.Checked)
            {
                IList<string> submodules = Settings.Module.GetSubmodulesNames();
                GitModule submodule = new GitModule();
                foreach (var submoduleName in submodules)
                {
                    submodule.WorkingDir = Settings.Module.WorkingDir + submoduleName + Settings.PathSeparator.ToString();
                    if (submodule.ValidWorkingDir())
                    {
                        var submoduleItems = CommitCounter.GroupAllCommitsByContributor(submodule).Item1;
                        foreach (var keyValuePair in submoduleItems)
                        {
                            if (!dict.ContainsKey(keyValuePair.Key))
                                dict.Add(keyValuePair.Key, new HashSet<string>());
                            dict[keyValuePair.Key].Add(submodule.SubmoduleName);
                            if (items.ContainsKey(keyValuePair.Key))
                                items[keyValuePair.Key] += keyValuePair.Value;
                            else
                                items.Add(keyValuePair.Key, keyValuePair.Value);
                        }
                    }
                }
            }

            var sortedItems = from pair in items
                        orderby pair.Value descending
                        select pair;

            foreach (var keyValuePair in sortedItems)
            {
                string submodulesList = "";
                if (dict.ContainsKey(keyValuePair.Key))
                {
                    var sub = dict[keyValuePair.Key];
                    if (sub.Count == 1)
                    {
                        foreach (var item in dict[keyValuePair.Key])
                            submodulesList = " [" + item + "]";
                    }
                    else
                        submodulesList = " [" + sub.Count.ToString() + " submodules]";
                }
                CommitCount.Text += string.Format("{0,6} - {1}{2}\r\n", keyValuePair.Value, keyValuePair.Key, submodulesList);
            }

            Loading.Visible = false;
        }
        /// <summary>
        /// Gets the commit info for module.
        /// </summary>
        /// <param name="module">Git module.</param>
        /// <param name="sha1">The sha1.</param>
        /// <returns></returns>
        public static CommitInformation GetCommitInfo(GitModule module, string sha1)
        {
            string error = "";
            CommitData data = CommitData.GetCommitData(module, sha1, ref error);
            if (data == null)
                return new CommitInformation(error, "");

            string header = data.GetHeader();
            string body = "\n" + WebUtility.HtmlEncode(data.Body.Trim());

            return new CommitInformation(header, body);
        }
예제 #28
0
 private void BranchDropDown(object sender, EventArgs e)
 {
     GitModule module = new GitModule(Directory.Text);
     Branch.DisplayMember = "Name";
     IList<GitRef> heads;
     if (module.IsValidGitWorkingDir())
         heads = module.GetRefs(false);
     else
         heads = new List<GitRef>();
     heads.Insert(0, GitRef.NoHead(module));
     Branch.DataSource = heads;
 }
예제 #29
0
        public static void RunEventScripts(GitModule aModule, ScriptEvent scriptEvent)
        {
            foreach (ScriptInfo scriptInfo in GetScripts())
                if (scriptInfo.Enabled && scriptInfo.OnEvent == scriptEvent)
                {
                    if (scriptInfo.AskConfirmation)
                        if (MessageBox.Show(String.Format("Do you want to execute '{0}'?", scriptInfo.Name), "Script", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                            continue;

                    ScriptRunner.RunScript(aModule, scriptInfo.Name, null);
                }
        }
예제 #30
0
        public static void SetCommitMessage(GitModule module, string commitMessageText)
        {
            if (String.IsNullOrEmpty(commitMessageText))
            {
                File.Delete(GetCommitMessagePath(module));
                return;
            }

            using (var textWriter = new StreamWriter(GetCommitMessagePath(module), false, module.CommitEncoding))
            {
                textWriter.Write(commitMessageText);
            }
        }