public Changeset Commit(ICommitScmFileArgs args) { Reset(args.RepositoryPath); if (!args.All) { foreach (var file in args.Files) { AddFileToIndex(args.RepositoryPath, file); } } var ab = new ArgBuilder(); ab.Add("commit"); ab.AddIf(args.All, "--all"); using (var msgFile = new TempFile("msg")) { File.WriteAllText(msgFile.FilePath, args.Message); ab.Add($"--file=\"{msgFile}\""); RunCommand(ab, args); } return(null); // todo }
public Changeset Commit(ICommitScmFileArgs args) { var ab = new ArgBuilder(); TempFile fileList = null; ab.Add("commit"); if (args.All) { ab.Add("--addremove"); } else if (args.Files?.Any() == true) { fileList = CreateFileList(args.Files); ab.Add($"--include listfile:\"{fileList}\""); } try { using (var msgFile = new TempFile("msg")) { File.WriteAllText(msgFile.FilePath, args.Message); ab.Add($"--logfile \"{msgFile}\""); RunCommand(ab, args); } } finally { fileList?.Dispose(); } return(null); // todo }
public Changeset[] UploadChangesets(IUploadChangesetArgs args) { var currentBranch = GetBranches(new GetBranchesArgs { Current = true, RepositoryPath = args.RepositoryPath }).FirstOrDefault(); var targetRev = args.TargetRev.WhenNullOrEmpty(currentBranch); var destination = args.Destination.WhenNullOrEmpty("origin"); var query = new RevisionQuery { FromRevisionId = targetRev, ToRevisionId = $"{destination}/{targetRev}" }; var changeSets = GetChangesets(new GetChangesetsArgs { RepositoryPath = args.RepositoryPath, Query = query }); if (!args.CheckOnly) { var ab = new ArgBuilder(); ab.Add("push"); ab.Add(args.Destination); ab.Add(args.TargetRev); } return(changeSets); }
public FileDiff[] GetDiff(IGetDiffArgs args) { var ab = new ArgBuilder(); ab.Add("diff"); TempFile fileList = null; if (args.Files != null) { if (args.Files.Any()) { fileList = CreateFileList(args.Files); ab.Add($"--include listfile:\"{fileList}\""); } } try { if (args.Query != null) { ab.Add($"--rev \"{FormatQuery(args.Query)}\""); } var lines = RunCommand(ab, args); return(FileDiff.FromLines(lines)); } finally { fileList?.Dispose(); } }
public string GetRepositoryRoot(string folder) { var ab = new ArgBuilder(); ab.Add("rev-parse"); ab.Add("--show-toplevel"); return(RunCommand(ab, null, folder).LastOrDefault()); }
private void AddFileToIndex(string repositoryPath, string filename) { var ab = new ArgBuilder(); ab.Add("add"); ab.Add(filename); RunCommand(ab, repositoryPath); }
public void CreateRepository(INewRepositoryArgs args) { Directory.CreateDirectory(args.RepositoryPath); var ab = new ArgBuilder(); ab.Add("init"); ab.Add(args.RepositoryPath.Enclose('"')); RunCommand(ab, args); }
public void CloneRepository(ICloneRepositoryArgs args) { var ab = new ArgBuilder(); ab.Add("clone"); ab.Add(args.Source.Enclose('"')); ab.Add(args.RepositoryPath.Enclose('"')); RunCommand(ab, args); }
public Changeset[] GetChangesets(IGetChangesetsArgs args) { var ab = new ArgBuilder(); ab.Add("log"); ab.Add(args.Current ? "-n 1" : FormatQuery(args.Query)); ab.Add($"--pretty=\"{XmlLogTemplate}\""); return(Changeset.FromXml(RunCommand(ab, args))); }
public void CheckoutChangeset(ICheckoutChangesetArgs args) { var ab = new ArgBuilder(); ab.Add("checkout"); ab.Add(args.TargetRev); ab.AddIf(args.Force, "--force"); ab.AddIf(!String.IsNullOrEmpty(args.NewBranchName), $"-b \"{args.NewBranchName}\""); RunCommand(ab, args); }
public void Revert(IResetScmFilesArgs args) { var ab = new ArgBuilder(); ab.Add("revert"); var fileList = CreateFileList(args.Files); ab.Add($"--include listfile:\"{fileList}\""); RunCommand(ab, args); }
public byte[] GetFileContents(IGetScmFileContentArgs args) { using (var tempFile = new TempFile()) { var ab = new ArgBuilder(); ab.Add("cat"); ab.Add(args.File); ab.Add($"--output \"{tempFile}\""); RunCommand(ab, args); return(File.ReadAllBytes(tempFile.FilePath)); } }
public void RenameScmFile(IRenameScmFileArgs args) { var ab = new ArgBuilder(); ab.Add("rename"); if (args.MarkOnly) { ab.Add("--after"); } ab.Add(args.Filename.Enclose('"')); ab.Add(args.NewFilename.Enclose('"')); RunCommand(ab, args); }
private void CreateBookmark(INewBranchArgs args) { var ab = new ArgBuilder(); ab.Add("bookmarks"); if (!String.IsNullOrEmpty(args.TargetChangeset)) { ab.Add($"--rev \"{args.TargetChangeset}\""); } ab.AddIf(args.Force, "--force"); ab.Add(args.Name); RunCommand(ab, args); }
public ScmFile[] GetFiles(IGetScmFileArgs args) { var command = args.All ? "files" : "status"; var ab = new ArgBuilder(); ab.Add(command); TempFile fileList = null; if (args.Files != null) { if (args.Files.Any()) { fileList = CreateFileList(args.Files); ab.Add($"--include listfile:\"{fileList}\""); } } string[] files; try { if (args.Query != null) { ab.Add($"--rev \"{FormatQuery(args.Query)}\""); } files = RunCommand(ab, args); } finally { fileList?.Dispose(); } var dict = new Dictionary <char, ScmFileStatus> { { 'C', ScmFileStatus.Clean }, { 'M', ScmFileStatus.Modified }, { 'A', ScmFileStatus.Added }, { 'R', ScmFileStatus.Removed }, { '?', ScmFileStatus.Unknown }, { '!', ScmFileStatus.Missing }, }; return(files.Select(file => { var status = dict[file[0]]; var localFilename = file.Substring(2); return new ScmFile(args.RepositoryPath, localFilename, status); }).ToArray()); }
public Changeset[] UploadChangesets(IUploadChangesetArgs args) { var ab = new ArgBuilder(); ab.Add(args.CheckOnly ? "outgoing" : "push"); ab.Add(args.Destination); if (args.TargetRev != null) { ab.Add($"--rev {FormatQuery(args.TargetRev)}"); } var r = RunCommand(ab, args); return(args.CheckOnly ? ParseChangesets(r) : new Changeset[] { }); }
public Changeset[] DownloadChangesets(IDownloadChangesetArgs args) { var ab = new ArgBuilder(); ab.Add("fetch"); ab.Add(args.Source); ab.Add(args.TargetRev); RunCommand(ab, args); return(GetChangesets(new GetChangesetsArgs { RepositoryPath = args.RepositoryPath, Query = "..@{u}" })); }
private void Reset(string repositoryPath) { var ab = new ArgBuilder(); ab.Add("reset"); RunCommand(ab, repositoryPath); }
public string GetRepositoryRoot(string path) { var ab = new ArgBuilder(); ab.Add("root"); return(RunCommand(ab, null, path).LastOrDefault()); }
public Changeset[] DownloadChangesets(IDownloadChangesetArgs args) { if (String.IsNullOrEmpty(args.Source)) { throw new ArgumentNullException(nameof(args.Source)); } var ab = new ArgBuilder(); ab.Add(args.CheckOnly ? "incoming" : "pull"); ab.Add(args.Source); if (args.TargetRev != null) { ab.Add($"--rev {FormatQuery(args.TargetRev)}"); } var r = RunCommand(ab, args); return(args.CheckOnly ? ParseChangesets(r) : new Changeset[] { }); }
public Changeset[] GetChangesets(IGetChangesetsArgs args) { var ab = new ArgBuilder(); if (args.Current) { ab.Add("parent"); } else { ab.Add("log"); if (args.Query != null) { ab.Add($"--rev \"{FormatQuery(args.Query)}\""); } } ab.Add($"--template \"{XmlLogTemplate}\""); var lines = RunCommand(ab, args); return(Changeset.FromXml(lines)); }
private void CreatePermanentBranch(INewBranchArgs args) { if (!String.IsNullOrEmpty(args.TargetChangeset)) { throw new NotSupportedException($"'{nameof(args.TargetChangeset)}' is not supported for permanent branches."); } var ab = new ArgBuilder(); ab.Add("branch"); ab.Add($"\"{args.Name}\""); ab.AddIf(args.Force, "--force"); RunCommand(ab, args); if (args.Commit) { Commit(new CommitScmFileArgs { RepositoryPath = args.RepositoryPath, Message = $"Opened branch '{args.Name}'" }); } }
public void CheckoutChangeset(ICheckoutChangesetArgs args) { var ab = new ArgBuilder(); ab.Add("update"); if (args.Clean) { ab.Add("--clean"); } if (args.TargetRev != null) { ab.Add(args.TargetRev); } RunCommand(ab, args); if (!String.IsNullOrEmpty(args.NewBranchName)) { CreateBranch(new NewBranchArgs { Name = args.NewBranchName, RepositoryPath = args.RepositoryPath }); } }
public string[] GetBranches(IGetBranchesArgs args) { var ab = new ArgBuilder(); ab.Add(args.Current ? "branch" : "branches"); IEnumerable <string> result = RunCommand(ab, args); if (!args.Current) { result = result.Select(r => { var m = Regex.Match(r, @"^(?<name>.*?)\s+[0-9]+:[a-f0-9]+(?<inactive> \(inactive\))?"); return(!m.Success ? null : m.Groups["name"].Value); }); } return(result.Where(r => !String.IsNullOrEmpty(r)).ToArray()); }
public string[] GetBranches(IGetBranchesArgs args) { if (args.Permanent) { ThrowPermanentBranchException(); } var ab = new ArgBuilder(); ab.Add("branch"); var branches = RunCommand(ab, args) .Select(line => Regex.Match(line, @"^(?<active>\*)? *(?<name>.*)$")); if (args.Current) { branches = branches.Where(b => b.Groups["active"].Value == "*"); } return(branches.Select(b => b.Groups["name"].Value).ToArray()); }