shithub: front

Download patch

ref: bd773dee09460f5d77c96f2fe3d34ec5ee0b54ce
parent: 44105baa85baa6c29e39f6c56f2ca0c68123e8c2
author: ori@eigenstate.org <ori@eigenstate.org>
date: Tue Aug 5 06:21:37 EDT 2025

git/rebase: a rethink

currently, git/rebase feels kind of clunky to use, and after
some beers and hackathon talk, we were wondering if it would
be any better if it acted like kill(1): printing the commands
that you should run, and giving you the chance to edit them.

Here's the result -- I'd like to know if it feels any better
to use:

--- a/sys/src/cmd/git/rebase
+++ b/sys/src/cmd/git/rebase
@@ -1,90 +1,35 @@
-#!/bin/rc
+#!/bin/rc -e
 
 . /sys/lib/git/common.rc
 gitup
 
-flagfmt='a:abort, r:resume, i:interactive'; args='onto'
+flagfmt='s:src src'; args='onto'
 eval `''{aux/getflags $*} || exec aux/usage
+if(~ $#* 0) exec aux/usage
 
-tmp=_rebase.working
-if(~ $#abort 1){
-	if(! test -f .git/rebase.todo)
-		die no rebase to abort
-	src=`{cat .git/rebase.src}
-	rm -f .git/rebase.^(src todo)
-	git/branch $src
-	git/branch -r $tmp
-	exit
-}
-if(test -f .git/rebase.todo){
-	if(~ $#resume 0)
-		die rebase in progress
-	if(! ~ $#* 0)
-		exec aux/usage
-	src=`{cat .git/rebase.src}
-}
-if not{
-	if(! ~ $#* 1)
-		exec aux/usage
+if(~ $#src 0)
 	src=`{git/branch}
-	dst=`{git/query $1}
-	echo $src > .git/rebase.src
-	git/log -se $dst'..'$src | sed 's/^/pick /' >.git/rebase.todo
-	if(! ~ $#interactive 0){
-		giteditor=`{git/conf core.editor}
-		if(~ $#editor 0)
-			editor=$giteditor
-		if(~ $#editor 0)
-			editor=hold
-		$editor .git/rebase.todo
-	}
-	git/branch -nb $dst $tmp
+dst=`{git/query $1}
+com=`{git/query $dst  $src @}
+if(~ $dst $com)
+	die 'nothing to rebase, doofus'
+git/log -se $dst'..'$src  | awk '
+BEGIN{
+	src=ENVIRON["src"];
+	dst=ENVIRON["dst"];
 }
-todo=`$nl{cat .git/rebase.todo}
-
-fn sigexit {
-	s=$status
-	if(!)
-		echo 'fix and git/rebase -r'
-	>.git/rebase.todo for(i in $todo)
-		echo $i
-	status=$s
+{
+	if(!done)
+		print "git/branch -nb "dst" rebase.wip";
+	c=$1; $1="";
+	print "git/export "c" | git/import #"$0;
+	done=1
 }
-
-flag e +
-
-while(! ~ $#todo 0){
-	item=`{echo $todo(1)}
-	todo=$todo(2-)
-	echo $item
-	c=$item(2)
-	switch($item(1)){
-	case p pick
-		git/export $c | git/import
-	case r reword
-		git/export $c | git/import
-		git/commit -re
-	case e edit
-		git/export $c | git/import
-		echo 'stopped for edit, resume with git/rebase -r'
-		exit
-	case s squash
-		git/export $c | git/import -n
-		msg=`''{cat $gitfs/HEAD/msg; echo; cat $gitfs/object/$c/msg}
-		git/commit -rem $msg .
-	case f fixup
-		git/export $c | git/import -n
-		git/commit -r .
-	case b break
-		echo 'stopped, resume with git/rebase -r'
-		exit
-	case '#'* ''
-	case *
-		die 'unknown command '''^$item(1)^''''
+END{
+	if(!done)
+		print "git/branch -nb "dst" ";
+	else{
+		print "git/branch -nb rebase.wip "src
+		print "git/branch -r rebase.wip";
 	}
-}
-
-fn sigexit
-git/branch -nb $tmp $src
-git/branch -r $tmp
-rm .git/rebase.todo .git/rebase.src
+}' 
--