To hook or not to hook - git

Our customized IDE outputs XML encoded files that make them look like binary files. Errors and merges of these files do not work.

We can create ASCII versions of these files using the tr command. I would like to move on to a state in which these files are always automatically converted to ascii before they are made.

I took my copy of version control with Git and it completely warns me against using interceptors if I really don't need to.

Should I use a hook for this purpose? Or can I do something else so that the files are always converted before committing?

Windows XP with msysgit 1.7.4

- = update = -

Thank you all for your help and patience. Looking at this question I tried the following, but it does not work:

 echo "*.xrp filter=xrp" > .git/info/attributes git config --global filter.xrp.clean 'tr -cd '\''\11\12\15\40-\176'\''' git config --global filter.xrp.smudge cat git checkout --force 

After a configuration change, the files remain unchanged. Even when I delete and re-check.

The tr command, configured as a clean task, runs in isolation. Evidence:

 $ head -n 1 cashflow/repo/C_GMM_CashflowRepo.xrp ΓΏΓΎ< ! - - XMLR epositoryfile 1 . 0 - - > $ tr -cd '\''\11\12\15\40-\176'\' < cashflow/repo/C_GMM_CashflowRepo.xrp | head -n 1 <!-- XML Repository file 1.0 --> 

Can anyone see what is wrong with my configuration?

+6
source share
3 answers

One problem with intercepts is that they are not propagated.

.gitattributes has some directive for controlling diff and file contents, but another option would be an attribute filter (still in .gitattributes ) and can automatically convert these files to commit.
(That is, if a pure script is able to detect these files only based on their contents )


In this chat discussion, OP Synesso reports on success:

 .gitattributes: *.xrp filter=xrp ~/.gitconfig: [filter "xrp"] clean = \"C:/Program Files/Git/bin/tr.exe\" -cd "\\''\\11\\12\\15\\40-\\176'\\'" smudge = cat 

Then I had to change the file, add, commit, delete, check ... and THEN it was fixed. :)

Please note that for any modification that does not concern only one user, but potentially any user cloning this repo, I prefer to add (and .gitattributes ) an additional .gitattributes file in which the filter is declared, rather than changing .git/info/attribute file (which is not cloned).

From the gitattributes man page :

  • If you want to influence only one repository (for example, assign attributes to files that are special for one workflow for this repository), then the attributes should be placed in the file $GIT_DIR/info/attributes .
  • Attributes that must be versioned and distributed to other repositories (i.e. attributes of interest to all users) must be included in .gitattributes files.
  • Attributes that should affect all repositories for a single user must be placed in the file specified by the core.attributesfile configuration core.attributesfile .
  • Attributes for all users in the system should be placed in the $ (prefix) / etc / gitattributes file.

http://git-scm.com/docs/gitattributes


phyatt adds in the comments :

I made an example similar to this for sqlite3.
You can add it to the correct files with two lines:

 git config diff.sqlite3.textconv 'sqlite3 $1 .dump' echo '*.db diff=sqlite3' >> $(git rev-parse --show-toplevel)/.gitattributes 

Similar lines can be used to write other git configuration paths.

+5
source

Does diff have the ability to work on them as they are (i.e. they contain only a few strange bytes, but otherwise text) or not? If so, you can simply force git to treat them as text using .gitattributes . If not, it might be better to create custom diff and merge scripts (which will use tr if necessary for conversion) and tell git to use it again with .gitattributes .

In any case, you will not use hooks (which are designed to work in certain operations), but .gitattributes , which depend on the file.

+2
source

If your preferred editing format was ASCII, and only your assemblies required binaries, I would recommend using assembly rules to generate the binary version from the preferred source that you would pass to the repository.

Given that your ID environment makes the files in binary format already, I think it is best to store them in the repository in this format.

Instead of hooks, look at git help attributes , especially diff and textconv , which allow you to customize files that match specific patterns to use alternative methods of distinguishing. You should be able to create ASCII working differences without the need to compromise how you store files or edit them.

EDIT: based on your comment elsewhere that "every other byte is 0" that the UTF-16 or UCS-2 file suggests. See this answer for diff , which can handle unicode: Can I make git recognize the UTF-16 file as text?

+2
source

Source: https://habr.com/ru/post/891618/


All Articles