From: Hannu Nyman Date: Sat, 4 May 2024 06:57:07 +0000 (+0300) Subject: scripts/feeds: Support feed update with git pull --rebase --autostash X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=f68dcce3bb2a5d1043db7282809ef9b197dec99a;p=openwrt%2Fstaging%2Fxback.git scripts/feeds: Support feed update with git pull --rebase --autostash Add feed update option '-s' that performs 'git pull --rebase --autostash': * possible local uncommited changes are autostashed before pull, * local commits are then rebased on top of the new commits pulled from origin and * finally git does 'stash pop'. This enables feed update while there are local development commits and possibly also local uncommited changes. Signed-off-by: Hannu Nyman Link: https://github.com/openwrt/openwrt/pull/15377 Signed-off-by: Robert Marko --- diff --git a/scripts/feeds b/scripts/feeds index 2f2a1d1e42..7cbe07f58e 100755 --- a/scripts/feeds +++ b/scripts/feeds @@ -160,6 +160,7 @@ my %update_method = ( 'init_commit' => "git clone '%s' '%s' && cd '%s' && git checkout -b '%s' '%s' && cd -", 'update' => "git pull --ff-only", 'update_rebase' => "git pull --rebase=merges", + 'update_stash' => "git pull --rebase=merges --autostash", 'update_force' => "git pull --ff-only || (git reset --hard HEAD; git pull --ff-only; exit 1)", 'post_update' => "git submodule update --init --recursive", 'controldir' => ".git", @@ -170,6 +171,7 @@ my %update_method = ( 'init_commit' => "git clone '%s' '%s' && cd '%s' && git checkout -b '%s' '%s' && cd -", 'update' => "git pull --ff-only", 'update_rebase' => "git pull --rebase=merges", + 'update_stash' => "git pull --rebase=merges --autostash", 'update_force' => "git pull --ff-only || (git reset --hard HEAD; git pull --ff-only; exit 1)", 'post_update' => "git submodule update --init --recursive", 'controldir' => ".git", @@ -196,13 +198,14 @@ my %update_method = ( # src-git: pull broken # src-cpy: broken if `basename $src` != $name -sub update_feed_via($$$$$$) { +sub update_feed_via($$$$$$$) { my $type = shift; my $name = shift; my $src = shift; my $relocate = shift; my $force = shift; my $rebase = shift; + my $stash = shift; my $m = $update_method{$type}; my $localpath = "./feeds/$name"; @@ -230,6 +233,9 @@ sub update_feed_via($$$$$$) { if ($rebase && exists $m->{'update_rebase'}) { $update_cmd = $m->{'update_rebase'}; } + if ($stash && exists $m->{'update_stash'}) { + $update_cmd = $m->{'update_stash'}; + } system("cd '$safepath'; $update_cmd") == 0 or return 1; } if ($m->{'post_update'}) { @@ -782,13 +788,14 @@ sub uninstall { return 0; } -sub update_feed($$$$$) +sub update_feed($$$$$$) { my $type=shift; my $name=shift; my $src=shift; my $force_update=shift; my $rebase_update=shift; + my $stash_update=shift; my $force_relocate=update_location( $name, "@$src" ); my $rv=0; @@ -803,7 +810,7 @@ sub update_feed($$$$$) my $failed = 1; foreach my $feedsrc (@$src) { warn "Updating feed '$name' from '$feedsrc' ...\n"; - if (update_feed_via($type, $name, $feedsrc, $force_relocate, $force_update, $rebase_update) != 0) { + if (update_feed_via($type, $name, $feedsrc, $force_relocate, $force_update, $rebase_update, $stash_update) != 0) { if ($force_update) { $rv=1; $failed=0; @@ -829,7 +836,7 @@ sub update { $ENV{SCAN_COOKIE} = $$; $ENV{OPENWRT_VERBOSE} = 's'; - getopts('ahifr', \%opts); + getopts('ahifrs', \%opts); %argv_feeds = map { $_ => 1 } @ARGV; if ($opts{h}) { @@ -837,8 +844,8 @@ sub update { return 0; } - if ($opts{f} && $opts{r}) { - warn "Force and rebase are incompatible update options.\n";; + if ($opts{f} && ($opts{r} || $opts{s})) { + warn "Force and rebase/stash are incompatible update options.\n";; return 1; } @@ -851,7 +858,7 @@ sub update { my ($type, $name, $src) = @$feed; next unless $#ARGV == -1 or $opts{a} or $argv_feeds{$name}; if (not $opts{i}) { - update_feed($type, $name, $src, $opts{f}, $opts{r}) == 0 or $failed=1; + update_feed($type, $name, $src, $opts{f}, $opts{r}, $opts{s}) == 0 or $failed=1; } push @index_feeds, $name; } @@ -917,6 +924,7 @@ Commands: Options: -a : Update all feeds listed within feeds.conf. Otherwise the specified feeds will be updated. -r : Update by rebase. (git only. Useful if local commits exist) + -s : Update by rebase and autostash. (git only. Useful if local commits and uncommited changes exist) -i : Recreate the index only. No feed update from repository is performed. -f : Force updating feeds even if there are changed, uncommitted files.