示例#1
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));
        }
示例#2
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);
        }
示例#3
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);
            }
        }
示例#4
0
            internal void Build(IEnumerable <GitStatusEntry> status, IEnumerable <GitStatusSubModuleEntry> subModules)
            {
                foreach (var entry in status)
                {
                    currentProjectPath = gitManager.ToProjectPath(entry.LocalPath);
                    currentPathArray   = currentProjectPath.Split('\\');
                    currentStatus      = !gitSettings.ShowEmptyFolders && gitManager.IsEmptyFolderMeta(currentProjectPath) ? FileStatus.Ignored : entry.Status;
                    if (cullNonAssetPaths && !UniGitPathHelper.IsPathInAssetFolder(currentProjectPath) && !UniGitPathHelper.IsPathInPackagesFolder(currentProjectPath))
                    {
                        continue;
                    }
                    AddRecursive(0, entries);
                }

                foreach (var module in subModules)
                {
                    currentPathArray       = UniGitPathHelper.Combine(paths.RepoProjectRelativePath, module.Path).Split('\\');
                    currentSubModuleStatus = module.Status;
                    AddSubModuleRecursive(0, entries);
                }
            }
示例#5
0
        private void CreateWatchers()
        {
            string rootedPath  = gitManager.GetCurrentRepoPath();
            string projectPath = rootedPath.Replace(paths.ProjectPath, "");

            if (!UniGitPathHelper.IsPathInAssetFolder(projectPath))
            {
                var mainFileWatcher = new FileSystemWatcher(rootedPath)
                {
                    InternalBufferSize    = 4,
                    EnableRaisingEvents   = gitSettings.TrackSystemFiles,
                    IncludeSubdirectories = false,
                    NotifyFilter          = NotifyFilters.FileName
                };
                fileWatchers.Add(mainFileWatcher);
                Subscribe(mainFileWatcher);

                var repoDirectoryInfo = new DirectoryInfo(rootedPath);
                foreach (var directory in repoDirectoryInfo.GetDirectories())
                {
                    if (!gitManager.Repository.Ignore.IsPathIgnored(directory.FullName) && ShouldTrackDirectory(directory))
                    {
                        var fileWatcher = new FileSystemWatcher(directory.FullName)
                        {
                            InternalBufferSize    = 4,
                            EnableRaisingEvents   = gitSettings.TrackSystemFiles,
                            IncludeSubdirectories = true,
                            NotifyFilter          = NotifyFilters.FileName
                        };

                        fileWatchers.Add(fileWatcher);
                        Subscribe(fileWatcher);
                    }
                }
            }
        }
        internal void DoFileDiff(Rect rect, StatusListEntry info, bool enabled, bool selected, GitDiffWindow window)
        {
            RectOffset elementPadding = GetElementStyle().padding;
            float      iconSize       = GetElementStyle().fixedHeight - elementPadding.vertical;
            float      toggleSize     = styles.toggle.fixedHeight;

            Event  current     = Event.current;
            string projectPath = gitManager.ToProjectPath(info.LocalPath);
            string fileName    = info.Name;

            GitGUI.StartEnable(enabled);
            Rect  stageToggleRect = new Rect(rect.x + rect.width - toggleSize * 2, rect.y + (rect.height - toggleSize) * 0.5f, toggleSize, toggleSize);
            bool  canUnstage      = GitManager.CanUnstage(info.State);
            bool  canStage        = GitManager.CanStage(info.State);
            float maxPathSize     = rect.width - stageToggleRect.width - toggleSize - 21;

            if (current.type == EventType.Repaint)
            {
                (selected ? styles.diffElementSelected : GetElementStyle()).Draw(rect, false, false, false, false);
            }

            if (canStage && canUnstage)
            {
                maxPathSize -= stageToggleRect.width - 4;
                Rect stageWarnningRect = new Rect(stageToggleRect.x - stageToggleRect.width - 4, stageToggleRect.y, stageToggleRect.width, stageToggleRect.height);
                EditorGUIUtility.AddCursorRect(stageWarnningRect, MouseCursor.Link);
                if (GUI.Button(stageWarnningRect, GitGUI.IconContent("console.warnicon", "", "Unstaged changed pending. Stage to update index."), GUIStyle.none))
                {
                    string[] localPaths = gitManager.GetPathWithMeta(info.LocalPath).ToArray();
                    if (gitManager.Threading.IsFlagSet(GitSettingsJson.ThreadingType.Stage))
                    {
                        gitManager.AsyncStage(localPaths).onComplete += (o) => { window.Repaint(); };
                    }
                    else
                    {
                        GitCommands.Stage(gitManager.Repository, localPaths);
                        gitManager.MarkDirtyAuto(localPaths);
                    }
                    window.Repaint();
                }
            }

            if (current.type == EventType.Repaint)
            {
                Object asset = null;
                if (UniGitPathHelper.IsPathInAssetFolder(projectPath))
                {
                    asset = AssetDatabase.LoadAssetAtPath(UniGitPathHelper.IsMetaPath(projectPath) ? GitManager.AssetPathFromMeta(projectPath) : projectPath, typeof(Object));
                }

                string     extension  = Path.GetExtension(projectPath);
                GUIContent tmpContent = GUIContent.none;
                if (string.IsNullOrEmpty(extension))
                {
                    tmpContent = GitGUI.GetTempContent(styles.folderIcon, "Folder");
                }

                if (tmpContent.image == null)
                {
                    if (asset != null)
                    {
                        tmpContent = GitGUI.GetTempContent(string.Empty, AssetDatabase.GetCachedIcon(projectPath), asset.GetType().Name);
                    }
                    else
                    {
                        tmpContent = GitGUI.GetTempContent(styles.defaultAssetIcon, "Unknown Type");
                    }
                }

                float x = rect.x + elementPadding.left;
                GUI.Box(new Rect(x, rect.y + elementPadding.top, iconSize, iconSize), tmpContent, styles.assetIcon);
                x += iconSize + 8;

                styles.diffElementName.Draw(new Rect(x, rect.y + elementPadding.top + 2, rect.width - elementPadding.right - iconSize - rect.height, EditorGUIUtility.singleLineHeight), GitGUI.GetTempContent(fileName), false, selected, selected, false);

                x = rect.x + elementPadding.left + iconSize + 8;
                foreach (var diffTypeIcon in gitOverlay.GetDiffTypeIcons(info.State, false))
                {
                    GUI.Box(new Rect(x, rect.y + elementPadding.top + EditorGUIUtility.singleLineHeight + 4, 21, 21), diffTypeIcon, GUIStyle.none);
                    x += 25;
                }

                if (info.MetaChange == (MetaChangeEnum.Object | MetaChangeEnum.Meta))
                {
                    GUI.Box(new Rect(x, rect.y + elementPadding.top + EditorGUIUtility.singleLineHeight + 4, 21, 21), GitGUI.GetTempContent(gitOverlay.icons.objectIconSmall.image, "main asset file changed"), GUIStyle.none);
                    x += 25;
                }
                if (info.MetaChange.IsFlagSet(MetaChangeEnum.Meta))
                {
                    GUI.Box(new Rect(x, rect.y + elementPadding.top + EditorGUIUtility.singleLineHeight + 4, 21, 21), GitGUI.GetTempContent(gitOverlay.icons.metaIconSmall.image, ".meta file changed"), GUIStyle.none);
                    x += 25;
                }
                if (info.Flags.IsFlagSet(StatusEntryFlags.IsLfs))
                {
                    GUI.Box(new Rect(x, rect.y + elementPadding.top + EditorGUIUtility.singleLineHeight + 4, 21, 21), GitGUI.GetTempContent(gitOverlay.icons.lfsObjectIconSmall.image, "Lfs Object"), GUIStyle.none);
                    x += 25;
                }
                if (info.Flags.IsFlagSet(StatusEntryFlags.IsSubModule))
                {
                    GUI.Box(new Rect(x, rect.y + elementPadding.top + EditorGUIUtility.singleLineHeight + 4, 21, 21), GitGUI.GetTempContent(gitOverlay.icons.submoduleTagIconSmall.image, "Sub Module"), GUIStyle.none);
                    x += 25;
                }

                Vector2 pathSize = styles.diffElementPath.CalcSize(GitGUI.GetTempContent(projectPath));
                pathSize.x = Mathf.Min(pathSize.x, maxPathSize - x);

                Rect pathRect = new Rect(x, rect.y + elementPadding.top + EditorGUIUtility.singleLineHeight, pathSize.x, EditorGUIUtility.singleLineHeight * 2);

                styles.diffElementPath.Draw(pathRect, GitGUI.GetTempContent(projectPath), false, selected, selected, false);
                x += pathRect.width + 4;

                if (!enabled)
                {
                    GUI.Box(new Rect(x, rect.y + elementPadding.top + EditorGUIUtility.singleLineHeight + 4, 21, 21), GitGUI.GetTempSpinAnimatedTexture(), GUIStyle.none);
                    //spinning animation needs constant repaint
                    if (gitSettings.AnimationType.HasFlag(GitSettingsJson.AnimationTypeEnum.Loading))
                    {
                        window.Repaint();
                    }
                }
            }

            if (canUnstage || canStage)
            {
                EditorGUI.BeginChangeCheck();
                EditorGUIUtility.AddCursorRect(stageToggleRect, MouseCursor.Link);
                EditorGUI.Toggle(stageToggleRect, canUnstage, styles.toggle);
                if (EditorGUI.EndChangeCheck())
                {
                    bool updateFlag = false;
                    if (GitManager.CanStage(info.State))
                    {
                        string[] paths = gitManager.GetPathWithMeta(info.LocalPath).ToArray();
                        if (gitManager.Threading.IsFlagSet(GitSettingsJson.ThreadingType.Stage))
                        {
                            gitManager.AsyncStage(paths).onComplete += (o) => { window.Repaint(); };
                        }
                        else
                        {
                            GitCommands.Stage(gitManager.Repository, paths);
                            gitManager.MarkDirtyAuto(paths);
                        }
                        updateFlag = true;
                    }
                    else if (GitManager.CanUnstage(info.State))
                    {
                        string[] paths = gitManager.GetPathWithMeta(info.LocalPath).ToArray();
                        if (gitManager.Threading.IsFlagSet(GitSettingsJson.ThreadingType.Unstage))
                        {
                            gitManager.AsyncUnstage(paths).onComplete += (o) => { window.Repaint(); };
                        }
                        else
                        {
                            GitCommands.Unstage(gitManager.Repository, paths);
                            gitManager.MarkDirtyAuto(paths);
                        }
                        updateFlag = true;
                    }

                    if (updateFlag)
                    {
                        window.Repaint();
                        current.Use();
                    }
                }
            }
            GitGUI.EndEnable();
        }
示例#7
0
        public string GetGuid(GitManager gitManager)
        {
            string projectPath = gitManager.ToProjectPath(localPath);

            return(UniGitPathHelper.IsPathInAssetFolder(projectPath) ? AssetDatabase.AssetPathToGUID(projectPath) : projectPath);
        }