git-gui: Setup branch.remote,merge for shorthand git-pull
When creating new branches if branch.autosetupmerge is not set, or is set to true or always and we have been given a remote tracking branch as the starting point for a new branch we want to create the necessary configuration options in .git/config for the new branch so that a no argument git-pull on the command line pulls from the remote repository's branch. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
May 8, 2008 at 20:16 UTC
fe70225dc730c5af4c491106d1e0226d1c014d1e
3 files changed
+27
-1
git-gui.sh
+1
@@ -601,6 +601,7 @@ proc apply_config {} {
601
}
602
}
603
604
+set default_config(branch.autosetupmerge) true
605
set default_config(merge.diffstat) true
606
set default_config(merge.summary) false
607
set default_config(merge.verbosity) 2
lib/branch_create.tcl
+3
@@ -183,6 +183,9 @@ method _create {} {
183
if {$spec ne {} && $opt_fetch} {
184
$co enable_fetch $spec
185
}
186
+ if {$spec ne {}} {
187
+ $co remote_source $spec
188
+ }
189
190
if {[$co run]} {
191
destroy $w
lib/checkout_op.tcl
+23
-1
@@ -16,6 +16,7 @@ field merge_base {}; # merge base if we have another ref involved
16
field fetch_spec {}; # refetch tracking branch if used?
17
field checkout 1; # actually checkout the branch?
18
field create 0; # create the branch if it doesn't exist?
19
+field remote_source {}; # same as fetch_spec, to setup tracking
20
21
field reset_ok 0; # did the user agree to reset?
22
field fetch_ok 0; # did the fetch succeed?
@@ -44,6 +45,10 @@ method enable_fetch {spec} {
45
set fetch_spec $spec
46
}
47
48
+method remote_source {spec} {
49
+ set remote_source $spec
50
+}
51
+
52
method enable_checkout {co} {
53
set checkout $co
54
}
@@ -145,7 +150,7 @@ method _finish_fetch {ok} {
150
}
151
152
method _update_ref {} {
148
- global null_sha1 current_branch
153
+ global null_sha1 current_branch repo_config
154
155
set ref $new_ref
156
set new $new_hash
@@ -172,6 +177,23 @@ method _update_ref {} {
177
178
set reflog_msg "branch: Created from $new_expr"
179
set cur $null_sha1
180
+
181
+ if {($repo_config(branch.autosetupmerge) eq {true}
182
+ || $repo_config(branch.autosetupmerge) eq {always})
183
+ && $remote_source ne {}
184
+ && "refs/heads/$newbranch" eq $ref} {
185
+
186
+ set c_remote [lindex $remote_source 1]
187
+ set c_merge [lindex $remote_source 2]
188
+ if {[catch {
189
+ git config branch.$newbranch.remote $c_remote
190
+ git config branch.$newbranch.merge $c_merge
191
+ } err]} {
192
+ _error $this [strcat \
193
+ [mc "Failed to configure simplified git-pull for '%s'." $newbranch] \
194
+ "\n\n$err"]
195
+ }
196
+ }
197
} elseif {$create && $merge_type eq {none}} {
198
# We were told to create it, but not do a merge.
199
# Bad. Name shouldn't have existed.