<commit_before># git-gui remote adding support
# Copyright (C) 2008 <NAME>

class remote_add {

field w              ; # widget path
field w_name         ; # new remote name widget
field w_loc          ; # new remote location widget

field name         {}; # name of the remote the user has chosen
field location     {}; # location of the remote the user has chosen

field opt_action fetch; # action to do after registering the remote locally

constructor dialog {} {
	global repo_config

	make_toplevel top w
	wm title $top [append "[appname] ([reponame]): " [mc "Add Remote"]]
	if {$top ne {.}} {
		wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
	}

	label $w.header -text [mc "Add New Remote"] -font font_uibold
	pack $w.header -side top -fill x

	frame $w.buttons
	button $w.buttons.create -text [mc Add] \
		-default active \
		-command [cb _add]
	pack $w.buttons.create -side right
	button $w.buttons.cancel -text [mc Cancel] \
		-command [list destroy $w]
	pack $w.buttons.cancel -side right -padx 5
	pack $w.buttons -side bottom -fill x -pady 10 -padx 10

	labelframe $w.desc -text [mc "Remote Details"]

	label $w.desc.name_l -text [mc "Name:"]
	set w_name $w.desc.name_t
	entry $w_name \
		-borderwidth 1 \
		-relief sunken \
		-width 40 \
		-textvariable @name \
		-validate key \
		-validatecommand [cb _validate_name %d %S]
	grid $w.desc.name_l $w_name -sticky we -padx {0 5}

	label $w.desc.loc_l -text [mc "Location:"]
	set w_loc $w.desc.loc_t
	entry $w_loc \
		-borderwidth 1 \
		-relief sunken \
		-width 40 \
		-textvariable @location
	grid $w.desc.loc_l $w_loc -sticky we -padx {0 5}

	grid columnconfigure $w.desc 1 -weight 1
	pack $w.desc -anchor nw -fill x -pady 5 -padx 5

	labelframe $w.action -text [mc "Further Action"]

	radiobutton $w.action.fetch \
		-text [mc "Fetch Immediately"] \
		-value fetch \
		-variable @opt_action
	pack $w.action.fetch -anchor nw

	radiobutton $w.action.push \
		-text [mc "Initialize Remote Repository and Push"] \
		-value push \
		-variable @opt_action
	pack $w.action.push -anchor nw

	radiobutton $w.action.none \
		-text [mc "Do Nothing Else Now"] \
		-value none \
		-variable @opt_action
	pack $w.action.none -anchor nw

	grid columnconfigure $w.action 1 -weight 1
	pack $w.action -anchor nw -fill x -pady 5 -padx 5

	bind $w <Visibility> [cb _visible]
	bind $w <Key-Escape> [list destroy $w]
	bind $w <Key-Return> [cb _add]\;break
	tkwait window $w
}

method _add {} {
	global repo_config env
	global M1B

	if {$name eq {}} {
		tk_messageBox \
			-icon error \
			-type ok \
			-title [wm title $w] \
			-parent $w \
			-message [mc "Please supply a remote name."]
		focus $w_name
		return
	}

	# XXX: We abuse check-ref-format here, but
	# that should be ok.
	if {[catch {git check-ref-format "remotes/$name"}]} {
		tk_messageBox \
			-icon error \
			-type ok \
			-title [wm title $w] \
			-parent $w \
			-message [mc "'%s' is not an acceptable remote name." $name]
		focus $w_name
		return
	}

	if {[catch {add_single_remote $name $location}]} {
		tk_messageBox \
			-icon error \
			-type ok \
			-title [wm title $w] \
			-parent $w \
			-message [mc "Failed to add remote '%s' of location '%s'." $name $location]
		focus $w_name
		return
	}

	switch -- $opt_action {
	fetch {
		set c [console::new \
			[mc "fetch %s" $remote] \
			[mc "Fetching the %s" $remote]]
		console::exec $c [list git fetch --all $name]
	}
	push {
		set cmds [list]

		# Parse the location
		if { [regexp {(?:git\+)?ssh://([^/]+)(/.+)} $location xx host path]
		     || [regexp {([^:][^:]+):(.+)} $location xx host path]} {
			set ssh ssh
			if {[info exists env(GIT_SSH)]} {
				set ssh $env(GIT_SSH)
			}
			lappend cmds [list exec $ssh $host mkdir -p $location && git --git-dir=$path init --bare]
		} elseif { ! [regexp {://} $location xx] } {<commit_msg>git-gui: Fix fetching from remotes when adding them<commit_after># git-gui remote adding support
# Copyright (C) 2008 <NAME>

class remote_add {

field w              ; # widget path
field w_name         ; # new remote name widget
field w_loc          ; # new remote location widget

field name         {}; # name of the remote the user has chosen
field location     {}; # location of the remote the user has chosen

field opt_action fetch; # action to do after registering the remote locally

constructor dialog {} {
	global repo_config

	make_toplevel top w
	wm title $top [append "[appname] ([reponame]): " [mc "Add Remote"]]
	if {$top ne {.}} {
		wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
	}

	label $w.header -text [mc "Add New Remote"] -font font_uibold
	pack $w.header -side top -fill x

	frame $w.buttons
	button $w.buttons.create -text [mc Add] \
		-default active \
		-command [cb _add]
	pack $w.buttons.create -side right
	button $w.buttons.cancel -text [mc Cancel] \
		-command [list destroy $w]
	pack $w.buttons.cancel -side right -padx 5
	pack $w.buttons -side bottom -fill x -pady 10 -padx 10

	labelframe $w.desc -text [mc "Remote Details"]

	label $w.desc.name_l -text [mc "Name:"]
	set w_name $w.desc.name_t
	entry $w_name \
		-borderwidth 1 \
		-relief sunken \
		-width 40 \
		-textvariable @name \
		-validate key \
		-validatecommand [cb _validate_name %d %S]
	grid $w.desc.name_l $w_name -sticky we -padx {0 5}

	label $w.desc.loc_l -text [mc "Location:"]
	set w_loc $w.desc.loc_t
	entry $w_loc \
		-borderwidth 1 \
		-relief sunken \
		-width 40 \
		-textvariable @location
	grid $w.desc.loc_l $w_loc -sticky we -padx {0 5}

	grid columnconfigure $w.desc 1 -weight 1
	pack $w.desc -anchor nw -fill x -pady 5 -padx 5

	labelframe $w.action -text [mc "Further Action"]

	radiobutton $w.action.fetch \
		-text [mc "Fetch Immediately"] \
		-value fetch \
		-variable @opt_action
	pack $w.action.fetch -anchor nw

	radiobutton $w.action.push \
		-text [mc "Initialize Remote Repository and Push"] \
		-value push \
		-variable @opt_action
	pack $w.action.push -anchor nw

	radiobutton $w.action.none \
		-text [mc "Do Nothing Else Now"] \
		-value none \
		-variable @opt_action
	pack $w.action.none -anchor nw

	grid columnconfigure $w.action 1 -weight 1
	pack $w.action -anchor nw -fill x -pady 5 -padx 5

	bind $w <Visibility> [cb _visible]
	bind $w <Key-Escape> [list destroy $w]
	bind $w <Key-Return> [cb _add]\;break
	tkwait window $w
}

method _add {} {
	global repo_config env
	global M1B

	if {$name eq {}} {
		tk_messageBox \
			-icon error \
			-type ok \
			-title [wm title $w] \
			-parent $w \
			-message [mc "Please supply a remote name."]
		focus $w_name
		return
	}

	# XXX: We abuse check-ref-format here, but
	# that should be ok.
	if {[catch {git check-ref-format "remotes/$name"}]} {
		tk_messageBox \
			-icon error \
			-type ok \
			-title [wm title $w] \
			-parent $w \
			-message [mc "'%s' is not an acceptable remote name." $name]
		focus $w_name
		return
	}

	if {[catch {add_single_remote $name $location}]} {
		tk_messageBox \
			-icon error \
			-type ok \
			-title [wm title $w] \
			-parent $w \
			-message [mc "Failed to add remote '%s' of location '%s'." $name $location]
		focus $w_name
		return
	}

	switch -- $opt_action {
	fetch {
		set c [console::new \
			[mc "fetch %s" $name] \
			[mc "Fetching the %s" $name]]
		console::exec $c [list git fetch $name]
	}
	push {
		set cmds [list]

		# Parse the location
		if { [regexp {(?:git\+)?ssh://([^/]+)(/.+)} $location xx host path]
		     || [regexp {([^:][^:]+):(.+)} $location xx host path]} {
			set ssh ssh
			if {[info exists env(GIT_SSH)]} {
				set ssh $env(GIT_SSH)
			}
			lappend cmds [list exec $ssh $host mkdir -p $location && git --git-dir=$path init --bare]
		} elseif { ! [regexp {://} $location xx] } {
{'fraction_non_alphanumeric': 0.1395713538944067, 'fraction_numerical': 0.007318348144276007, 'mean_word_length': 2.73681640625, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3348432', 'n_tokens_mistral': 3113, 'n_tokens_neox': 2810, 'n_words': 962}