git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[TopGit PATCH] tg-create.sh: Introduce --add option to add a dependency.

From
JNJan Nieuwenhuizen <janneke-list@xs4all.nl>
Date
Aug 13, 2008, 14:25 UTC
Message-ID
<1218637514.7561.30.camel@heerbeest>
This implements 
    tg create --add DEP
to add dependency DEP to an already existing topgit branch.

The bad thing is that this does not play well with tg undepend; it won't work to re-add a previously removed dependency. This --add is implemented as a merge, and all merge commits are already present; it is only that lateron they are reverted.

Any ideas on how to fix that?
Signed-off-by: Jan Nieuwenhuizen <janneke@gnu.org>
---
 README       |    6 +++++-
 tg-create.sh |   44 ++++++++++++++++++++++++++++++++++++--------
 2 files changed, 41 insertions(+), 9 deletions(-)
diff --git a/README b/README
index 096b9ec..a9957f2 100644
--- a/README
+++ b/README
@@ -215,6 +215,9 @@ tg create
 	it will detect that you are on a topic branch base ref and
 	resume the topic branch creation operation.
 
+	With the --add option, all given arguments are added as
+	dependencies to current topic branch.
+
 tg delete
 ~~~~~~~~~
 	Remove a TopGit-controlled topic branch of given name
@@ -333,7 +336,8 @@ tg export
 tg undepend
 ~~~~~~~~~~~
 	Update the current topic branch by removing the given
-	branch (required argument) from the list of dependencies.
+	branch (required argument) from the list of dependencies
+	and reverting all its commits.
 
 tg update
 ~~~~~~~~~
diff --git a/tg-create.sh b/tg-create.sh
index 939af33..c5bc5fb 100644
--- a/tg-create.sh
+++ b/tg-create.sh
@@ -3,9 +3,11 @@
 # (c) Petr Baudis <pasky@suse.cz>  2008
 # GPLv2
 
+add= # Set to 1 when adding dependencies to existing topgit branch
 deps= # List of dependent branches
 restarted= # Set to 1 if we are picking up in the middle of base setup
 merge= # List of branches to be merged; subset of $deps
+merged= # List branches actually merged
 name=
 
 
@@ -14,8 +16,12 @@ name=
 while [ -n "$1" ]; do
 	arg="$1"; shift
 	case "$arg" in
+	--add)
+		add=1
+		name=$(git symbolic-ref HEAD | cut -b 12-)
+		;;
 	-*)
-		echo "Usage: tg create NAME [DEPS...]" >&2
+		echo "Usage: tg create --add|NAME [DEPENDENCY]..." >&2
 		exit 1;;
 	*)
 		if [ -z "$name" ]; then
@@ -50,12 +56,22 @@ fi
 
 [ -n "$merge" -o -n "$restarted" ] || merge="$deps "
 
+if [ -z "$add" ]; then
+	! git rev-parse --verify "$name" >/dev/null 2>&1 \
+		|| die "branch '$name' already exists"
+else
+	dupes=$(grep -E "^${merge// /|}/\$" .topdeps | tr '\n' ' ')
+	[ -z "$dupes" ] || die "already depend on: $dupes"
+	deps=$(echo "$merge" | cat .topdeps - | tr '\n' ' ' | sed -e 's/ \+$//')
+	merged="$merge"
+	merge="$name $merge"
+fi
+
+
 for d in $deps; do
 	git rev-parse --verify "$d" >/dev/null 2>&1 ||
 		die "unknown branch dependency '$d'"
 done
-! git rev-parse --verify "$name" >/dev/null 2>&1 ||
-	die "branch '$name' already exists"
 
 # Clean up any stale stuff
 rm -f "$git_dir/top-name" "$git_dir/top-deps" "$git_dir/top-merge"
@@ -96,7 +112,13 @@ done
 
 ## Set up the topic branch
 
-git update-ref "refs/top-bases/$name" "HEAD" ""
+if [ -z "$add" ]; then
+	git update-ref "refs/top-bases/$name" "HEAD" ""
+else
+	#[ -n "$add" ] && git -D "$name"
+	git branch -D save/"$name" || :
+	git branch -m "$name" save/$name
+fi
 git checkout -b "$name"
 
 echo "$deps" | sed 's/ /\n/g' >"$root_dir/.topdeps"
@@ -104,7 +126,7 @@ git add "$root_dir/.topdeps"
 
 author="$(git var GIT_AUTHOR_IDENT)"
 author_addr="${author%> *}>"
-{
+[ -z "$add" ] && {
 	echo "From: $author_addr"
 	! header="$(git config topgit.to)" || echo "To: $header"
 	! header="$(git config topgit.cc)" || echo "Cc: $header"
@@ -120,7 +142,13 @@ EOT
 } >"$root_dir/.topmsg"
 git add "$root_dir/.topmsg"
 
+if [ -z "$add" ]; then
+	info "Topic branch $name set up. Please fill .topmsg now and make initial commit."
+	info "To abort: git rm -f .top* && git checkout ${deps%% *} && tg delete $name"
+else
+	git commit -am "Add dependency: $merged"
+fi
 
-
-info "Topic branch $name set up. Please fill .topmsg now and make initial commit."
-info "To abort: git rm -f .top* && git checkout ${deps%% *} && tg delete $name"
+# Local Variables:
+# sh-basic-offset:8
+# End:
-- 
1.6.0.rc0.44.g67270


-- 
Jan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond - The music typesetter
http://www.xs4all.nl/~jantien       | http://www.lilypond.org
Next: Jonathan Nieder
Message 1 of 5 in “tg-create.sh: Introduce --add option to add a dependency.”
  1. tg-create.sh: Introduce --add option to add a dependency.Jan Nieuwenhuizen, Aug 13, 2008
  2. Jonathan NiederAug 13, 2008
  3. Jan NieuwenhuizenAug 15, 2008
  4. Jonathan NiederAug 15, 2008
  5. Jan NieuwenhuizenAug 18, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.