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(); }
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); } } }
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(); } }
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 !")); } }
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)); }
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); }
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")); }
public static string AssetPathFromMeta(string metaPath) { if (UniGitPathHelper.IsMetaPath(metaPath)) { return(metaPath.Substring(0, metaPath.Length - 5)); } return(metaPath); }
public string GetCurrentDotGitFolder() { if (inSubModule) { return(dotGitDirCached); } return(UniGitPathHelper.Combine(paths.RepoPath, ".git")); }
/// <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); }
public bool IsEmptyFolderMeta(string path) { if (UniGitPathHelper.IsMetaPath(path)) { return(IsEmptyFolder(path.Substring(0, path.Length - 5))); } return(false); }
public void SwitchToSubModule(string path) { if (gitSettings.ActiveSubModule != path && Repository.IsValid(UniGitPathHelper.Combine(paths.RepoProjectRelativePath, path))) { gitSettings.ActiveSubModule = path; gitSettings.MarkDirty(); MarkDirty(true); } }
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); }
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); }
public void SaveTracking() { using (StreamWriter file = File.CreateText(UniGitPathHelper.Combine(gitManager.GetCurrentRepoPath(), ".gitattributes"))) { foreach (var info in trackedInfo) { file.WriteLine(info.ToString()); } } Update(); }
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); }
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(); }
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); }
internal void DeleteAsset(string localPath) { string projectPath = gitManager.ToProjectPath(localPath); if (UniGitPathHelper.IsPathInAssetFolder(projectPath)) { AssetDatabase.DeleteAsset(projectPath); } else { File.Delete(projectPath); gitManager.MarkDirty(localPath); } }
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)); }
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(); }
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); } } }
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"); }
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); } }
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); }
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); } } }
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); } } } } } }
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(); }
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); }