Skip to content

Commit

Permalink
git-gui: Setup branch.remote,merge for shorthand git-pull
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Shawn O. Pearce committed May 9, 2008
1 parent 259cd0f commit fe70225
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions git-gui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ proc apply_config {} {
}
}
set default_config(branch.autosetupmerge) true
set default_config(merge.diffstat) true
set default_config(merge.summary) false
set default_config(merge.verbosity) 2
Expand Down
3 changes: 3 additions & 0 deletions lib/branch_create.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ method _create {} {
if {$spec ne {} && $opt_fetch} {
$co enable_fetch $spec
}
if {$spec ne {}} {
$co remote_source $spec
}

if {[$co run]} {
destroy $w
Expand Down
24 changes: 23 additions & 1 deletion lib/checkout_op.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ field merge_base {}; # merge base if we have another ref involved
field fetch_spec {}; # refetch tracking branch if used?
field checkout 1; # actually checkout the branch?
field create 0; # create the branch if it doesn't exist?
field remote_source {}; # same as fetch_spec, to setup tracking

field reset_ok 0; # did the user agree to reset?
field fetch_ok 0; # did the fetch succeed?
Expand Down Expand Up @@ -44,6 +45,10 @@ method enable_fetch {spec} {
set fetch_spec $spec
}

method remote_source {spec} {
set remote_source $spec
}

method enable_checkout {co} {
set checkout $co
}
Expand Down Expand Up @@ -145,7 +150,7 @@ method _finish_fetch {ok} {
}

method _update_ref {} {
global null_sha1 current_branch
global null_sha1 current_branch repo_config

set ref $new_ref
set new $new_hash
Expand All @@ -172,6 +177,23 @@ method _update_ref {} {

set reflog_msg "branch: Created from $new_expr"
set cur $null_sha1

if {($repo_config(branch.autosetupmerge) eq {true}
|| $repo_config(branch.autosetupmerge) eq {always})
&& $remote_source ne {}
&& "refs/heads/$newbranch" eq $ref} {

set c_remote [lindex $remote_source 1]
set c_merge [lindex $remote_source 2]
if {[catch {
git config branch.$newbranch.remote $c_remote
git config branch.$newbranch.merge $c_merge
} err]} {
_error $this [strcat \
[mc "Failed to configure simplified git-pull for '%s'." $newbranch] \
"\n\n$err"]
}
}
} elseif {$create && $merge_type eq {none}} {
# We were told to create it, but not do a merge.
# Bad. Name shouldn't have existed.
Expand Down

0 comments on commit fe70225

Please sign in to comment.