Ejemplo n.º 1
0
 public void AdvertiseReceivePack(Stream output)
 {
     using (var repository = GetRepository()) {
         var pack = new ReceivePack(repository);
         pack.SendAdvertisedRefs(new RefAdvertiser.PacketLineOutRefAdvertiser(new PacketLineOut(output)));
     }
 }
Ejemplo n.º 2
0
 public void Receive(Stream inputStream, Stream outputStream)
 {
     using (var repository = GetRepository()) {
         var pack = new ReceivePack(repository);
         pack.setBiDirectionalPipe(false);
         pack.receive(inputStream, outputStream, outputStream);
     }
 }
Ejemplo n.º 3
0
        public static void Receive(string path, Stream input, Stream output)
        {
            var repositoryPath = RepositoryPath.Resolve(path);

            using (var repository = new Repository(repositoryPath.AbsoluteRootPath))
            {
                var pack = new ReceivePack(repository);
                pack.setBiDirectionalPipe(false);
                pack.receive(input, output, output);
            }
        }
Ejemplo n.º 4
0
 public void OnPostReceive(ReceivePack rp, ICollection <ReceiveCommand> commands)
 {
     try
     {
         if (!string.IsNullOrEmpty(fogBugzApi) && commands != null && commands.Count > 0)
         {
             UpdateFogBugz(rp, commands);
         }
     }
     catch { }
 }
Ejemplo n.º 5
0
        public static void AdvertiseReceivePack(string path, Stream output)
        {
            var repositoryPath = RepositoryPath.Resolve(path);

            using (var repository = new Repository(repositoryPath.AbsoluteRootPath))
            {
                var pack = new ReceivePack(repository);

                pack.SendAdvertisedRefs(
                    new RefAdvertiser.PacketLineOutRefAdvertiser(
                        new PacketLineOut(output)));
            }
        }
Ejemplo n.º 6
0
        public void Receive(Stream inputStream, Stream outputStream)
        {
            using (var repository = GetRepository()) {
                var pack = new ReceivePack(repository);
                pack.setBiDirectionalPipe(false);

                if (PostRecieveHook != null)
                {
                    pack.setPostReceiveHook(PostRecieveHook);
                }

                pack.receive(inputStream, outputStream, outputStream);
            }
        }
Ejemplo n.º 7
0
        // To keep this simple I only look at the head commit and parse the bugzid.
        void UpdateFogBugz(ReceivePack rp, ICollection <ReceiveCommand> commands)
        {
            using (var gitRepo = new GitSharp.Repository(repository.FullPath))
            {
                var commit = gitRepo.Head.CurrentCommit;

                if (commit != null && commit.Message != null && commit.Message.ToLower().Contains("bugzid:"))
                {
                    var bugzid = ParseBugzId(commit.Message);

                    var hashBase = commit.Hash;

                    foreach (var change in commit.Changes)
                    {
                        if (change == null)
                        {
                            continue;
                        }

                        var fileName = change.Name;

                        var fileOldSha = string.Empty;
                        if (change.ReferenceObject != null)
                        {
                            fileOldSha = change.ReferenceObject.Hash;
                        }

                        var fileNewSha = string.Empty;
                        if (change.ChangedObject != null)
                        {
                            fileNewSha = change.ChangedObject.Hash;
                        }

                        var hashBaseParent = string.Empty;
                        if (change.ReferenceCommit != null)
                        {
                            hashBaseParent = change.ReferenceCommit.Hash;
                        }

                        SubmitData(fileOldSha, hashBaseParent, fileNewSha, hashBase, bugzid, fileName, repository.Name);
                    }
                }
            }
        }
Ejemplo n.º 8
0
        private void Run(ReceivePack rp, string hook)
        {
            var processStartInfo = new ProcessStartInfo {
                FileName               = hook, UseShellExecute = false,
                WindowStyle            = ProcessWindowStyle.Hidden, CreateNoWindow = true,
                RedirectStandardOutput = true, RedirectStandardError = true,
                RedirectStandardInput  = true,
                WorkingDirectory       = FullPath
            };
            var appSettings = AppSettings.Current;

            using (var process = new Process {
                StartInfo = processStartInfo
            }) {
                if (!appSettings.RunHooksSilently)
                {
                    process.OutputDataReceived += (d, r) => { if (!String.IsNullOrWhiteSpace(r.Data))
                                                              {
                                                                  rp.sendMessage(r.Data);
                                                              }
                    };
                    process.ErrorDataReceived += (d, r) => { if (!String.IsNullOrWhiteSpace(r.Data))
                                                             {
                                                                 rp.sendError(r.Data);
                                                             }
                    };
                }
                process.Start();
                process.BeginOutputReadLine();
                process.BeginErrorReadLine();
                foreach (var command in rp.getAllCommands())
                {
                    process.StandardInput.WriteLine(command.getOldId().Name + " " + command.getNewId().Name + " " +
                                                    command.getRefName());
                }
                process.StandardInput.Close();
                process.WaitForExit((int)appSettings.HookTimeout.TotalMilliseconds);
                process.WaitForExit();
                process.Close();
            }
        }
Ejemplo n.º 9
0
        public void OnPostReceive(ReceivePack rp, ICollection <ReceiveCommand> commands)
        {
            var hooksDirectory = new DirectoryInfo(Path.Combine(FullPath, "hooks"));

            if (!hooksDirectory.Exists)
            {
                hooksDirectory = new DirectoryInfo(Path.Combine(FullPath, ".git/hooks"));
                if (!hooksDirectory.Exists)
                {
                    return;
                }
            }
            var hooks = hooksDirectory
                        .GetFiles("post-receive*")
                        .Where(hook => !hook.FullName.EndsWith(".sample"));

            foreach (var hook in hooks)
            {
                Run(rp, hook.FullName);
            }
        }
Ejemplo n.º 10
0
        private ActionResult GetInfoRefs(String project, String service)
        {
            Response.StatusCode = 200;

            Response.ContentType = String.Format("application/x-{0}-advertisement", service);
            SetNoCache();
            Response.Write(FormatMessage(String.Format("# service={0}\n", service)));
            Response.Write(FlushMessage());

            var directory = GetDirectoryInfo(project);

            if (GitSharp.Repository.IsValid(directory.FullName, true))
            {
                using (var repository = new GitSharp.Repository(directory.FullName))
                {
                    if (String.Equals("git-receive-pack", service, StringComparison.InvariantCultureIgnoreCase))
                    {
                        using (var pack = new ReceivePack(repository))
                        {
                            pack.SendAdvertisedRefs(new RefAdvertiser.PacketLineOutRefAdvertiser(new PacketLineOut(Response.OutputStream)));
                        }
                    }
                    else if (String.Equals("git-upload-pack", service, StringComparison.InvariantCultureIgnoreCase))
                    {
                        using (var pack = new UploadPack(repository))
                        {
                            pack.SendAdvertisedRefs(new RefAdvertiser.PacketLineOutRefAdvertiser(new PacketLineOut(Response.OutputStream)));
                        }
                    }
                }

                return(new EmptyResult());
            }
            else
            {
                return(new HttpNotFoundResult());
            }
        }
Ejemplo n.º 11
0
        private ActionResult ExecuteReceivePack(string project)
        {
            Response.ContentType = "application/x-git-receive-pack-result";
            SetNoCache();

            var directory = GetDirectoryInfo(project);

            if (GitSharp.Repository.IsValid(directory.FullName, true))
            {
                using (var repository = new GitSharp.Repository(directory.FullName))
                    using (var pack = new ReceivePack(repository))
                    {
                        pack.setBiDirectionalPipe(false);
                        pack.receive(GetInputStream(), Response.OutputStream, Response.OutputStream);
                    }

                return(new EmptyResult());
            }
            else
            {
                return(new HttpNotFoundResult());
            }
        }