示例#1
0
    private static void CopyFilesTo(string from, string to)
    {
        DirectoryInfo dirInfo = new DirectoryInfo(to);

        if (!dirInfo.Exists)
        {
            Directory.CreateDirectory(to);
        }

        List <string> files = Directory.GetFiles(from, "*.*", SearchOption.AllDirectories).ToList();

        foreach (string file in files)
        {
            FileInfo mFile = new FileInfo(file);

            string subDir  = mFile.Directory.ToString().Replace(from + "\\", "");
            string newPath = UniGitPath.Combine(to, subDir);
            // to remove name collisions
            if (!new FileInfo(UniGitPath.Combine(newPath, mFile.Name)).Exists)
            {
                if (!Directory.Exists(newPath))
                {
                    Directory.CreateDirectory(newPath);
                }
                mFile.CopyTo(UniGitPath.Combine(newPath, mFile.Name));
            }
        }
    }
示例#2
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 = UniGitPath.Combine(path, fileName);
                if (File.Exists(fullPath))
                {
                    return(fullPath);
                }
            }
            return(null);
        }
示例#3
0
    public void RepositoryHandlesLockedFileWhenWithIgnoreStatus()
    {
        File.AppendAllText(gitManager.GitIgnoreFilePath, "testFile.txt");
        string lockedFilePathName = "testFile.txt";
        string lockedFilePath     = UniGitPath.Combine(gitManager.RepoPath, lockedFilePathName);

        using (var lockFileStream = File.CreateText(lockedFilePath))
        {
            lockFileStream.WriteLine("This is a locked test file");
        }
        injectionHelper.Bind <GitProjectOverlay>();
        var projectOverlays = injectionHelper.GetInstance <GitProjectOverlay>();

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

        try
        {
            gitManager.MarkDirty();
            injectionHelper.GetInstance <GitCallbacks>().IssueEditorUpdate();
            Assert.AreEqual(FileStatus.Ignored, projectOverlays.StatusTree.GetStatus(lockedFilePathName).State);
        }
        finally
        {
            lockedFileStream.Dispose();
        }
    }
        private void ValidateCredentialsPath()
        {
            string settingsFileDirectory = UniGitPath.Combine(gitManager.GitFolderPath, "UniGit");

            if (!Directory.Exists(settingsFileDirectory))
            {
                Directory.CreateDirectory(settingsFileDirectory);
            }
        }
示例#5
0
        public GitManager(string repoPath, GitCallbacks callbacks, GitSettingsJson settings, IGitPrefs prefs, GitAsyncManager asyncManager)
        {
            this.repoPath     = repoPath;
            this.callbacks    = callbacks;
            this.prefs        = prefs;
            this.asyncManager = asyncManager;
            gitSettings       = settings;
            gitPath           = UniGitPath.Combine(repoPath, ".git");

            Initialize();
        }
示例#6
0
        public void SaveTracking()
        {
            using (StreamWriter file = File.CreateText(UniGitPath.Combine(gitManager.RepoPath, ".gitattributes")))
            {
                foreach (var info in trackedInfo)
                {
                    file.WriteLine(info.ToString());
                }
            }

            Update();
        }
示例#7
0
        public void Update()
        {
            RegisterFilter();

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

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

            if (!Directory.Exists(UniGitPath.Combine(gitManager.RepoPath, ".git", "lfs")))
            {
                Debug.LogError("Git-LFS install failed! (Try manually)");
                Debug.LogError(output);
                return(false);
            }
            EditorUtility.DisplayDialog("Git LFS Initialized", output, "Ok");
            UpdateInitilized();
            return(true);
        }
示例#9
0
        private void BuildChangeSections(Commit commit)
        {
            int          lastIndexFileLine = 0;
            Stream       indexFileContent  = File.OpenRead(UniGitPath.Combine(gitManager.RepoPath, path));
            StreamReader indexFileReader   = new StreamReader(indexFileContent);

            var lines = GetLines(commit);

            try
            {
                ProcessChanges(lines, indexFileReader, ref lastIndexFileLine);
            }
            catch (Exception e)
            {
                Debug.LogError("There was a problem while loading changes");
                Debug.LogException(e);
            }
            finally
            {
                indexFileContent.Dispose();
                indexFileReader.Dispose();
            }
        }
示例#10
0
    public static void BuildDLL()
    {
        UpdateVSProject();

        string devnetPath = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\devenv.exe", null, null).ToString();

        if (string.IsNullOrEmpty(devnetPath))
        {
            Debug.LogError("Could not find devnet in registry!");
            devnetPath = EditorUtility.OpenFilePanel("Devnet.Exe", "", "exe");

            if (string.IsNullOrEmpty(devnetPath))
            {
                Debug.LogError("Could not find devnet!");
                return;
            }
        }
        else
        {
            Debug.Log("Devnet Path: " + devnetPath);
        }

        Process devnetProcess = new Process();

        devnetProcess.StartInfo.Arguments              = string.Format("{0} {1} {2} {3}", "\"UniGitVs.sln\"", " /build Debug", "/project \"UniGitVs.csproj\"", "/projectconfig Debug");
        devnetProcess.StartInfo.RedirectStandardError  = true;
        devnetProcess.StartInfo.RedirectStandardOutput = true;
        devnetProcess.StartInfo.UseShellExecute        = false;
        devnetProcess.StartInfo.FileName = devnetPath.ToString();
        //devnetProcess.StartInfo.Verb = "runas";
        devnetProcess.StartInfo.WorkingDirectory = Application.dataPath.Replace("/", "\\").Replace("Assets", "UniGitVs");

        devnetProcess.Start();
        EditorUtility.DisplayProgressBar("Building Project", "Building in progress", 0.1f);
        devnetProcess.WaitForExit();
        EditorUtility.ClearProgressBar();

        string logs           = devnetProcess.StandardOutput.ReadToEnd();
        string errors         = devnetProcess.StandardError.ReadToEnd();
        bool   buildHasOutput = !string.IsNullOrEmpty(logs) || !string.IsNullOrEmpty(errors);

        if (buildHasOutput)
        {
            Debug.Log("---- Build Process Output ----");
            if (!string.IsNullOrEmpty(logs))
            {
                Debug.Log(logs);
            }

            if (!string.IsNullOrEmpty(errors))
            {
                Debug.LogError(errors);
            }
            Debug.Log("---- ------------------- ----");
        }

        Application.OpenURL(Application.dataPath.Replace("/", "\\").Replace("Assets", UniGitPath.Combine("UniGitVs", "bin", "Debug")));
    }
 private void OpenGitIgnore()
 {
     Application.OpenURL(UniGitPath.Combine(gitManager.RepoPath, ".gitignore"));
 }
示例#12
0
        static UniGitLoader()
        {
            Profiler.BeginSample("UniGit Initialization");
            try
            {
                injectionHelper = new InjectionHelper();
                GitWindows.Init();
                var recompileChecker = ScriptableObject.CreateInstance <AssemblyReloadScriptableChecker>();
                recompileChecker.OnBeforeReloadAction = OnBeforeAssemblyReload;

                string repoPath     = Application.dataPath.Replace(UniGitPath.UnityDeirectorySeparatorChar + "Assets", "").Replace(UniGitPath.UnityDeirectorySeparatorChar, Path.DirectorySeparatorChar);
                string settingsPath = UniGitPath.Combine(repoPath, ".git", "UniGit", "Settings.json");

                injectionHelper.Bind <string>().FromInstance(repoPath).WithId("repoPath");
                injectionHelper.Bind <string>().FromInstance(settingsPath).WithId("settingsPath");

                injectionHelper.Bind <GitCallbacks>().FromMethod(() =>
                {
                    var c = new GitCallbacks();
                    EditorApplication.update += c.IssueEditorUpdate;
                    c.RefreshAssetDatabase   += AssetDatabase.Refresh;
                    c.SaveAssetDatabase      += AssetDatabase.SaveAssets;
                    EditorApplication.projectWindowItemOnGUI += c.IssueProjectWindowItemOnGUI;
                    //asset postprocessing
                    GitAssetPostprocessors.OnWillSaveAssetsEvent            += c.IssueOnWillSaveAssets;
                    GitAssetPostprocessors.OnPostprocessImportedAssetsEvent += c.IssueOnPostprocessImportedAssets;
                    GitAssetPostprocessors.OnPostprocessDeletedAssetsEvent  += c.IssueOnPostprocessDeletedAssets;
                    GitAssetPostprocessors.OnPostprocessMovedAssetsEvent    += c.IssueOnPostprocessMovedAssets;
                    return(c);
                });
                injectionHelper.Bind <IGitPrefs>().To <UnityEditorGitPrefs>();
                injectionHelper.Bind <GitManager>();
                injectionHelper.Bind <GitSettingsJson>();
                injectionHelper.Bind <GitSettingsManager>();
                injectionHelper.Bind <GitAsyncManager>();

                GitManager = injectionHelper.GetInstance <GitManager>();
                GitManager.Callbacks.RepositoryCreate += OnRepositoryCreate;

                GitUnityMenu.Init(GitManager);
                GitResourceManager.Initilize();
                GitOverlay.Initlize();

                //credentials
                injectionHelper.Bind <ICredentialsAdapter>().To <WincredCredentialsAdapter>();
                injectionHelper.Bind <GitCredentialsManager>();
                //externals
                injectionHelper.Bind <IExternalAdapter>().To <GitExtensionsAdapter>();
                injectionHelper.Bind <IExternalAdapter>().To <TortoiseGitAdapter>();
                injectionHelper.Bind <GitExternalManager>();
                injectionHelper.Bind <GitLfsManager>();
                //hooks
                injectionHelper.Bind <GitPushHookBase>().To <GitLfsPrePushHook>();
                injectionHelper.Bind <GitHookManager>();
                //helpers
                injectionHelper.Bind <GitLfsHelper>();
                injectionHelper.Bind <FileLinesReader>();
                //project window overlays
                injectionHelper.Bind <GitProjectOverlay>();

                if (!Repository.IsValid(repoPath))
                {
                    EditorApplication.delayCall += OnDelayedInit;
                }
                else
                {
                    Rebuild(injectionHelper);
                    EditorApplication.delayCall += OnDelayedInit;
                }
            }
            finally
            {
                Profiler.EndSample();
            }
        }
示例#13
0
 public bool CheckInitialized()
 {
     return(Directory.Exists(UniGitPath.Combine(gitManager.RepoPath, ".git", "lfs")) && File.Exists(UniGitPath.Combine(gitManager.RepoPath, ".git", "hooks", "pre-push")));
 }