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

[PATCH] Cogito: Support for implicit remote branches in cloned repositories

From
JWJosef Weidendorfer <josef.weidendorfer@gmx.de>
Date
Nov 4, 2005, 16:01 UTC
Message-ID
<200511041701.48881.Josef.Weidendorfer@gmx.de>

This allows to specify remote branch names from the repository this one was cloned from (= remote repository of "origin" branch), without explicitly adding a branch for them. Therefore, these remote branches are called implicit.

Use them together with cg-fetch or cg-update.
Example: Your current repository was cloned with
  cg-clone git+ssh://remotehost:/path myrep

If this remote repository contains a branch "foo", you can say inside of myrep:

  cg-fetch foo

This fetches "git+ssh://remotehost:/path#foo" into a local branch "foo" (created if not existing). Similarily, a "cg-update foo" will fetch the remote branch and merge it into your current local branch.

After fetching from an implicit remote branch, cg-status will show the corresponding local branch, but still without an "R", because that is only shown for explicit branches. The implicit remote branch in the example above can be made explicit with

  cg-branch-add foo git+ssh://remotehost:/path#foo

Note that cg-update now always tries to fetch from a remote repository, as every non-explicit branch name is supposed to be an implicit remote branch.

Signed-off-by: Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
---

This patch is RFC. IMHO, it simplifies the usage of Cogito quite a lot. One difference of cloning with GIT vs. with Cogito is that Git always clones all remote branches. This can be limiting if you want to work with multiple repositories, but allows you to immediatly work with all the branches.

Cogito instead clones only one remote branch, and requires you to explicitly add further branches with "cg-branch-add". This is not necessary with implicit remote branches, and they should cover the standard use case which works with branches from the repository you clone from.

The nice thing here is that the patch is really small for the added functionality. If you accept it, I will provide updates for the documentation and tutorial.

Josef
 cg-fetch  |   10 +++++++++-
 cg-update |    6 +-----
 2 files changed, 10 insertions(+), 6 deletions(-)

applies-to: 22948869bcf0ec216ed9aa14e1c5ecc22114d66b 769aa2148fc2b583b071354e8eef3dae74e09c14

diff --git a/cg-fetch b/cg-fetch
index 759488a..5a5aeb1 100755
--- a/cg-fetch
+++ b/cg-fetch
@@ -262,7 +262,15 @@ name=${ARGS[0]}
 
 [ "$name" ] || { [ -s "$_git/branches/origin" ] && name=origin; }
 [ "$name" ] || die "where to fetch from?"
-uri=$(cat "$_git/branches/$name" 2>/dev/null) || die "unknown branch: $name"
+uri=$(cat "$_git/branches/$name" 2>/dev/null) || \
+    { if [ -s "$_git/branches/origin" ]; then
+	uri=$(cat "$_git/branches/origin" 2>/dev/null)
+	uri="$(echo "$uri" | cut -d '#' -f 1)#$name"
+	echo Fetching implicit remote branch "$uri".
+      else
+        die "unknown branch: $name"
+      fi
+    }
 
 rembranch=
 if echo "$uri" | grep -q '#'; then
diff --git a/cg-update b/cg-update
index 96035c5..534bf4a 100755
--- a/cg-update
+++ b/cg-update
@@ -39,11 +39,7 @@ name=${ARGS[0]}
 [ "$name" ] || { [ -s $_git/branches/origin ] && name=origin; }
 [ "$name" ] || die "where to update from?"
 
-if [ -s "$_git/branches/$name" ]; then
-	cg-fetch $force $name || exit 1
-else
-	echo "Updating from a local branch."
-fi
+cg-fetch $force $name || exit 1
 echo
 echo "Applying changes..."
 cg-merge $name
Next: Junio C Hamano
Message 1 of 10 in “Cogito: Support for implicit remote branches in cloned repositories”
  1. Cogito: Support for implicit remote branches in cloned repositoriesJosef Weidendorfer, Nov 4, 2005
  2. Junio C HamanoNov 4, 2005
  3. Josef WeidendorferNov 4, 2005
  4. Petr BaudisNov 4, 2005
  5. Junio C HamanoNov 4, 2005
  6. Linus TorvaldsNov 4, 2005
  7. Junio C HamanoNov 6, 2005
  8. Petr BaudisNov 7, 2005
  9. Junio C HamanoNov 7, 2005
  10. Josef WeidendorferNov 8, 2005

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.