/// <summary> /// Get the git configuration /// </summary> /// <returns>A Config object.</returns> public Config GetConfig() { //Run at startup, this will create the global repository, only needs to be run once. Repository.Init(GlobalGitRepositoryLocation, true); //Run at startup, this will create the instance specific clone on the local machine, should be run on every service start. //Don't need to do this more than once the first time if (!Repository.IsValid(LocalGitRepositoryLocation)) { Repository.Clone(GlobalGitRepositoryLocation, LocalGitRepositoryLocation, new CloneOptions { IsBare = true }); } //In application code attempt to use the git repository using (var repository = new Repository(LocalGitRepositoryLocation)) { try { repository.Network.Fetch(repository.Network.Remotes[ConfigurationRemote]); } catch { } var refOriginMaster = repository.Refs[ConfigurationRemoteRef]; if (refOriginMaster == null) { return(new Config()); } var sha = refOriginMaster.TargetIdentifier; var configFile = repository.Lookup <Commit>(sha)[GitConfigurationFile]; if (configFile == null || !(configFile.Target is Blob)) { return(new Config()); } using (var fileStream = ((Blob)configFile.Target).GetContentStream()) using (var reader = new StreamReader(fileStream, Encoding.UTF8)) { var result = reader.ReadToEnd(); try { return(new JavaScriptSerializer().Deserialize <Config>(result)); } catch { return(new Config()); } } } }