public void CloneRepo() { var scd = BuildSelfCleaningDirectory(); CloneOptions options = new CloneOptions(); var credentials = new UsernamePasswordCredentials(); credentials.Username = Constants.Identity.Name; credentials.Password = "******"; options.CredentialsProvider += (url, fromUrl, types) => credentials; string clonedRepoPath = Repository.Clone(testUrl, scd.DirectoryPath, options); string file = Path.Combine(scd.DirectoryPath, "testpush.txt"); var rbg = new RandomBufferGenerator(30000); using (var repo = new Repository(clonedRepoPath)) { for (int i = 0; i < 1; i++) { var network = repo.Network.Remotes.First(); FetchOptions fetchOptions = new FetchOptions(); fetchOptions.CredentialsProvider += (url, fromUrl, types) => credentials; repo.Fetch(network.Name, fetchOptions); File.WriteAllBytes(file, rbg.GenerateBufferFromSeed(30000)); repo.Stage(file); Signature author = Constants.Signature; Commit commit = repo.Commit($"Here's a commit {i + 1} i made!", author, author); PushOptions pushOptions = new PushOptions(); pushOptions.CredentialsProvider += (url, fromUrl, types) => credentials; repo.Network.Push(repo.Branches["master"], pushOptions); } } }
public static string Update(string url, Log log, string directory, string repoDirectory = null) { if (string.IsNullOrWhiteSpace(url)) { Utility.Log(LogStatus.Skipped, "Updater", string.Format("No Url specified - {0}", url), log); } else { try { var dir = Path.Combine(directory, url.GetHashCode().ToString("X"), "trunk"); if (Repository.IsValid(dir)) { using (var repo = new Repository(dir)) { repo.Config.Set("user.name", Config.Instance.Username); repo.Config.Set("user.email", Config.Instance.Username + "@joduska.me"); repo.Fetch("origin"); if (repoDirectory != null) { repo.CheckoutPaths("origin/master", new List<String>() { repoDirectory }, new CheckoutOptions { CheckoutModifiers = CheckoutModifiers.Force }); } else { repo.Checkout("origin/master", new CheckoutOptions { CheckoutModifiers = CheckoutModifiers.Force }); } } } else { var oldPath = Path.Combine(directory, url.GetHashCode().ToString("X")); if (Directory.Exists(oldPath)) { Directory.Delete(oldPath, true); } Repository.Clone(url, dir, new CloneOptions { Checkout = true }); using (var repo = new Repository(dir)) { repo.Config.Set("user.name", Config.Instance.Username); repo.Config.Set("user.email", Config.Instance.Username + "@joduska.me"); } } return dir; } catch (Exception ex) { Utility.Log(LogStatus.Error, "Updater", string.Format("{0} - {1}", ex.Message, url), log); } } return string.Empty; }
protected override void CheckForNewLogEntriesImpl() { string directory; string remote; string branch; GetGitSettings(out directory, out remote, out branch); using (var repo = new Repository(directory)) { repo.Fetch(remote); foreach (var commit in repo.Branches[remote + "/" + branch].Commits .Where(c => c.Committer.When.UtcDateTime > MaxDateTimeRetrieved) .Take(30) .OrderBy(c => c.Committer.When.UtcDateTime)) { ProcessLogEntry(repo, commit); } } }
public void FetchChanges(string repoPath) { Repository repository = new Repository(repoPath); repository.Fetch("origin"); }
public void TryUpdateRepository(HttpContext context) { var targetWebRoot = GetTargetWebRoot(); if (String.IsNullOrEmpty(targetWebRoot)) { SendResponse(context, 404, "No web root target."); return; } if (!Repository.IsValid(targetWebRoot)) { SendResponse(context, 404, "No repository configured at: {0}", targetWebRoot); return; } string snapshotId = null; string siteId = null; var handlers = GetProgressHandlers(context); using (var repo = new Repository(targetWebRoot)) { repo.Fetch("origin", onCompletion: handlers.CompletionHandler, onTransferProgress: handlers.TransferProgressHandler, onProgress: msg => SendProgress(context, msg)); repo.Reset(ResetOptions.Hard, "origin/master"); snapshotId = GetLatestSnapShotId(repo); siteId = HostingEnvironment.ApplicationHost.GetSiteID(); var url = GetScmUri(repo); Protocol.KuduCalfCmdUpdateSiteStatus(url, siteId, snapshotId); } SendResponse(context, 200, "Updated root {0} of subscriber {1} to {2}", targetWebRoot, siteId, snapshotId); }