コード例 #1
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();
			}
		}
コード例 #2
0
ファイル: Repository.cs プロジェクト: hafstrom/git-dot-aspx
 public void AdvertiseReceivePack(Stream output)
 {
     using (var repository = GetRepository()) {
         var pack = new ReceivePack(repository);
         pack.SendAdvertisedRefs(new RefAdvertiser.PacketLineOutRefAdvertiser(new PacketLineOut(output)));
     }
 }
コード例 #3
0
ファイル: RpcController.cs プロジェクト: tolism7/git-dot-aspx
 public ActionResult ReceivePack(string project)
 {
     return ExecuteRpc(project, Rpc.ReceivePack, repository => {
         var pack = new ReceivePack(repository);
         pack.setBiDirectionalPipe(false);
         pack.receive(Request.InputStream, Response.OutputStream, Response.OutputStream);
     });
 }
コード例 #4
0
ファイル: Repository.cs プロジェクト: mios-fi/mios.guvnor
		public void Receive(Stream inputStream, Stream outputStream) {
			using (var repository = GetRepository()) {
				var pack = new ReceivePack(repository);
				pack.setPostReceiveHook(new PostReceiveFileHook(FullPath));
				pack.setBiDirectionalPipe(false);
				pack.receive(inputStream, outputStream, outputStream);
			}
		}
コード例 #5
0
 public override void Receive(Stream inputStream, Stream outputStream)
 {
     using (var repository = GetRepository())
     {
         var pack = new ReceivePack(repository);
         pack.setBiDirectionalPipe(false);
         pack.receive(inputStream, outputStream, outputStream);
     }
 }
コード例 #6
0
 public void OnPostReceive(ReceivePack rp, ICollection<ReceiveCommand> commands)
 {
     try
     {
         if (!string.IsNullOrEmpty(fogBugzApi) && commands != null && commands.Count > 0)
         {
             UpdateFogBugz(rp, commands);
         }
     }
     catch { }
 }
コード例 #7
0
        public void ReceivePack(string project)
        {
            Response.ContentType = "application/x-git-receive-pack-result";
            WriteNoCache();

            using (var repository = repositories.GetRepository(project)) {
                var pack = new ReceivePack(repository);
                pack.setBiDirectionalPipe(false);
                pack.receive(Request.InputStream, Response.OutputStream, Response.OutputStream);
            }
        }
コード例 #8
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);
			}
		}
コード例 #9
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);
                    }
                }
            }
        }
コード例 #10
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,
         WorkingDirectory = FullPath
     };
     var appSettings = AppSettings.FromAppConfig();
     using (var process = Process.Start(processStartInfo)) {
         if(!appSettings.RunHooksSilently) {
             process.OutputDataReceived += (d, r) => rp.sendMessage(r.Data);
             process.ErrorDataReceived += (d, r) => rp.sendError(r.Data);
         }
         process.BeginOutputReadLine();
         process.BeginErrorReadLine();
         process.WaitForExit((int)appSettings.HookTimeout.TotalMilliseconds);
         process.Close();
     }
 }
コード例 #11
0
            public override void Execute(DaemonClient client, Repository db)
            {
                EndPoint peer = client.Peer;

                var ipEndpoint = peer as IPEndPoint;

                if (ipEndpoint == null)
                {
                    throw new InvalidOperationException("peer must be a IPEndPoint");
                }

                string       host   = Dns.GetHostEntry(ipEndpoint.Address).HostName ?? ipEndpoint.Address.ToString();
                var          rp     = new ReceivePack(db);
                Stream       stream = client.Stream;
                const string name   = "anonymous";
                string       email  = name + "@" + host;

                rp.setRefLogIdent(new PersonIdent(name, email));
                rp.receive(stream, stream, null);
            }
コード例 #12
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();
            }
        }
コード例 #13
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();
            }
        }
コード例 #14
0
ファイル: IPreReceiveHook.cs プロジェクト: spraints/GitSharp
 public void onPreReceive(ReceivePack rp, ICollection<ReceiveCommand> commands)
 {
 }
コード例 #15
0
ファイル: Repository.cs プロジェクト: JasonRowe/git-dot-aspx
        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);
            }
        }
コード例 #16
0
 public void onPreReceive(ReceivePack rp, ICollection <ReceiveCommand> commands)
 {
 }
コード例 #17
0
 public void OnPostReceive(ReceivePack rp, ICollection <ReceiveCommand> commands)
 {
 }
コード例 #18
0
ファイル: IPostReceiveHook.cs プロジェクト: spraints/GitSharp
 public void OnPostReceive(ReceivePack rp, ICollection<ReceiveCommand> commands)
 {
 }
コード例 #19
0
ファイル: Daemon.cs プロジェクト: dev218/GitSharp
			public override void Execute(DaemonClient client, Repository db)
			{
				EndPoint peer = client.Peer;

				var ipEndpoint = peer as IPEndPoint;
				if (ipEndpoint == null)
				{
					throw new InvalidOperationException("peer must be a IPEndPoint");
				}

				string host = Dns.GetHostEntry(ipEndpoint.Address).HostName ?? ipEndpoint.Address.ToString();
				var rp = new ReceivePack(db);
				Stream stream = client.Stream;
				const string name = "anonymous";
				string email = name + "@" + host;
				rp.setRefLogIdent(new PersonIdent(name, email));
				rp.receive(stream, stream, null);
			}
コード例 #20
0
ファイル: IPostReceiveHook.cs プロジェクト: kkl713/GitSharp
 public void OnPostReceive(ReceivePack rp, List <ReceiveCommand> commands)
 {
 }
コード例 #21
0
ファイル: TransportLocal.cs プロジェクト: yolanother/GitSharp
            public InternalLocalPushConnection(TransportLocal transport)
                : base(transport)
            {
                Repository dst;
                try
                {
                    dst = new Repository(transport.remoteGitDir);
                }
                catch (IOException)
                {
                    throw new TransportException(uri, "Not a Git directory");
                }

                PipedInputStream in_r;
                PipedOutputStream in_w;

                PipedInputStream out_r;
                PipedOutputStream out_w;
                try
                {
                    in_r = new PipedInputStream();
                    in_w = new PipedOutputStream(in_r);

                    out_r = new PipedInputStream();
                    out_w = new PipedOutputStream(out_r);
                }
                catch (IOException ex)
                {
                    dst.Close();
                    throw new TransportException(uri, "Cannot connect pipes", ex);
                }

                worker = new Thread(() =>
                {
                    try
                    {
                        ReceivePack rp = new ReceivePack(dst);
                        rp.receive(out_r, in_w, null);
                    }
                    catch (IOException)
                    {
                        // Client side of the pipes should report the problem.
                    }
                    catch (Exception)
                    {
                        // Clients side will notice we went away, and report.
                    }
                    finally
                    {
                        try
                        {
                            out_r.close();
                        }
                        catch (IOException)
                        {
                            // Ignore close failure, we probably crashed above.
                        }

                        try
                        {
                            in_w.close();
                        }
                        catch (IOException)
                        {
                            // Ignore close failure, we probably crashed above.
                        }

                        dst.Close();
                    }
                });
                worker.Name = "JGit-Receive-Pack";
                worker.Start();

                init(in_r, out_w);
                readAdvertisedRefs();
            }
コード例 #22
0
            public InternalLocalPushConnection(TransportLocal transport)
                : base(transport)
            {
                Repository dst;

                try
                {
                    dst = new Repository(transport.remoteGitDir);
                }
                catch (IOException)
                {
                    throw new TransportException(uri, "Not a Git directory");
                }

                PipedInputStream  in_r;
                PipedOutputStream in_w;

                PipedInputStream  out_r;
                PipedOutputStream out_w;

                try
                {
                    in_r = new PipedInputStream();
                    in_w = new PipedOutputStream(in_r);

                    out_r = new PipedInputStream();
                    out_w = new PipedOutputStream(out_r);
                }
                catch (IOException ex)
                {
                    dst.Close();
                    throw new TransportException(uri, "Cannot connect pipes", ex);
                }

                worker = new Thread(() =>
                {
                    try
                    {
                        ReceivePack rp = new ReceivePack(dst);
                        rp.receive(out_r, in_w, null);
                    }
                    catch (IOException)
                    {
                        // Client side of the pipes should report the problem.
                    }
                    catch (Exception)
                    {
                        // Clients side will notice we went away, and report.
                    }
                    finally
                    {
                        try
                        {
                            out_r.close();
                        }
                        catch (IOException)
                        {
                            // Ignore close failure, we probably crashed above.
                        }

                        try
                        {
                            in_w.close();
                        }
                        catch (IOException)
                        {
                            // Ignore close failure, we probably crashed above.
                        }

                        dst.Close();
                    }
                });
                worker.Name = "JGit-Receive-Pack";
                worker.Start();

                init(in_r, out_w);
                readAdvertisedRefs();
            }
コード例 #23
0
ファイル: IPostReceiveHook.cs プロジェクト: stschake/GitSharp
 public void OnPostReceive(ReceivePack rp, List<ReceiveCommand> commands)
 {
 }
コード例 #24
0
        private static void HandleInfoRefsGet(HttpContext context, GitRoute route)
        {
            var gitService = context.Request.QueryString["service"];

            if (string.IsNullOrWhiteSpace(gitService) || !gitService.StartsWith("git-"))
            {
                SendFile(context, route, "text/plain; charset=utf-8");
            }
            else
            {
                var service = gitService.Substring(4);
                context.Response.ContentType = string.Format("application/x-git-{0}-advertisement", service);
                context.Response.Write(GitString("# service=git-" + service + "\n"));
                context.Response.Write("0000");

                if (service == "upload-pack")
                {
                    var pack = new UploadPack(route.Repository);
                    pack.sendAdvertisedRefs(new RefAdvertiser.PacketLineOutRefAdvertiser(new PacketLineOut(context.Response.OutputStream)));
                }
                else if (service == "receive-pack")
                {
                    VerifyAccess(context);
                    var pack = new ReceivePack(route.Repository);
                    pack.SendAdvertisedRefs(new RefAdvertiser.PacketLineOutRefAdvertiser(new PacketLineOut(context.Response.OutputStream)));
                }
            }
        }
コード例 #25
0
 private static void HandleReceivePackPost(HttpContext context, GitRoute route)
 {
     VerifyAccess(context);
     context.Response.ContentType = "application/x-git-receive-pack-result";
     var pack = new ReceivePack(route.Repository);
     pack.setBiDirectionalPipe(false);
     pack.receive(context.Request.InputStream, context.Response.OutputStream, context.Response.OutputStream);
 }
コード例 #26
0
ファイル: IPreReceiveHook.cs プロジェクト: kkl713/GitSharp
 public void onPreReceive(ReceivePack rp, List <ReceiveCommand> commands)
 {
 }