git-svn --ignore-paths

后端 未结 7 1583
悲哀的现实
悲哀的现实 2021-02-01 04:27

I\'m struggling for a number of hours now with the --ignore-paths option to git-svn, in an attempt to fetch only certain tags from a large repository.

I want to start

相关标签:
7条回答
  • 2021-02-01 04:49

    I have a similar problem and a partial Solution for my case .. .

    Context :
    We have only one SVN repository for Meca, Hardware, Software team... the repository is a complete mess.. so I try to use regex to reduce the area to scan. After 1 day I just gave up.

    Finally I used the include-path option to scan only folder with "*Src*" inside. which speed up the scan. also use the option :
    -r to reduce the history size you will get in local.
    --no-minimize-url otherwise git-svn will scan the whole repository even if you specify the trunk and branch location.

    git svn clone 
    -r11213:HEAD 
    --prefix svn/
    --no-minimize-url
    --trunk=/trunk/dev/SW/Code/Controller1
    --branches=/branches/SW_team/
    --include-paths=.*Src.*
    https://svnserver.compagny.com/Project1/
    Controller1__git__
    

    notice that right now i do not care of the Tags.

    Hope it could help, even It's not the original question (5 years ago :-) )


    EDIT: I cannot add a comment so I comment the question here (not enough reputation point)

    1) --ignore-paths can be given for git svn [init/fetch or clone] (i do not know if there is a different behavior)
    2) --ignore-paths expect a regex , be carefull the "." means any character. By chance the carater "." is also any character so regex=Acme-5.0 will match string="Acme-5.0" but also string="Acme-580", it should work anyway.

    0 讨论(0)
  • 2021-02-01 04:54

    I have been experiencing strange problems with --ignore-paths too. git-svn seems to ignore the entire regexp in some cases. I have seen the same regexp working on repos 1 and ignored on repos 2, where both repos have the same file structure, but different history.

    Although I don't see anything wrong with your regexp for your specific tree, I would recommend using the ^ caret at the beginning to specify the ignored paths starting at the root. This might help the rexexp parser speed-up the search and avoid issues where a match could also be found deep inside the trunk for example.

    I would use something like --ignore-paths="^tags/Acme-(4|5.[0-4])"

    0 讨论(0)
  • 2021-02-01 04:57

    I've struggled with the exact same problem and started editing .git/config to explicitly list the branches or tags that I want.

    That approach worked well until I came across a svn repository with lots of branches, so I duly added the ones I wanted and left out the ones I did not. But this failed with configuration file errors. Trial and error apparently shows that there is a limit either the number of branches in the config file or more likely the total number of characters between the opening { and closing }.

    My life would be much easier if I could just build regexs.

    0 讨论(0)
  • 2021-02-01 04:59

    I was having this same problem today: my regexp would just never match... Make sure you know what the target paths actually look like. I was making an incorrect assumption about the structure of the paths that were being fed to my regexp.

    To find out what the paths look like, make git-svn output each path to the console as it tests them:

    NOTE: Just in case, make a backup copy of the git-svn file first!

    1. Open the git-svn script in a text editor. My script was <git-dir>/libexec/git-core/git-svn.
    2. Locate the is_path_ignored subroutine.
    3. Add a print statement above the first return statement, as follows...
    sub is_path_ignored {
        my ($self, $path) = @_;
    
        print STDERR "$path\n"; //<-- **ADD THIS LINE**
    
        return 1 if in_dot_git($path);
        return 1 if defined($self->{ignore_regex}) &&
                $path =~ m!$self->{ignore_regex}!;
        return 0 unless defined($_ignore_regex);
        return 1 if $path =~ m!$_ignore_regex!o;
        return 0;
    }
    

    Now use git-svn again with the --ignore-paths switch.

    I realised that instead of paths like trunk/baz it was actually using bar/trunk/baz

    So instead of

    --ignore-paths='^(?:trunk|branches|tags)/baz' 
    

    I needed to use

    --ignore-paths='^bar/(?:trunk|branches|tags)/baz'
    

    Don't forget to remove the print statement from the git-svn script.

    0 讨论(0)
  • 2021-02-01 04:59

    I'm posting this for everyone, who was aslo trying to use --ignore-paths for fetching only specific branches/tags...

    After a while struggling with --ignore-paths, which resulted in the following pattern to ignore all folders in branches folder, except folder branchname1 and branchname2:

    --ignore-paths='branches/(?!branchname1|branchname2)'
    

    Howerver, the correct solution is hiding at the bottom of the GIT SVN documentation:

    It is also possible to fetch a subset of branches or tags by using a comma-separated list of names within braces. For example:

    [svn-remote "huge-project"]
      url = http://server.org/svn
      fetch = trunk/src:refs/remotes/trunk
      branches = branches/{red,green}/src:refs/remotes/project-a/branches/*
      tags = tags/{1.0,2.0}/src:refs/remotes/project-a/tags/*
    

    So in your case, .git/config should contain something like this:

    tags = tags/{Acme-4.x,Acme-5.0,Acme-5.1,Acme-5.2,Acme-5.3,Acme-5.4}:refs/remotes/origin/tags/*
    
    0 讨论(0)
  • 2021-02-01 05:03

    You might also just try:

    cat .git/config
    

    on Linux, or:

    type .git\config
    

    on Windows, from your new repository directory, to see the fetch URL, the branches and tags url.

    0 讨论(0)
提交回复
热议问题