示例#1
0
        private void BuildChangeSections(Commit commit)
        {
            int    lastIndexFileLine = 0;
            Stream indexFileContent;
            string indexFilePath = UniGitPathHelper.Combine(gitManager.GetCurrentRepoPath(), localPath);

            if (File.Exists(indexFilePath))
            {
                indexFileContent = File.OpenRead(indexFilePath);
            }
            else
            {
                indexFileContent = new MemoryStream();
            }

            StreamReader indexFileReader = new StreamReader(indexFileContent);

            var lines = GetLines(commit);

            try
            {
                ProcessChanges(lines, indexFileReader, ref lastIndexFileLine);
            }
            catch (Exception e)
            {
                logger.Log(LogType.Error, "There was a problem while loading changes");
                logger.LogException(e);
            }
            finally
            {
                indexFileContent.Dispose();
                indexFileReader.Dispose();
            }
        }
 public GitStatusSubModuleEntry(Submodule submodule)
 {
     path      = UniGitPathHelper.FixUnityPath(submodule.Path);
     url       = submodule.Url;
     workDirId = submodule.WorkDirCommitId.Sha;
     status    = submodule.RetrieveStatus();
 }
示例#3
0
        public IEnumerable <string> GetPathWithMeta(string path)
        {
            if (UniGitPathHelper.IsMetaPath(path))
            {
                string assetPath = AssetPathFromMeta(path);
                yield return(path);

                //if the asset belonging to the meta file is a folder just return the meta
                if (IsDirectory(assetPath))
                {
                    yield break;
                }
                if (!string.IsNullOrEmpty(assetPath))
                {
                    yield return(assetPath);
                }
            }
            else
            {
                string metaPath = MetaPathFromAsset(path);
                //if the path is a directory then return only it's meta path
                if (IsDirectory(path))
                {
                    yield return(metaPath);

                    yield break;
                }
                if (!string.IsNullOrEmpty(metaPath))
                {
                    yield return(path);

                    yield return(metaPath);
                }
            }
        }
示例#4
0
    public IEnumerator RepositoryHandlesLockedFileWhenWithIgnoreStatus()
    {
        File.AppendAllText(injectionHelper.GetInstance <GitInitializer>().GitIgnoreFilePath, "testFile.txt");
        string lockedFilePathName = "testFile.txt";
        string lockedFilePath     = UniGitPathHelper.Combine(gitManager.GetCurrentRepoPath(), lockedFilePathName);

        using (var lockFileStream = File.CreateText(lockedFilePath))
        {
            lockFileStream.WriteLine("This is a locked test file");
        }
        injectionHelper.Bind <GitProjectOverlay>().WithArguments(new InjectionArgument("cullNonAssetPaths", false));
        var projectOverlays = injectionHelper.GetInstance <GitProjectOverlay>();
        var prefs           = injectionHelper.GetInstance <IGitPrefs>();

        prefs.SetBool(GitProjectOverlay.ForceUpdateKey, true);

        Assert.IsTrue(File.Exists(lockedFilePath));
        GitCommands.Stage(gitManager.Repository, lockedFilePathName);
        FileStream lockedFileStream = new FileStream(lockedFilePath, FileMode.Open, FileAccess.Read, FileShare.None);

        try
        {
            gitManager.MarkDirty();
            yield return(null);

            Assert.AreEqual(FileStatus.Ignored, projectOverlays.StatusTree.GetStatus(lockedFilePathName).State);
        }
        finally
        {
            lockedFileStream.Dispose();
        }
    }
示例#5
0
        public void ShowChooseMainRepositoryPathPopup(EditorWindow context = null)
        {
            var rootProjectPath = paths.ProjectPath;

            var repoPath = EditorUtility.OpenFolderPanel("Repository Path", rootProjectPath, "");

            if (string.IsNullOrEmpty(repoPath))
            {
                return;
            }

            bool isRootPath    = UniGitPathHelper.PathsEqual(repoPath, rootProjectPath);
            bool isChildOfRoot = UniGitPathHelper.IsSubDirectoryOf(repoPath, rootProjectPath);

            if (isRootPath || isChildOfRoot)
            {
                if (isRootPath)
                {
                    EditorPrefs.DeleteKey(UniGitLoader.RepoPathKey);
                }
                else
                {
                    string localPath = repoPath.Replace(rootProjectPath + UniGitPathHelper.UnityDeirectorySeparatorChar, "");
                    EditorPrefs.SetString(UniGitLoader.RepoPathKey, localPath);
                }

                paths.SetRepoPath(repoPath);
                initializer.RecompileSoft();
            }
            else if (context)
            {
                context.ShowNotification(new GUIContent("Invalid Path !"));
            }
        }
示例#6
0
        private SelectionId CreateSelectionId(StatusListEntry entry)
        {
            string projectPath = gitManager.ToProjectPath(entry.LocalPath);
            string guid        = UniGitPathHelper.IsPathInAssetFolder(projectPath) ? AssetDatabase.AssetPathToGUID(projectPath) : projectPath;

            return(string.IsNullOrEmpty(guid) ? new SelectionId(projectPath, true) : new SelectionId(guid, false));
        }
示例#7
0
        internal static string GetFullPath(string fileName)
        {
            if (File.Exists(fileName))
            {
                return(Path.GetFullPath(fileName));
            }

            var variables = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Machine);

            if (variables == null)
            {
                return(null);
            }
            var values = variables.Split(';');

            foreach (var path in values)
            {
                var fullPath = UniGitPathHelper.Combine(path, fileName);
                if (File.Exists(fullPath))
                {
                    return(fullPath);
                }
            }
            return(null);
        }
示例#8
0
 public string GetCommitMessageFilePath(string subModule)
 {
     if (!string.IsNullOrEmpty(subModule))
     {
         return(UniGitPathHelper.Combine(paths.GitPath, "UniGit", "Settings", $"CommitMessage_{UniGitPathHelper.GetFriendlyNameFromPath(subModule)}.txt"));
     }
     return(UniGitPathHelper.Combine(paths.GitPath, "UniGit", "Settings", "CommitMessage.txt"));
 }
示例#9
0
 public static string AssetPathFromMeta(string metaPath)
 {
     if (UniGitPathHelper.IsMetaPath(metaPath))
     {
         return(metaPath.Substring(0, metaPath.Length - 5));
     }
     return(metaPath);
 }
示例#10
0
 public string GetCurrentDotGitFolder()
 {
     if (inSubModule)
     {
         return(dotGitDirCached);
     }
     return(UniGitPathHelper.Combine(paths.RepoPath, ".git"));
 }
示例#11
0
 /// <summary>
 /// If in sub module returns it's repo path
 /// </summary>
 /// <returns></returns>
 public string GetCurrentRepoPath()
 {
     if (inSubModule)
     {
         return(UniGitPathHelper.Combine(paths.RepoPath, gitSettings.ActiveSubModule));
     }
     return(paths.RepoPath);
 }
示例#12
0
 public bool IsEmptyFolderMeta(string path)
 {
     if (UniGitPathHelper.IsMetaPath(path))
     {
         return(IsEmptyFolder(path.Substring(0, path.Length - 5)));
     }
     return(false);
 }
示例#13
0
 public void SwitchToSubModule(string path)
 {
     if (gitSettings.ActiveSubModule != path && Repository.IsValid(UniGitPathHelper.Combine(paths.RepoProjectRelativePath, path)))
     {
         gitSettings.ActiveSubModule = path;
         gitSettings.MarkDirty();
         MarkDirty(true);
     }
 }
示例#14
0
        public bool CanOpenLine(string stackTrace)
        {
            var match = lineAndNumberRegex.Match(stackTrace);

            if (match.Success)
            {
                var path = match.Groups[2].Value.Replace(Path.DirectorySeparatorChar, UniGitPathHelper.UnityDeirectorySeparatorChar).Trim();
                return(UniGitPathHelper.IsPathInAssetFolder(path) && !string.IsNullOrEmpty(AssetDatabase.AssetPathToGUID(path)));
            }
            return(false);
        }
示例#15
0
 public string ToLocalPath(string projectPath)
 {
     if (!string.IsNullOrEmpty(paths.RepoProjectRelativePath))
     {
         projectPath = UniGitPathHelper.SubtractDirectory(projectPath, UniGitPathHelper.ToUnityPath(paths.RepoProjectRelativePath));
     }
     if (inSubModule)
     {
         return(UniGitPathHelper.SubtractDirectory(projectPath, gitSettings.ActiveSubModule));
     }
     return(projectPath);
 }
示例#16
0
        public void SaveTracking()
        {
            using (StreamWriter file = File.CreateText(UniGitPathHelper.Combine(gitManager.GetCurrentRepoPath(), ".gitattributes")))
            {
                foreach (var info in trackedInfo)
                {
                    file.WriteLine(info.ToString());
                }
            }

            Update();
        }
示例#17
0
        public string ToProjectPath(string localPath)
        {
            if (!string.IsNullOrEmpty(paths.RepoProjectRelativePath))
            {
                localPath = UniGitPathHelper.Combine(paths.RepoProjectRelativePath, localPath);
            }

            if (inSubModule)
            {
                return(UniGitPathHelper.Combine(gitSettings.ActiveSubModule, localPath));
            }
            return(localPath);
        }
示例#18
0
        public void Update()
        {
            RegisterFilter();

            if (File.Exists(UniGitPathHelper.Combine(gitManager.GetCurrentRepoPath(), ".gitattributes")))
            {
                using (TextReader file = File.OpenText(UniGitPathHelper.Combine(gitManager.GetCurrentRepoPath(), ".gitattributes")))
                {
                    trackedInfo = file.ReadToEnd().Split(UniGitPathHelper.NewLineChar).Select(GitLfsTrackedInfo.Parse).Where(l => l != null).ToArray();
                }
            }

            UpdateInitilized();
        }
示例#19
0
        public bool Initialize()
        {
            string output = GitHelper.RunExeOutput(gitManager.GetCurrentRepoPath(), "git-lfs", "install", null);

            if (!Directory.Exists(UniGitPathHelper.Combine(gitManager.GetCurrentDotGitFolder(), "lfs")))
            {
                logger.Log(LogType.Error, "Git-LFS install failed! (Try manually)");
                logger.Log(LogType.Error, output);
                return(false);
            }
            EditorUtility.DisplayDialog("Git LFS Initialized", output, "Ok");
            UpdateInitilized();
            return(true);
        }
示例#20
0
        internal void DeleteAsset(string localPath)
        {
            string projectPath = gitManager.ToProjectPath(localPath);

            if (UniGitPathHelper.IsPathInAssetFolder(projectPath))
            {
                AssetDatabase.DeleteAsset(projectPath);
            }
            else
            {
                File.Delete(projectPath);
                gitManager.MarkDirty(localPath);
            }
        }
示例#21
0
        public bool IsDirectory(string localPath)
        {
            string projectPath = ToProjectPath(localPath);

            if (IsSubModule(ToProjectPath(localPath)))
            {
                return(false);
            }
            if (Path.IsPathRooted(projectPath))
            {
                return(Directory.Exists(UniGitPathHelper.Combine(paths.RepoPath, projectPath)));
            }
            return(Directory.Exists(projectPath));
        }
示例#22
0
        private void LoadFileLines()
        {
            var asset = AssetDatabase.LoadAssetAtPath <MonoScript>(manager.ToProjectPath(blameLocalPath));

            if (asset != null)
            {
                lines = asset.text.Split(new[] { UniGitPathHelper.NewLineChar }, StringSplitOptions.None);
            }
            else
            {
                lines = File.ReadAllLines(UniGitPathHelper.Combine(manager.GetCurrentRepoPath(), blameLocalPath));
            }

            commitLog = manager.Repository.Commits.QueryBy(blameLocalPath).Where(e => blameHunk.Any(h => h.FinalCommit.Sha == e.Commit.Sha)).ToArray();
        }
示例#23
0
 public void MarkDirty(IEnumerable <string> paths)
 {
     foreach (var path in paths)
     {
         string fixedPath = UniGitPathHelper.FixUnityPath(path);
         if (IsDirectory(fixedPath))
         {
             continue;
         }
         if (!gitData.DirtyFilesQueue.Contains(fixedPath))
         {
             gitData.DirtyFilesQueue.Add(fixedPath);
         }
     }
 }
示例#24
0
        public void SetRepoPath(string repoPath)
        {
            this.RepoPath = repoPath;

            if (!UniGitPathHelper.PathsEqual(repoPath, ProjectPath))
            {
                RepoProjectRelativePath = UniGitPathHelper.SubtractDirectory(repoPath, ProjectPath);
            }

            SettingsFolderPath  = UniGitPathHelper.Combine(repoPath, ".git", "UniGit");
            SettingsFilePath    = UniGitPathHelper.Combine(SettingsFolderPath, "Settings.json");
            LogsFolderPath      = SettingsFolderPath;
            LogsFilePath        = UniGitPathHelper.Combine(LogsFolderPath, "log.txt");
            CredentialsFilePath = UniGitPathHelper.Combine(SettingsFolderPath, "Credentials.json");
            GitPath             = UniGitPathHelper.Combine(RepoPath, ".git");
        }
示例#25
0
        internal void Add(GitStatusEntry entry, IComparer <StatusListEntry> sorter)
        {
            StatusListEntry statusEntry;

            if (UniGitPathHelper.IsMetaPath(entry.LocalPath))
            {
                string mainAssetPath = GitManager.AssetPathFromMeta(entry.LocalPath);
                if (!gitSettings.ShowEmptyFolders && gitManager.IsEmptyFolder(mainAssetPath))
                {
                    return;
                }

                int index = entries.FindIndex(e => e.LocalPath == mainAssetPath);
                if (index >= 0)
                {
                    StatusListEntry ent = entries[index];
                    ent.MetaChange |= MetaChangeEnum.Meta;
                    ent.State      |= entry.Status;
                    entries[index]  = ent;
                    return;
                }

                statusEntry = new StatusListEntry(mainAssetPath, entry.Status, MetaChangeEnum.Meta, CalculateFlags(entry));
            }
            else
            {
                int index = entries.FindIndex(e => e.LocalPath == entry.LocalPath);
                if (index >= 0)
                {
                    StatusListEntry ent = entries[index];
                    ent.State     |= entry.Status;
                    entries[index] = ent;
                    return;
                }

                statusEntry = new StatusListEntry(entry.LocalPath, entry.Status, MetaChangeEnum.Object, CalculateFlags(entry));
            }

            if (sorter != null)
            {
                AddSorted(statusEntry, sorter);
            }
            else
            {
                entries.Add(statusEntry);
            }
        }
示例#26
0
 public bool CheckoutNotifyHandler(string path, CheckoutNotifyFlags notifyFlags)
 {
     if (gitSettings.CreateFoldersForDriftingMeta)
     {
         if (UniGitPathHelper.IsMetaPath(path))
         {
             string assetPath       = AssetPathFromMeta(path);
             string rootedAssetPath = Path.Combine(paths.RepoPath, assetPath);
             if (!Path.HasExtension(assetPath) && !File.Exists(rootedAssetPath) && !Directory.Exists(rootedAssetPath))
             {
                 Directory.CreateDirectory(rootedAssetPath);
                 logger.LogFormat(LogType.Log, "Folder '{0}' created for drifting '{1}' file.", assetPath, path);
             }
         }
     }
     return(true);
 }
示例#27
0
 private void DrawTreeEntry(Tree tree, int depth)
 {
     foreach (var file in tree)
     {
         if (file.TargetType == TreeEntryTargetType.Tree)
         {
             EditorGUI.indentLevel = depth;
             EditorGUILayout.LabelField(Path.GetFileName(file.Path));
             DrawTreeEntry(file.Target as Tree, depth + 1);
         }
         else if (!UniGitPathHelper.IsMetaPath(file.Path))
         {
             EditorGUI.indentLevel = depth;
             EditorGUILayout.LabelField(file.Path);
         }
     }
 }
示例#28
0
 public void RemoveRange(string[] paths)
 {
     foreach (var path in paths)
     {
         if (UniGitPathHelper.IsMetaPath(path))
         {
             var assetPath = GitManager.AssetPathFromMeta(path);
             for (int i = entries.Count - 1; i >= 0; i--)
             {
                 var entry = entries[i];
                 if (entry.LocalPath == assetPath)
                 {
                     if (entry.MetaChange.HasFlag(MetaChangeEnum.Object))
                     {
                         entry.MetaChange = entry.MetaChange.ClearFlags(MetaChangeEnum.Meta);
                         entries[i]       = entry;
                     }
                     else
                     {
                         entries.RemoveAt(i);
                     }
                 }
             }
         }
         else
         {
             for (int i = entries.Count - 1; i >= 0; i--)
             {
                 var entry = entries[i];
                 if (entry.LocalPath == path)
                 {
                     if (entry.MetaChange.HasFlag(MetaChangeEnum.Meta))
                     {
                         entry.MetaChange = entry.MetaChange.ClearFlags(MetaChangeEnum.Object);
                         entries[i]       = entry;
                     }
                     else
                     {
                         entries.RemoveAt(i);
                     }
                 }
             }
         }
     }
 }
示例#29
0
        public override void OnGUI(Rect rect)
        {
            EditorGUILayout.Space();
            float msgHeight = commitMessageStyle.CalcHeight(GitGUI.GetTempContent(commit.Message), rect.width);

            scroll = EditorGUILayout.BeginScrollView(scroll);
            EditorGUILayout.LabelField(GitGUI.GetTempContent(commit.Message), commitMessageStyle, GUILayout.Height(msgHeight));
            if (changes != null)
            {
                foreach (var change in changes)
                {
                    //EditorGUILayout.BeginHorizontal();
                    //GUILayout.Label(change.Status.ToString(), "AssetLabel");
                    EditorGUILayout.BeginHorizontal("ProjectBrowserHeaderBgTop");
                    GUILayout.Label(new GUIContent(gitOverlay.GetDiffTypeIcon(change.Status, true))
                    {
                        tooltip = change.Status.ToString()
                    }, GUILayout.Width(16));
                    GUILayout.Space(8);
                    string[] pathChunks = change.Path.Split(Path.DirectorySeparatorChar);
                    for (int i = 0; i < pathChunks.Length; i++)
                    {
                        string chunk = pathChunks[i];
                        if (GUILayout.Button(GitGUI.GetTempContent(chunk), GitGUI.Styles.BreadcrumMid))
                        {
                            string assetPath = string.Join("/", pathChunks, 0, i + 1);
                            if (UniGitPathHelper.IsMetaPath(assetPath))
                            {
                                assetPath = GitManager.AssetPathFromMeta(assetPath);
                            }
                            ShowContextMenuForElement(change.Path, assetPath);
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }
            else
            {
                DrawTreeEntry(commitTree, 0);
            }
            EditorGUILayout.Space();
            EditorGUILayout.EndScrollView();
        }
示例#30
0
        private Repository CreateRepository(string activeModule)
        {
            var mainRepository = new Repository(paths.RepoPath);

            if (!string.IsNullOrEmpty(activeModule))
            {
                var subModule = mainRepository.Submodules[activeModule];
                if (subModule != null && Repository.IsValid(UniGitPathHelper.Combine(paths.RepoProjectRelativePath, subModule.Path)))
                {
                    var subModuleRepo = new Repository(UniGitPathHelper.Combine(paths.RepoProjectRelativePath, subModule.Path));
                    mainRepository.Dispose();
                    inSubModule     = true;
                    dotGitDirCached = subModuleRepo.Info.Path;
                    return(subModuleRepo);
                }
            }
            inSubModule     = false;
            dotGitDirCached = mainRepository.Info.Path;
            return(mainRepository);
        }