[openwrt/openwrt] scripts/feeds: Support feed update with git pull --rebase
LEDE Commits
lede-commits at lists.infradead.org
Sun Sep 8 09:54:45 PDT 2024
robimarko pushed a commit to openwrt/openwrt.git, branch main:
https://git.openwrt.org/ef720b1e09fc8f013dc2bcc0b86f9b98ed4607fc
commit ef720b1e09fc8f013dc2bcc0b86f9b98ed4607fc
Author: Hannu Nyman <hannu.nyman at iki.fi>
AuthorDate: Sat May 4 09:56:32 2024 +0300
scripts/feeds: Support feed update with git pull --rebase
Add feed update option '-r' to perform "git pull --rebase" so that
possible local commits are rebased on top of the new commits pulled
from origin. That enables git pull while there are local
development commits.
Signed-off-by: Hannu Nyman <hannu.nyman at iki.fi>
Link: https://github.com/openwrt/openwrt/pull/15377
Signed-off-by: Robert Marko <robimarko at gmail.com>
---
scripts/feeds | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/scripts/feeds b/scripts/feeds
index b5b943c70b..2f2a1d1e42 100755
--- a/scripts/feeds
+++ b/scripts/feeds
@@ -159,6 +159,7 @@ my %update_method = (
'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-only",
+ 'update_rebase' => "git pull --rebase=merges",
'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",
@@ -168,6 +169,7 @@ my %update_method = (
'init_branch' => "git clone --branch '%s' '%s' '%s'",
'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_force' => "git pull --ff-only || (git reset --hard HEAD; git pull --ff-only; exit 1)",
'post_update' => "git submodule update --init --recursive",
'controldir' => ".git",
@@ -194,12 +196,13 @@ 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 $m = $update_method{$type};
my $localpath = "./feeds/$name";
@@ -224,6 +227,9 @@ sub update_feed_via($$$$$) {
if ($force && exists $m->{'update_force'}) {
$update_cmd = $m->{'update_force'};
}
+ if ($rebase && exists $m->{'update_rebase'}) {
+ $update_cmd = $m->{'update_rebase'};
+ }
system("cd '$safepath'; $update_cmd") == 0 or return 1;
}
if ($m->{'post_update'}) {
@@ -776,12 +782,13 @@ 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 $force_relocate=update_location( $name, "@$src" );
my $rv=0;
@@ -796,7 +803,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) != 0) {
+ if (update_feed_via($type, $name, $feedsrc, $force_relocate, $force_update, $rebase_update) != 0) {
if ($force_update) {
$rv=1;
$failed=0;
@@ -822,7 +829,7 @@ sub update {
$ENV{SCAN_COOKIE} = $$;
$ENV{OPENWRT_VERBOSE} = 's';
- getopts('ahif', \%opts);
+ getopts('ahifr', \%opts);
%argv_feeds = map { $_ => 1 } @ARGV;
if ($opts{h}) {
@@ -830,6 +837,11 @@ sub update {
return 0;
}
+ if ($opts{f} && $opts{r}) {
+ warn "Force and rebase are incompatible update options.\n";;
+ return 1;
+ }
+
-d "feeds" or do {
mkdir "feeds" or die "Unable to create the feeds directory";
};
@@ -839,7 +851,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}) == 0 or $failed=1;
+ update_feed($type, $name, $src, $opts{f}, $opts{r}) == 0 or $failed=1;
}
push @index_feeds, $name;
}
@@ -904,6 +916,7 @@ Commands:
update -a|<feedname(s)>: Update packages and lists of feeds in feeds.conf .
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)
-i : Recreate the index only. No feed update from repository is performed.
-f : Force updating feeds even if there are changed, uncommitted files.
More information about the lede-commits
mailing list