feeds: enable cloning of specific git commit
authorluka <luka@3c298f89-4303-0410-b956-a3cf2f4a3e73>
Wed, 25 Sep 2013 13:02:55 +0000 (13:02 +0000)
committerluka <luka@3c298f89-4303-0410-b956-a3cf2f4a3e73>
Wed, 25 Sep 2013 13:02:55 +0000 (13:02 +0000)
Following syntax should be used to enable this feature:

src-git custom git://openwrt/custom-feed^SHA_COMMIT_ID

Signed-off-by: Luka Perkov <luka@openwrt.org>
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@38172 3c298f89-4303-0410-b956-a3cf2f4a3e73

scripts/feeds

index 680500d..85aeab5 100755 (executable)
@@ -119,6 +119,7 @@ my %update_method = (
        'src-git' => {
                'init'          => "git clone --depth 1 '%s' '%s'",
                'init_branch'   => "git clone --depth 1 --branch '%s' '%s' '%s'",
        'src-git' => {
                'init'          => "git clone --depth 1 '%s' '%s'",
                'init_branch'   => "git clone --depth 1 --branch '%s' '%s' '%s'",
+               'init_commit'   => "git clone '%s' '%s' && cd '%s' && git checkout -b '%s' '%s' && cd -",
                'update'        => "git pull --ff",
                'controldir'    => ".git",
                'revision'      => "git show --abbrev-commit HEAD | head -n 1 | cut -d ' ' -f 2 | tr -d '\n'"},
                'update'        => "git pull --ff",
                'controldir'    => ".git",
                'revision'      => "git show --abbrev-commit HEAD | head -n 1 | cut -d ' ' -f 2 | tr -d '\n'"},
@@ -154,15 +155,20 @@ sub update_feed_via($$$$) {
        my $localpath = "./feeds/$name";
        my $safepath = $localpath;
        $safepath =~ s/'/'\\''/;
        my $localpath = "./feeds/$name";
        my $safepath = $localpath;
        $safepath =~ s/'/'\\''/;
-       my ($base, $branch) = split(/;/, $src, 2);
+       my ($base_branch, $branch) = split(/;/, $src, 2);
+       my ($base_commit, $commit) = split(/\^/, $src, 2);
 
        if( $relocate || !$m->{'update'} || !-d "$localpath/$m->{'controldir'}" ) {
                system("rm -rf '$safepath'");
                if ($m->{'init_branch'} and $branch) {
 
        if( $relocate || !$m->{'update'} || !-d "$localpath/$m->{'controldir'}" ) {
                system("rm -rf '$safepath'");
                if ($m->{'init_branch'} and $branch) {
-                       system(sprintf($m->{'init_branch'}, $branch, $base, $safepath)) == 0 or return 1;
+                       system(sprintf($m->{'init_branch'}, $branch, $base_branch, $safepath)) == 0 or return 1;
+               } elsif ($m->{'init_commit'} and $commit) {
+                       system(sprintf($m->{'init_commit'}, $base_commit, $safepath, $safepath, $commit, $commit)) == 0 or return 1;
                } else {
                        system(sprintf($m->{'init'}, $src, $safepath)) == 0 or return 1;
                }
                } else {
                        system(sprintf($m->{'init'}, $src, $safepath)) == 0 or return 1;
                }
+       } elsif ($m->{'init_commit'} and $commit) {
+               # in case git hash has been provided don't update the feed
        } else {
                system("cd '$safepath'; $m->{'update'}") == 0 or return 1;
        }
        } else {
                system("cd '$safepath'; $m->{'update'}") == 0 or return 1;
        }