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); } }
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); } }
private void DebugLog_StdErrorCallback(string line) { DebugLog.LogError(line); }
/// <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); }
private void DebugLog_RunExeDebugLineCallback(string line) { DebugLog.Log(line); }
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 static void CheckForUpdates(string url, CheckForUpdatesCallbackMethod checkForUpdatesCallback) { try { // validate git install var repository = new Repository(); // git and git-lfs versions string gitVersion = null, gitlfsVersion = null; string gitlfsRequiredGitVersion = "0.0.0.0"; const string minGitVersion = "2.11.0", minGitLFSVersion = "1.5.5"; // get git version string try { if (!repository.GetVersion(out gitVersion)) { throw new Exception(repository.lastError); } } catch { DebugLog.LogError("git is not installed correctly. (Make sure git is usable in the cmd/terminal)"); client.Dispose(); if (checkForUpdatesCallback != null) { checkForUpdatesCallback(UpdateCheckResult.GitNotInstalledError); } DownloadGit(); return; } // get git-lfs version string try { if (!repository.lfs.GetVersion(out gitlfsVersion)) { throw new Exception(repository.lastError); } } catch { DebugLog.LogError("git-lfs is not installed correctly. (Make sure git-lfs is usable in the cmd/terminal)"); client.Dispose(); if (checkForUpdatesCallback != null) { checkForUpdatesCallback(UpdateCheckResult.GitLFSNotInstalledError); } DownloadGitLFS(); return; } // grab git version value string appendix = ""; if (PlatformInfo.platform == Platforms.Windows) { appendix = @"\.windows"; } var match = Regex.Match(gitVersion, @"git version (.*)" + appendix); if (match.Success && match.Groups.Count == 2) { gitVersion = match.Groups[1].Value; } else { DebugLog.LogError("Failed to grab git version!"); client.Dispose(); if (checkForUpdatesCallback != null) { checkForUpdatesCallback(UpdateCheckResult.GitVersionCheckError); } DownloadGit(); return; } // grab lfs and required git version value if (PlatformInfo.platform == Platforms.Windows) { appendix = @"; git .*\)"; } else { appendix = @"\)"; } match = Regex.Match(gitlfsVersion, @"git-lfs/(.*) \(GitHub; (\w*) (\w*); go (.*)" + appendix); if (match.Success && match.Groups.Count == 5) { gitlfsVersion = match.Groups[1].Value; gitlfsRequiredGitVersion = match.Groups[4].Value; } else { DebugLog.LogError("Failed to grab git-lfs version!"); client.Dispose(); if (checkForUpdatesCallback != null) { checkForUpdatesCallback(UpdateCheckResult.GitLFSVersionCheckError); } DownloadGitLFS(); return; } // make sure the git version installed is supporeted by lfs if (!IsValidVersion(gitVersion, gitlfsRequiredGitVersion)) { DebugLog.LogError(string.Format("'git-lfs' version is not compatible with 'git' version installed!")); client.Dispose(); if (checkForUpdatesCallback != null) { checkForUpdatesCallback(UpdateCheckResult.GitVersionToLowForLFS); } DownloadGit(); DownloadGitLFS(); return; } // check min git versions bool gitValid = true, gitlfsValid = true; if (!IsValidVersion(gitVersion, minGitVersion)) { DebugLog.LogError("Your 'git' version is out of date.\nDownload and install with defaults!"); gitValid = false; } if (!IsValidVersion(gitlfsVersion, minGitLFSVersion)) { DebugLog.LogError("Your 'git-lfs' version is out of date.\nDownload and install with defaults!"); gitlfsValid = false; } if (!gitValid || !gitlfsValid) { if (!gitValid) { DownloadGit(); } if (!gitlfsValid) { DownloadGitLFS(); } if (checkForUpdatesCallback != null) { checkForUpdatesCallback(UpdateCheckResult.BadVersionError); } return; } // check app version client = new WebClient(); client.DownloadStringCompleted += Client_DownloadStringCompleted; client.DownloadStringAsync(new Uri(url), checkForUpdatesCallback); } catch (Exception e) { DebugLog.LogError("Failed to check for updates: " + e.Message); if (checkForUpdatesCallback != null) { checkForUpdatesCallback(UpdateCheckResult.CommonError); } } }
/// <summary> /// Call before app exit after everything else /// </summary> public static void Dispose() { DebugLog.Dispose(); }