简体   繁体   English

如何使用git服务器端钩子与gitlab更改提交的内容

[英]How to change the contents of a commit using git server side hooks with gitlab

I have installed gitlab (manually) at ubuntu 12.04. 我在ubuntu 12.04上安装了gitlab(手动)。

There are some repositories that contain PSD (Adobe photoshop files). 有一些包含PSD的存储库(Adobe photoshop文件)。 What we hope to achieve is that whenever someone is pushing a commit to the gitlab server, it will automatically: 我们希望实现的是,每当有人将提交推送到gitlab服务器时,它将自动:

  1. Convert PSD to PNG 将PSD转换为PNG
  2. Move to PSD to dropbox (or other cloud storage) 转移到PSD到Dropbox(或其他云存储)
  3. Remove PSD from the commit 从提交中删除PSD
  4. Add the PNG to the commit 将PNG添加到提交中

Note: Step 2 is irrelevant to this question. 注意:第2步与此问题无关。

Anyway, we have managed to download tools to convert PSD to PNG which involves installing Ruby, some Ruby Gems, and PSD.rb (Google PSD.rb if anyone is interested) 无论如何,我们已经设法下载工具将PSD转换为PNG,其中包括安装Ruby,一些Ruby Gems和PSD.rb(谷歌PSD.rb,如果有人有兴趣)

The problem is we do not wish to manage the installations (Ruby, gems, and etc.) on client side as we assume it will be hard for us to maintain the installations on a number of windows, mac, and linux machines. 问题是我们不希望在客户端管理安装(Ruby,gems等),因为我们认为我们很难在许多windows,mac和linux机器上维护安装。

So what we are hoping to achieve is that the above will be executed in server side hooks when someone do a git push and there are PSD files in the commit. 所以我们希望实现的是,当有人进行git推送并且提交中有PSD文件时,上述内容将在服务器端钩子中执行。

We have tried to do that in pre-receive hook but we can't manage to modify the contents of the commit (eg remove PSD from commit, Add new file - PNG to the commit) 我们已尝试在预接收挂钩中执行此操作但我们无法管理修改提交的内容(例如,从提交中删除PSD,将新文件 - PNG添加到提交中)

Is there any other way to do the above on server side? 在服务器端有没有其他方法可以做到这一点? Or there are other methods we can explore? 或者我们可以探索其他方法?

You cannot modify a commit. 您无法修改提交。

You can reject a commit, and having done so, you can make a new and different commit based on what you received. 您可以拒绝提交,并且在完成提交后,您可以根据收到的内容进行新的不同提交。

That is, you take what you received, save it elsewhere, reject the commit, and then take the saved stuff and make your changes and make a new commit out of it. 也就是说,你拿走你收到的东西,把它保存在别的地方,拒绝提交,然后拿出保存的东西,做出你的改变并做出新的提交。 To the user who attempted to push something, it looks like their commit was rejected, and then someone else (who is very fast at typing) did all the same work they did but then cleaned it up and committed a slightly different version while they were reading the "rejected" message. 对于试图推送某些东西的用户来说,看起来他们的提交被拒绝了,然后其他人(打字速度非常快)做了他们所做的所有相同的工作,但随后清理了它并提交了一个略有不同的版本阅读“被拒绝”的消息。

Note that I am not particularly recommending this idea, nor going to write you code to achieve it, but it should work just fine. 请注意,我并不是特别推荐这个想法,也不会写代码来实现它,但它应该工作得很好。

You can also use a different two-step method, where there are two different servers involved: 您还可以使用不同的两步方法,其中涉及两个不同的服务器:

  • server "pure" delivers only PNG contents, and does not take pushes from users 服务器“pure”仅提供PNG内容,不会从用户那里获取推送
  • server "converter" takes pushes from users, accepts them (no rejection here), then cleans them up and pushes the cleaned-up version to "pure" 服务器“转换器”从用户那里接受推送,接受它们(这里没有拒绝),然后清理它们并将清理后的版本推送到“纯粹”

Users thus read items from "pure", write stuff, push it to "converter", and then read back from "pure" to get the updated (different) commits and discard their "unclean", un-converted commits. 因此,用户从“纯”读取项目,写入内容,将其推送到“转换器”,然后从“纯”读回以获取更新(不同)提交并丢弃其“不清洁”,未转换的提交。

This is exactly the same process as the first system, except that it's more obvious to everyone how it works, and users must know how to fetch from "pure" and push to "converter". 这与第一个系统完全相同,只是每个人的工作方式更加明显,用户必须知道如何从“纯”中获取并推送到“转换器”。 In the first system, a single git repository and machine acts as both "pure" (when delivering cleaned-up stuff) and "converter" (when receiving and secretly saving, but then rejecting, a push). 在第一个系统中,单个git存储库和机器既充当“纯粹”(当提供清理的东西时)和“转换器”(当接收并秘密保存,但随后拒绝,推送时)。

Rewriting a commit on the server is a bad idea, for the same reasons as rewriting history is. 重写服务器上的提交是一个坏主意,原因与重写历史相同。

Another option is to setup git-annex and dropboxannex for storing the PSDs on dropbox. 另一种选择是设置git-annexdropboxannex ,用于在dropbox上存储PSD。

The server commit hook can reject any pushed that has a non- git-annex -ed PSD. 服务器提交挂钩可以拒绝任何具有非git-annex -ed PSD的推送。 On the client, a pre-commit hook could automate adding the PSDs to git-annex . 在客户端上,预提交挂钩可以自动将PSD添加到git-annex

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM