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

[PATCH] git-gui: Implement a 'clone' subcommand

From
Petr Baudis <pasky@suse.cz>
Date
Sep 30, 2008, 16:51 UTC
Message-ID
<1222793501-17997-1-git-send-email-pasky@suse.cz>

This enables git-gui to be started with the clone dialog opened right away, possibly with the URL prefilled when it is passed as another argument. git-gui can then be e.g. registered as the git:// protocol handler.

This is just a simple implementation - we construct the front actions page, then throw it away immediately; I wanted to avoid unnecessary refactoring and complication of the code, though.

Signed-off-by: Petr Baudis <petr.baudis@novartis.com>
---
 Documentation/git-gui.txt         |    5 +++++
 git-gui/git-gui.sh                |   21 ++++++++++++++++++---
 git-gui/lib/choose_repository.tcl |   11 ++++++++++-
 3 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/Documentation/git-gui.txt b/Documentation/git-gui.txt
index 0e650f4..9ce63be 100644
--- a/Documentation/git-gui.txt
+++ b/Documentation/git-gui.txt
@@ -43,6 +43,11 @@ citool::
 	to only commit actions, slightly reducing the application's
 	startup time and simplifying the menubar.
 
+clone::
+	Start the 'git-gui' clone dialog, optionally taking
+	a source location as an extra argument to pre-fill
+	in the dialog.
+
 version::
 	Display the currently running version of 'git-gui'.
 
diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh
index 4085e8f..86f0151 100755
--- a/git-gui/git-gui.sh
+++ b/git-gui/git-gui.sh
@@ -950,6 +950,8 @@ enable_option multicommit
 enable_option branch
 enable_option transport
 disable_option bare
+set init_action {}
+set clone_url {}
 
 switch -- $subcommand {
 browser -
@@ -960,6 +962,13 @@ blame {
 	disable_option branch
 	disable_option transport
 }
+clone {
+	set init_action "clone"
+	if {[llength $argv] > 0} {
+		set clone_url [lindex $argv 0]
+		set argv [lrange $argv 1 end]
+	}
+}
 citool {
 	enable_option singlecommit
 	enable_option retcode
@@ -995,7 +1004,12 @@ citool {
 ##
 ## repository setup
 
-if {[catch {
+if {$init_action != ""} {
+	load_config 1
+	apply_config
+	choose_repository::pick $init_action
+
+} elseif {[catch {
 		set _gitdir $env(GIT_DIR)
 		set _prefix {}
 		}]
@@ -1005,7 +1019,7 @@ if {[catch {
 	} err]} {
 	load_config 1
 	apply_config
-	choose_repository::pick
+	choose_repository::pick {}
 }
 if {![file isdirectory $_gitdir] && [is_Cygwin]} {
 	catch {set _gitdir [exec cygpath --windows $_gitdir]}
@@ -2622,6 +2636,7 @@ blame {
 	return
 }
 citool -
+clone -
 gui {
 	if {[llength $argv] != 0} {
 		puts -nonewline stderr "usage: $argv0"
@@ -2635,7 +2650,7 @@ gui {
 	# fall through to setup UI for commits
 }
 default {
-	puts stderr "usage: $argv0 \[{blame|browser|citool}\]"
+	puts stderr "usage: $argv0 \[{blame|browser|citool|clone}\]"
 	exit 1
 }
 }
diff --git a/git-gui/lib/choose_repository.tcl b/git-gui/lib/choose_repository.tcl
index 3180786..290fbc0 100644
--- a/git-gui/lib/choose_repository.tcl
+++ b/git-gui/lib/choose_repository.tcl
@@ -21,7 +21,7 @@ field clone_type hardlink ; # Type of clone to construct
 field readtree_err        ; # Error output from read-tree (if any)
 field sorted_recent       ; # recent repositories (sorted)
 
-constructor pick {} {
+constructor pick {action} {
 	global M1T M1B
 
 	make_toplevel top w
@@ -195,6 +195,11 @@ constructor pick {} {
 		bind $top <Visibility> {}
 	"
 	wm deiconify $top
+
+	if {$action != ""} {
+		_next $this $action
+	}
+
 	tkwait variable @done
 
 	if {$top eq {.}} {
@@ -447,6 +452,10 @@ proc _new_ok {p} {
 ## Clone Existing Repository
 
 method _do_clone {} {
+	if {$::clone_url != ""} {
+		set origin_url $::clone_url
+	}
+
 	$w_next conf \
 		-state disabled \
 		-command [cb _do_clone2] \
-- 
tg: (9800c0d..) t/git-gui/clonecmd (depends on: vanilla/master)
Next: Shawn O. Pearce
Message 1 of 8 in “git-gui: Implement a 'clone' subcommand”
  1. git-gui: Implement a 'clone' subcommandPetr Baudis, Sep 30, 2008
  2. Shawn O. PearceSep 30, 2008
  3. Shawn O. PearceSep 30, 2008
  4. git-gui: Correctly set up locators in case of preset URL variablePetr Baudis, Oct 3, 2008
  5. H.Merijn BrandOct 3, 2008
  6. Petr BaudisOct 3, 2008
  7. Shawn O. PearceOct 10, 2008
  8. Petr BaudisOct 3, 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.