Reputation: 15319
In my git repository I have a file workflow.vsd
that represents a diagram created in Microsoft Visio.
Since not everybody in our team has Visio installed, whoever changes the workflow.vsd
must also generate a correspondent workflow.png
.
The problem is that quite often, people commit a new version of the vsd
file and forget to commit the png
, making the image outdated.
Is there some way for git to allow a commit only if both workflow.vsd
and workflow.png
are added under the same commit hash?
In other words, I want to commit the Visio project only and only if png is also commited:
git add workflow.vsd worflow.png
git commit
and this should fail:
git add workflow.vsd
git commit
Upvotes: 1
Views: 72
Reputation: 1380
You'll want to look in to commit hooks - Git allows access to several points of the process, one of which being pre-commit, in which you can inject some code.
You'll be able to check for those files with something along the lines of
git status -s | grep "workflow.vsd"
.
You could then either also check for the png
and fail if it isn't present, or run a script which automatically generates the png
as escitalopram suggests.
Upvotes: 2
Reputation: 3856
I'd recommend against that setup. Users shouldn't be required to put generated stuff into version control. In programming we have build tools to automatically generate derived files from »source files« such as the vsd. Maybe you can look into Makefiles or Maven or whatever build tool you see fit (although I don't know if there's a tool to make pngs from vsds).
If you must have the png in versioning, the other way to go around it would be a commit hook, either on »the git server« or on the local repositories. Still, you need to have a tool that can automatically generate pngs.
If you don't have the tool either, you can still write a commit hook that checks programmatically if both files have been changed or not, and reject the commit if necessary.
Upvotes: 1