git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] git push --track
@ 2010-01-13 15:12 Rudolf Polzer
  2010-01-13 15:43 ` Ilari Liusvaara
                   ` (3 more replies)
  0 siblings, 4 replies; 42+ messages in thread
From: Rudolf Polzer @ 2010-01-13 15:12 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 798 bytes --]

Hi,

I'd like a feature to automatically "transform" a non-tracking local  
branch into a tracking branch on push. A patch to do that is attached.

Usage:

git branch mybranch
git checkout mybranch
...
git push --track origin mybranch:mybranch

will not just perform the push, but also write a block

[branch "mybranch"]
         remote = origin
         merge = refs/heads/mybranch

to the git configuration so the branch becomes tracking.

This should be a simpler alternative to the otherwise usual procedure

git push origin mybranch:mybranch
git config branch.mybranch.remote origin
git config branch.mybranch.merge refs/heads/mybranch

Are there any chances for this getting added to official git - or an  
alternate convenient way convert a local to a tracking branch?

Best regards,

Rudolf

[-- Attachment #2: git-push-track.diff --]
[-- Type: application/octet-stream, Size: 2340 bytes --]

diff --git a/builtin-push.c b/builtin-push.c
index 28a26e7..8d68646 100644
--- a/builtin-push.c
+++ b/builtin-push.c
@@ -7,6 +7,7 @@
 #include "builtin.h"
 #include "remote.h"
 #include "transport.h"
+#include "branch.h"
 #include "parse-options.h"
 
 static const char * const push_usage[] = {
@@ -115,6 +116,33 @@ static int push_with_options(struct transport *transport, int flags)
 		fprintf(stderr, "Pushing to %s\n", transport->url);
 	err = transport_push(transport, refspec_nr, refspec, flags,
 			     &nonfastforward);
+	if (err == 0 && flags & TRANSPORT_PUSH_TRACK)
+	{
+		struct ref *remote_refs =
+			transport->get_refs_list(transport, 1);
+		struct ref *local_refs = get_local_heads();
+		int match_flags = 0;
+		if (flags & TRANSPORT_PUSH_ALL)
+			match_flags |= MATCH_REFS_ALL;
+		if (flags & TRANSPORT_PUSH_MIRROR)
+			match_flags |= MATCH_REFS_MIRROR;
+		if(!(flags & TRANSPORT_PUSH_DRY_RUN))
+		if(!match_refs(local_refs, &remote_refs, refspec_nr, refspec, match_flags))
+		{
+			struct ref *next = remote_refs;
+			while(next)
+			{
+				if(next->peer_ref && *next->peer_ref->name && *next->name && next->peer_ref->new_sha1 && !is_null_sha1(next->peer_ref->new_sha1))
+				{
+					if (!prefixcmp(next->peer_ref->name, "refs/heads/"))
+					{
+						install_branch_config(BRANCH_CONFIG_VERBOSE, next->peer_ref->name + 11, transport->remote->name, next->name);
+					}
+				}
+				next = next->next;
+			}
+		}
+	}
 	if (err != 0)
 		error("failed to push some refs to '%s'", transport->url);
 
@@ -218,6 +246,8 @@ int cmd_push(int argc, const char **argv, const char *prefix)
 		OPT_BOOLEAN( 0 , "thin", &thin, "use thin pack"),
 		OPT_STRING( 0 , "receive-pack", &receivepack, "receive-pack", "receive pack program"),
 		OPT_STRING( 0 , "exec", &receivepack, "receive-pack", "receive pack program"),
+		OPT_BIT('t', "track",  &flags, "set up tracking mode (see git-pull(1))",
+			TRANSPORT_PUSH_TRACK),
 		OPT_END()
 	};
 
diff --git a/transport.h b/transport.h
index 9e74406..8a9c776 100644
--- a/transport.h
+++ b/transport.h
@@ -74,6 +74,7 @@ struct transport {
 #define TRANSPORT_PUSH_VERBOSE 16
 #define TRANSPORT_PUSH_PORCELAIN 32
 #define TRANSPORT_PUSH_QUIET 64
+#define TRANSPORT_PUSH_TRACK 128
 
 /* Returns a transport suitable for the url */
 struct transport *transport_get(struct remote *, const char *);

^ permalink raw reply related	[flat|nested] 42+ messages in thread

end of thread, other threads:[~2010-01-15 18:55 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-13 15:12 [PATCH] git push --track Rudolf Polzer
2010-01-13 15:43 ` Ilari Liusvaara
2010-01-13 15:55   ` Rudolf Polzer
2010-01-13 16:27     ` Ilari Liusvaara
2010-01-13 16:37     ` Matthieu Moy
2010-01-14  5:21     ` Tay Ray Chuan
2010-01-14  7:00       ` Rudolf Polzer
2010-01-14 23:13         ` Junio C Hamano
2010-01-14  7:16     ` Jeff King
2010-01-15  5:47     ` Junio C Hamano
2010-01-15 14:00       ` Rudolf Polzer
2010-01-15 15:45         ` Miles Bader
2010-01-15 18:16         ` Junio C Hamano
2010-01-14  0:28   ` Miles Bader
2010-01-14  0:25 ` Miles Bader
2010-01-14  0:33   ` Johannes Schindelin
2010-01-14  0:36     ` Miles Bader
2010-01-14  0:46   ` Miles Bader
2010-01-14  7:01   ` Rudolf Polzer
2010-01-14 13:44   ` Martin Langhoff
2010-01-14 14:16     ` Johannes Schindelin
2010-01-14 14:25       ` Matthieu Moy
2010-01-14 14:35         ` Martin Langhoff
2010-01-14 15:27         ` Andreas Krey
2010-01-14  1:27 ` Tay Ray Chuan
2010-01-14  1:35   ` Miles Bader
2010-01-14  1:37     ` Tay Ray Chuan
2010-01-14  1:49       ` Miles Bader
2010-01-14  1:58         ` Tay Ray Chuan
2010-01-14  7:03   ` Rudolf Polzer
2010-01-14 23:46     ` Junio C Hamano
2010-01-15  0:30       ` Miles Bader
2010-01-15 18:18         ` Junio C Hamano
2010-01-15 18:54           ` Miles Bader
2010-01-15 13:26       ` Matthieu Moy
2010-01-14  6:41 ` Nanako Shiraishi
2010-01-14  7:08   ` Rudolf Polzer
2010-01-14 10:31   ` Johannes Schindelin
2010-01-14 22:27     ` Nanako Shiraishi
2010-01-14 23:50       ` Junio C Hamano
2010-01-15 13:44       ` Rudolf Polzer
2010-01-15 14:09         ` Johannes Schindelin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).