public void Commit(string author, string comment, params LogPropertyInfo[] properties) { if (this.transactionName != null) { var diffCommand = new GitCommand(this.BasePath, "diff") { "HEAD", new GitCommandItem("stat"), new GitCommandItem("binary") }; var output = diffCommand.ReadLine(); FileUtility.Prepare(this.transactionPatchPath); File.WriteAllText(this.transactionPatchPath, output); this.transactionMessageList.Add(comment); this.transactionPropertyList.AddRange(properties); return; } try { var statusCommand = new GitCommand(this.BasePath, "status") { new GitCommandItem('s') }; var items = statusCommand.ReadLines(true); if (items.Length != 0) { var authorValue = new GitAuthor(author); GitConfig.SetValue(this.BasePath, "user.email", authorValue.Email == string.Empty ? "<>" : authorValue.Email); GitConfig.SetValue(this.BasePath, "user.name", authorValue.Name); var commitCommand = new GitCommitCommand(this.BasePath, author, comment); var result = commitCommand.Run(this.logService); this.logService?.Debug(result); var log = GitLogInfo.GetLatestLog(this.BasePath); this.repositoryInfo.Revision = log.CommitID; this.repositoryInfo.ModificationInfo = new SignatureDate(author, log.CommitDate); this.SetNotes(properties); //this.isModified = true; //this.Pull(); //this.Push(); //this.PushNotes(); } else { this.logService?.Debug("repository no changes. \"{0}\"", this.BasePath); } } catch (Exception e) { this.logService?.Warn(e); throw; } }
public IRepository CreateInstance(RepositorySettings settings) { var remoteUri = new Uri(settings.RemotePath); var baseUri = new Uri(settings.BasePath); var originUri = UriUtility.MakeRelativeOfDirectory(baseUri, remoteUri); var repositoryName = settings.RepositoryName == string.Empty ? "master" : settings.RepositoryName; if (Directory.Exists(settings.BasePath) == false) { var cloneCommand = new GitCommand(null, "clone") { (GitPath)remoteUri, new GitCommandItem('b'), repositoryName, (GitPath)settings.BasePath, new GitCommandItem("single-branch") }; cloneCommand.Run(); var fetchCommand = new GitCommand(settings.BasePath, "fetch") { "origin", "refs/notes/commits:refs/notes/commits", }; fetchCommand.Run(); var id = this.GetID(settings.RemotePath, repositoryName); this.SetID(settings.BasePath, repositoryName, id); GitConfig.SetValue(settings.BasePath, "remote.origin.url", originUri); var repositoryInfo = this.GetRepositoryInfo(settings.RemotePath, repositoryName); return(new GitRepository(this, settings, repositoryInfo)); } else { var repositoryInfo = this.GetRepositoryInfo(settings.BasePath, repositoryName); return(new GitRepository(this, settings, repositoryInfo)); } }
private string GetDescription(string repositoryPath, string repositoryName) { return(GitConfig.GetValue(repositoryPath, $"branch.{repositoryName}.description")); }
private bool HasDescription(string repositoryPath, string repositoryName) { return(GitConfig.HasValue(repositoryPath, $"branch.{repositoryName}.description")); }
private void SetDescription(string repositoryPath, string repositoryName, string description) { GitConfig.SetValue(repositoryPath, $"branch.{repositoryName}.description", $"{description}"); }
private SignatureDate GetCreationInfo(string repositoryPath, string repositoryName) { return(SignatureDate.Parse(GitConfig.GetValue(repositoryPath, $"branch.{repositoryName}.createdDateTime"), CultureInfo.GetCultureInfo("en-US"))); }
private bool HasCreationInfo(string repositoryPath, string repositoryName) { return(GitConfig.HasValue(repositoryPath, $"branch.{repositoryName}.createdDateTime")); }
private void SetCreationInfo(string repositoryPath, string repositoryName, SignatureDate signatureDate) { GitConfig.SetValue(repositoryPath, $"branch.{repositoryName}.createdDateTime", $"{signatureDate.ToString(CultureInfo.GetCultureInfo("en-US"))}"); }
private Guid GetID(string repositoryPath, string repositoryName) { return(Guid.Parse(GitConfig.GetValue(repositoryPath, $"branch.{repositoryName}.id"))); }
private bool HasID(string repositoryPath, string repositoryName) { return(GitConfig.HasValue(repositoryPath, $"branch.{repositoryName}.id")); }
private void UnsetID(string repositoryPath, string repositoryName) { GitConfig.UnsetValue(repositoryPath, $"branch.{repositoryName}.id"); }
private void SetID(string repositoryPath, string repositoryName, Guid guid) { GitConfig.SetValue(repositoryPath, $"branch.{repositoryName}.id", $"{guid}"); }
public void InitializeRepository(string basePath, string repositoryPath, params LogPropertyInfo[] properties) { var cloneCommand = new GitCommand(null, "clone") { (GitPath)repositoryPath, (GitPath)basePath, }; if (cloneCommand.TryRun() == true) { var fetchCommand = new GitCommand(basePath, "fetch") { "origin", "refs/notes/commits:refs/notes/commits", }; fetchCommand.Run(); GitConfig.SetValue(basePath, "receive.denyCurrentBranch", "ignore"); return; } var initCommand = new GitCommand(null, "init") { (GitPath)basePath }; initCommand.Run(); var configCommand = new GitCommand(basePath, "config") { "receive.denyCurrentBranch", "ignore" }; configCommand.Run(); DirectoryUtility.Copy(repositoryPath, basePath); foreach (var item in GetEmptyDirectories(basePath)) { File.WriteAllText(Path.Combine(item, KeepExtension), string.Empty); } var query = from item in DirectoryUtility.GetAllFiles(basePath, "*", true) select(GitPath) PathUtility.GetFullPath(item); var itemList = query.ToList(); var addCommand = new GitAddCommand(basePath, query.ToArray()); addCommand.Run(); var commitCommand = new GitCommitCommand(basePath, Environment.UserName, "first commit"); commitCommand.Run(); var props = properties.Select(item => (GitPropertyValue)item).ToArray(); var propText = propertySerializer.Serialize(props); var addNotesCommand = new GitCommand(basePath, "notes") { "add", GitCommandItem.FromMessage(propText) }; addNotesCommand.Run(); this.SetID(basePath, "master", Guid.NewGuid()); }