开发者

How to setup gitattributes to filter part of a file?

I am using Visual Studio 2010 and git (git svn). My coworker uses pure svn with the Ankhsvn plugin.

When i try to open the file with the Git Source Control Provider enabled, Visual Studion complains:

Source Control Plug-in

The active solution or project is controlled by adifferen source control plug-in than the one you have selected. If you change the source control plu-in, the active solution or project will be closed.

Do you want to continue?

When i click yes an empty solution is opened. When i click no, all the git specific icons next to the solution items are missing (i still see the branch name in the solution explorer) and i get prompted about the Source Control Plug-in 开发者_Go百科every time i open the solution.

When i clone the svn repository which my coworker created the solution sln file contains the following

GlobalSection(SubversionScc) = preSolution

Svn-Managed = True

Manager = AnkhSVN - Subversion Support for Visual Studio

EndGlobalSection

I have deleted this section and now the solution opens without problems when the Git Source Control Provider is activated but complains when you select the Ankhsvn Provider - the situation is reversed.

I would like to tell git to remove this part of the .sln file during a pull (git svn fetch) and add it when i commit (git svn dcommit). Is this possible through gitattributes and how to do it?

EDIT:

I have now added

solutionname.sln filter=ankhsvn

to $GIT_DIR/info/attributes

and

[filter "ankhsvn"]
  clean=sed '/^Global$/ r ../ankhsvnsection '
  smudge=sed '/GlobalSection(SubversionScc)/,/EndGlobalSection/d '

to my .git/config file.

ankhsvnsection contains the secton that is removed by the smudge operation. I does not seem to do anything?!


I do not know how to do it exactly on windows, but I do know how I would do it on *nix.

I would write a sed/bash script (called myscript) which removes those lines from the file when they are checked-out by git using a git "smudge" filter.

So in "$GIT_DIR/info/attributes" I would add:

{sln filename} filter=myfilter

And define the smudge-part of the filter in the "$GIT_DIR/config" file:

[filter "myfilter"]
    smudge={path to myscript}

For Linux I would even just call sed directly like this:

[filter "myfilter"]
    smudge=sed '/GlobalSection(SubversionScc)/,/EndGlobalSection/ d'

This is maybe something you can take over in windows using git bash.

Be careful when you want to checkin changes to the file, as it will checkin the "smudged" version. You can define a "clean" filter for this which adds the svn statements again.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜