private bool RefreshBranches(bool isRefreshMode) { isEmpty = false; try { // gather branches BranchState[] bStates; if (!repository.GetBrancheStates(out bStates)) { throw new Exception(repository.lastError); } branchStates = bStates; // check for new repo state if (branchStates.Length == 0) { isEmpty = true; activeBranch = null; branchStates = null; remoteStates = null; DebugLog.LogWarning("New branch, nothing commit!"); return(true); } // find active branch activeBranch = Array.Find <BranchState>(branchStates, x => x.isActive); if (activeBranch.isRemote) { DebugLog.LogError("Active repo branch cannot be a remote: " + activeBranch.fullname); if (isRefreshMode) { Environment.Exit(0); } else { return(false); } } // gather remotes RemoteState[] rStates; if (!repository.GetRemoteStates(out rStates)) { throw new Exception(repository.lastError); } remoteStates = rStates; } catch (Exception e) { DebugLog.LogError("BranchManager.Refresh Failed: " + e.Message); return(false); } return(true); }
private static void LoadMergeDiffTool() { if (PlatformInfo.platform == Platforms.Windows) { string programFilesx86, programFilesx64; PlatformInfo.GetWindowsProgramFilesPath(out programFilesx86, out programFilesx64); switch (settings.mergeDiffTool) { case MergeDiffTools.None: mergeToolPath = null; break; case MergeDiffTools.Meld: mergeToolPath = programFilesx86 + "\\Meld\\Meld.exe"; break; case MergeDiffTools.kDiff3: mergeToolPath = programFilesx64 + "\\KDiff3\\kdiff3.exe"; break; case MergeDiffTools.P4Merge: mergeToolPath = programFilesx64 + "\\Perforce\\p4merge.exe"; break; case MergeDiffTools.DiffMerge: mergeToolPath = programFilesx64 + "\\SourceGear\\Common\\\\DiffMerge\\sgdm.exe"; break; } } else if (PlatformInfo.platform == Platforms.Mac) { mergeToolPath = null; } else if (PlatformInfo.platform == Platforms.Linux) { mergeToolPath = null; } else { throw new Exception("Unsported platform: " + PlatformInfo.platform); } if (mergeToolPath != null) { isMergeToolInstalled = File.Exists(mergeToolPath); if (!isMergeToolInstalled) { DebugLog.LogWarning("Diff/Merge tool not installed: " + mergeToolPath); } } else { isMergeToolInstalled = false; DebugLog.LogWarning("Diff/Merge tool set to none. Some app functions will fail."); } }
private static void Client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { var checkForUpdatesCallback = (CheckForUpdatesCallbackMethod)e.UserState; if (e.Error != null) { DebugLog.LogError("Failed to check for updates: " + e.Error.Message); client.Dispose(); if (checkForUpdatesCallback != null) { checkForUpdatesCallback(UpdateCheckResult.CommonError); } return; } if (e.Cancelled) { DebugLog.LogError("Update check canceled!"); client.Dispose(); if (checkForUpdatesCallback != null) { checkForUpdatesCallback(UpdateCheckResult.CommonError); } return; } try { // check app version bool canCheckAppVersion = true; using (var reader = new StringReader(e.Result)) using (var xmlReader = new XmlTextReader(reader)) { while (xmlReader.Read()) { if (canCheckAppVersion && xmlReader.Name == "AppVersion") { canCheckAppVersion = false; if (!IsValidVersion(VersionInfo.version, xmlReader.ReadInnerXml())) { DebugLog.LogWarning("Your 'Git-It-GUI' version is out of date."); if (checkForUpdatesCallback != null) { checkForUpdatesCallback(UpdateCheckResult.AppVersionOutOfDate); } } } } } if (checkForUpdatesCallback != null) { checkForUpdatesCallback(UpdateCheckResult.Success); } } catch (Exception ex) { DebugLog.LogError("Failed to get version info!\nMake sure git and git-lfs are installed\nAlso make sure you're connected to the internet: \n\n" + ex.Message); if (checkForUpdatesCallback != null) { checkForUpdatesCallback(UpdateCheckResult.AppVersionParseError); } } client.Dispose(); }
public bool RemoveGitLFSSupport(bool rebase) { lock (this) { // check if not init if (!lfsEnabled) { DebugLog.LogWarning("Git LFS is not enabled on repo"); return(false); } try { // untrack lfs filters string gitattributesPath = Path.Combine(repository.repoPath, ".gitattributes"); if (File.Exists(gitattributesPath)) { string data = File.ReadAllText(gitattributesPath); var values = Regex.Matches(data, @"(\*\..*)? filter=lfs diff=lfs merge=lfs"); foreach (Match value in values) { if (value.Groups.Count != 2) { continue; } if (!repository.lfs.Untrack(value.Groups[1].Value)) { throw new Exception(repository.lastError); } } } // remove lfs repo files if (!repository.lfs.Uninstall()) { throw new Exception(repository.lastError); } string lfsHookFile = Path.Combine(repository.repoPath, ".git", "hooks", "pre-push"); if (File.Exists(lfsHookFile)) { File.Delete(lfsHookFile); } string lfsFolder = Path.Combine(repository.repoPath, ".git", "lfs"); if (Directory.Exists(lfsFolder)) { Directory.Delete(lfsFolder, true); } // rebase repo if (rebase) { // TODO } // finish lfsEnabled = false; } catch (Exception e) { DebugLog.LogError("Remove Git-LFS Error: " + e.Message); Environment.Exit(0); // quit for safety as application should restart return(false); } return(true); } }
public bool AddGitLFSSupport(bool addLFSDefaultExts) { lock (this) { // check if already init if (lfsEnabled) { DebugLog.LogWarning("Git LFS already enabled on repo"); return(false); } try { // init git lfs string lfsFolder = Path.Combine(repository.repoPath, ".git", "lfs"); if (!Directory.Exists(lfsFolder)) { if (!repository.lfs.Install()) { throw new Exception(repository.lastError); } if (!Directory.Exists(lfsFolder)) { DebugLog.LogError("Git-LFS install failed! (Try manually)"); lfsEnabled = false; return(false); } } // add attr file if it doesn't exist string gitattributesPath = Path.Combine(repository.repoPath, ".gitattributes"); if (!File.Exists(gitattributesPath)) { using (var writer = File.CreateText(gitattributesPath)) { // this will be an empty file... } } // add default ext to git lfs if (addLFSDefaultExts && AppManager.defaultGitLFS_Exts != null && AppManager.defaultGitLFS_Exts.Count != 0) { if (!repository.lfs.Track(AppManager.defaultGitLFS_Exts)) { throw new Exception(repository.lastError); } } // finish lfsEnabled = true; } catch (Exception e) { DebugLog.LogError("Add Git-LFS Error: " + e.Message); Environment.Exit(0); // quit for safety as application should restart return(false); } return(true); } }
/// <summary> /// Use to open an existing repo /// </summary> /// <param name="repoPath">Path to git repo</param> /// <returns>True if succeeded</returns> public bool Open(string repoPath, bool checkForSettingErros = false) { lock (this) { isOpen = false; // unload repo if (string.IsNullOrEmpty(repoPath)) { repository.Close(); return(true); } bool isRefreshMode = repoPath == repository.repoPath; try { // load repo if (isRefreshMode) { repository.Close(); } if (!repository.Open(repoPath)) { throw new Exception(repository.lastError); } // check for git lfs lfsEnabled = repository.lfs.isEnabled; // check for .gitignore file if (!isRefreshMode) { string gitIgnorePath = Path.Combine(repoPath, ".gitignore"); if (!File.Exists(gitIgnorePath)) { DebugLog.LogWarning("No '.gitignore' file exists.\nAuto creating one!"); File.WriteAllText(gitIgnorePath, ""); } } // add repo to history AppManager.AddRepoToHistory(repoPath); // non-refresh checks if (!isRefreshMode) { // get signature string sigName, sigEmail; if (repository.GetSignature(SignatureLocations.Local, out sigName, out sigEmail)) { signatureName = sigName; signatureEmail = sigEmail; signatureIsLocal = true; if (string.IsNullOrEmpty(sigName) || string.IsNullOrEmpty(sigEmail)) { if (repository.GetSignature(SignatureLocations.Any, out sigName, out sigEmail)) { signatureName = sigName; signatureEmail = sigEmail; signatureIsLocal = false; } else { signatureName = "<< ERROR >>"; signatureEmail = "<< ERROR >>"; signatureIsLocal = false; } } } else { signatureName = "<< ERROR >>"; signatureEmail = "<< ERROR >>"; signatureIsLocal = false; } if (checkForSettingErros) { if (string.IsNullOrEmpty(sigName) || string.IsNullOrEmpty(sigEmail)) { DebugLog.LogWarning("Credentials not set, please go to the settings tab!"); } } // submodules if (repository.hasSubmodules) { if (repository.areSubmodulesInit) { if (!repository.PullSubmodules()) { DebugLog.LogError("Failed to pull submodules: " + repository.lastError); return(false); } } else { if (!repository.InitPullSubmodules()) { DebugLog.LogError("Failed to init and pull submodules: " + repository.lastError); return(false); } } } } } catch (Exception e) { DebugLog.LogError("RepoManager.OpenRepo Failed: " + e.Message); repository.Close(); return(false); } // refesh partials if (!RefreshBranches(isRefreshMode)) { return(false); } if (!RefreshChanges()) { return(false); } // check sync if (IsUpToDateWithRemote(out bool yes)) { isInSync = yes; } else { isInSync = null; } isOpen = true; } // finish if (!disableRepoRefreshedCallback && RepoRefreshedCallback != null) { RepoRefreshedCallback(false); } return(true); }
private void DebugLog_StdWarningCallback(string line) { DebugLog.LogWarning(line); }