From d86a7ed412555192e2000a9a34b3372f380ec3d0 Mon Sep 17 00:00:00 2001 From: Ori Bernstein Date: Tue, 16 Aug 2022 23:50:28 +0000 Subject: git/rebase: allow rebase without a clean tree Here, patch grows a dry run option (-n), which allows git/import to bail out early if it would patch files that are dirty in tree. Once git/import refuses to patch dirty files, git/rebase can skip checking if the whole tree is clean, which is both convenient and much faster on large trees. --- sys/src/cmd/git/import | 12 ++++++++++-- sys/src/cmd/git/rebase | 2 -- 2 files changed, 10 insertions(+), 4 deletions(-) mode change 100755 => 100644 sys/src/cmd/git/import mode change 100755 => 100644 sys/src/cmd/git/rebase (limited to 'sys/src/cmd/git') diff --git a/sys/src/cmd/git/import b/sys/src/cmd/git/import old mode 100755 new mode 100644 index 0cc450bf8..102a4fdcd --- a/sys/src/cmd/git/import +++ b/sys/src/cmd/git/import @@ -76,8 +76,16 @@ fn apply @{ # force re-reading env rc -c ' - echo applying $msg | sed 1q date=`{seconds $date} + files=`$nl{patch -np1 < $diffpath} + if(! git/walk -q $files){ + >[1=2] { + echo patch would clobber files: + git/walk $files + exit clobber + } + } + echo applying $msg | sed 1q if(! files=`$nl{patch -p1 < $diffpath}) die ''patch failed'' for(f in $files){ @@ -111,6 +119,6 @@ for(p in $patches){ if(test -d $p && test -f $p/header && test -f $p/body) {{cat $p/header; echo; cat $p/body} | apply} || die $status if not - apply < $p || die $status + apply < $p } exit '' diff --git a/sys/src/cmd/git/rebase b/sys/src/cmd/git/rebase old mode 100755 new mode 100644 index 395f3e693..a2aef6c2f --- a/sys/src/cmd/git/rebase +++ b/sys/src/cmd/git/rebase @@ -7,8 +7,6 @@ flagfmt='a:abort, r:resume, i:interactive'; args='onto' eval `''{aux/getflags $*} || exec aux/usage tmp=_rebase.working -if(! git/walk -q) - die dirty working tree if(~ $#abort 1){ if(! test -f .git/rebase.todo) die no rebase to abort -- cgit v1.2.3