示例#1
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();
        }
    }
示例#2
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();
            }
        }
示例#3
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);
        }
示例#4
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"));
 }
示例#5
0
 public string GetCurrentDotGitFolder()
 {
     if (inSubModule)
     {
         return(dotGitDirCached);
     }
     return(UniGitPathHelper.Combine(paths.RepoPath, ".git"));
 }
示例#6
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);
 }
示例#7
0
 public void SwitchToSubModule(string path)
 {
     if (gitSettings.ActiveSubModule != path && Repository.IsValid(UniGitPathHelper.Combine(paths.RepoProjectRelativePath, path)))
     {
         gitSettings.ActiveSubModule = path;
         gitSettings.MarkDirty();
         MarkDirty(true);
     }
 }
示例#8
0
        public void SaveTracking()
        {
            using (StreamWriter file = File.CreateText(UniGitPathHelper.Combine(gitManager.GetCurrentRepoPath(), ".gitattributes")))
            {
                foreach (var info in trackedInfo)
                {
                    file.WriteLine(info.ToString());
                }
            }

            Update();
        }
示例#9
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);
        }
示例#10
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);
        }
示例#11
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();
        }
示例#12
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));
        }
示例#13
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();
        }
示例#14
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");
        }
示例#15
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);
        }
示例#16
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);
                }
            }
示例#17
0
        public int Compare(StatusListEntry x, StatusListEntry y)
        {
            int stateCompare = window.IsGrouping() ? GetPriority(x.State).CompareTo(GetPriority(y.State)) : 0;

            if (stateCompare == 0)
            {
                var settings = window.GitDiffSettings;

                if (settings.sortDir == GitDiffWindow.SortDir.Descending)
                {
                    var oldLeft = x;
                    x = y;
                    y = oldLeft;
                }

                if (settings.unstagedChangesPriority)
                {
                    bool canStageX   = GitManager.CanStage(x.State);
                    bool canUnstageX = GitManager.CanUnstage(x.State);
                    bool canStageY   = GitManager.CanStage(y.State);
                    bool canUnstageY = GitManager.CanUnstage(y.State);

                    //prioritize upsaged changes that are pending
                    if ((canStageX && canUnstageX) && !(canStageY && canUnstageY))
                    {
                        return(-1);
                    }
                    if (!(canStageX && canUnstageX) && (canStageY && canUnstageY))
                    {
                        return(1);
                    }
                }

                switch (settings.sortType)
                {
                case GitDiffWindow.SortType.Name:
                    stateCompare = string.Compare(x.Name, y.Name, StringComparison.InvariantCultureIgnoreCase);
                    break;

                case GitDiffWindow.SortType.Path:
                    stateCompare = string.Compare(x.LocalPath, y.LocalPath, StringComparison.InvariantCultureIgnoreCase);
                    break;

                case GitDiffWindow.SortType.ModificationDate:
                    //todo cache modification dates
                    DateTime modifedTimeLeft  = GetClosest(gitManager.GetPathWithMeta(x.LocalPath).Select(p => File.GetLastWriteTime(UniGitPathHelper.Combine(gitManager.GetCurrentRepoPath(), p))));
                    DateTime modifedRightTime = GetClosest(gitManager.GetPathWithMeta(x.LocalPath).Select(p => File.GetLastWriteTime(UniGitPathHelper.Combine(gitManager.GetCurrentRepoPath(), p))));
                    stateCompare = DateTime.Compare(modifedRightTime, modifedTimeLeft);
                    break;

                case GitDiffWindow.SortType.CreationDate:
                    //todo cache creation dates
                    DateTime createdTimeLeft  = GetClosest(gitManager.GetPathWithMeta(x.LocalPath).Select(p => File.GetCreationTime(UniGitPathHelper.Combine(gitManager.GetCurrentRepoPath(), p))));
                    DateTime createdRightTime = GetClosest(gitManager.GetPathWithMeta(y.LocalPath).Select(p => File.GetCreationTime(UniGitPathHelper.Combine(gitManager.GetCurrentRepoPath(), p))));
                    stateCompare = DateTime.Compare(createdRightTime, createdTimeLeft);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            if (stateCompare == 0)
            {
                stateCompare = String.Compare(x.LocalPath, y.LocalPath, StringComparison.Ordinal);
            }
            return(stateCompare);
        }
示例#18
0
        static UniGitLoader()
        {
            HandlePaths();

            GitProfilerProxy.BeginSample("UniGit Initialization");
            try
            {
                GitWindows.OnWindowAddedEvent += OnWindowAdded;
                EditorApplication.update      += OnEditorUpdate;

                injectionHelper = new InjectionHelper();

                GitWindows.Init();

                uniGitData = CreateUniGitData();                 //data must be created manually to not call unity methods from constructors

                string projectPath = UniGitPathHelper.FixUnityPath(
                    Application.dataPath.Replace(UniGitPathHelper.UnityDeirectorySeparatorChar + "Assets", ""));
                string repoPath = projectPath;
                if (EditorPrefs.HasKey(RepoPathKey))
                {
                    repoPath = UniGitPathHelper.FixUnityPath(UniGitPathHelper.Combine(repoPath, EditorPrefs.GetString(RepoPathKey)));
                }

                injectionHelper.Bind <UniGitPaths>().FromInstance(new UniGitPaths(repoPath, projectPath));
                injectionHelper.Bind <GitInitializer>().NonLazy();
                injectionHelper.Bind <UniGitData>().FromMethod(c => uniGitData);                //must have a getter so that it can be injected
                injectionHelper.Bind <GitCallbacks>().FromMethod(GetGitCallbacks);
                injectionHelper.Bind <IGitPrefs>().To <UnityEditorGitPrefs>();
                injectionHelper.Bind <GitManager>().NonLazy();
                injectionHelper.Bind <GitSettingsJson>();
                injectionHelper.Bind <GitSettingsManager>();
                injectionHelper.Bind <GitAsyncManager>();
                injectionHelper.Bind <GitFileWatcher>().NonLazy();
                injectionHelper.Bind <GitReflectionHelper>();
                injectionHelper.Bind <IGitResourceManager>().To <GitResourceManager>();
                injectionHelper.Bind <GitOverlay>();
                injectionHelper.Bind <GitAutoFetcher>().NonLazy();
                injectionHelper.Bind <GitLog>();
                injectionHelper.Bind <ILogger>().FromMethod(c => new Logger(c.injectionHelper.GetInstance <GitLog>()));
                injectionHelper.Bind <GitAnimation>();
                injectionHelper.Bind <ICredentialsAdapter>().To <WincredCredentialsAdapter>();
                injectionHelper.Bind <GitCredentialsManager>().NonLazy();
                injectionHelper.Bind <IExternalAdapter>().To <GitExtensionsAdapter>();
                injectionHelper.Bind <IExternalAdapter>().To <TortoiseGitAdapter>();
                injectionHelper.Bind <GitExternalManager>();
                injectionHelper.Bind <GitLfsManager>().NonLazy();                //must be non lazy as it add itself as a filter
                injectionHelper.Bind <GitPushHookBase>().To <GitLfsPrePushHook>();
                injectionHelper.Bind <GitHookManager>().NonLazy();
                injectionHelper.Bind <GitLfsHelper>();
                injectionHelper.Bind <FileLinesReader>();
                injectionHelper.Bind <GitProjectOverlay>().NonLazy();
                injectionHelper.Bind <GitConflictsHandler>();

                //diff window
                injectionHelper.Bind <GitDiffWindowToolbarRenderer>().AsTransient();
                injectionHelper.Bind <GitDiffElementContextFactory>().AsTransient();
                injectionHelper.Bind <GitDiffWindowCommitRenderer>().AsTransient();
                injectionHelper.Bind <GitDiffWindowDiffElementRenderer>().AsTransient();

                Rebuild(injectionHelper);
            }
            finally
            {
                GitProfilerProxy.EndSample();
            }
        }
示例#19
0
 public bool CheckInitialized()
 {
     return(Directory.Exists(UniGitPathHelper.Combine(gitManager.GetCurrentDotGitFolder(), "lfs")) && File.Exists(UniGitPathHelper.Combine(gitManager.GetCurrentDotGitFolder(), "hooks", "pre-push")));
 }
示例#20
0
 private static void HandlePaths()
 {
     AddPath(UniGitPathHelper.Combine(Environment.CurrentDirectory, "Assets", "Plugins", "LibGit2"));
     AddPath(UniGitPathHelper.Combine(Environment.CurrentDirectory, "Assets", "Plugins", "LibGit2", "x86"));
     AddPath(UniGitPathHelper.Combine(Environment.CurrentDirectory, "Assets", "Plugins", "LibGit2", "x86_64"));
 }
示例#21
0
 private void OpenGitIgnore()
 {
     Application.OpenURL(UniGitPathHelper.Combine(gitManager.GetCurrentRepoPath(), ".gitignore"));
 }