git-gui: Factor out common fast-forward merge case
In both the ff and reset merge_types supported by checkout_op the result is the same if the merge base of our target commit and the existing commit is the existing commit: its a fast-forward as the existing commit is fully contained in the target commit. This minor cleanup in logic will make it easier to implement a new kind of merge_type that actually merges the two trees with a real merge strategy, such as git-merge-recursive. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
This commit is contained in:
@ -182,27 +182,23 @@ method _update_ref {} {
|
|||||||
#
|
#
|
||||||
} else {
|
} else {
|
||||||
catch {set merge_base [git merge-base $new $cur]}
|
catch {set merge_base [git merge-base $new $cur]}
|
||||||
switch -- $merge_type {
|
if {$merge_base eq $cur} {
|
||||||
ff {
|
# The current branch is older.
|
||||||
if {$merge_base eq $new} {
|
#
|
||||||
# The current branch is actually newer.
|
set reflog_msg "merge $new_expr: Fast-forward"
|
||||||
#
|
} else {
|
||||||
set new $cur
|
switch -- $merge_type {
|
||||||
} elseif {$merge_base eq $cur} {
|
ff {
|
||||||
# The current branch is older.
|
if {$merge_base eq $new} {
|
||||||
#
|
# The current branch is actually newer.
|
||||||
set reflog_msg "merge $new_expr: Fast-forward"
|
#
|
||||||
} else {
|
set new $cur
|
||||||
_error $this "Branch '$newbranch' already exists.\n\nIt cannot fast-forward to $new_expr.\nA merge is required."
|
} else {
|
||||||
return 0
|
_error $this "Branch '$newbranch' already exists.\n\nIt cannot fast-forward to $new_expr.\nA merge is required."
|
||||||
|
return 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
reset {
|
||||||
reset {
|
|
||||||
if {$merge_base eq $cur} {
|
|
||||||
# The current branch is older.
|
|
||||||
#
|
|
||||||
set reflog_msg "merge $new_expr: Fast-forward"
|
|
||||||
} else {
|
|
||||||
# The current branch will lose things.
|
# The current branch will lose things.
|
||||||
#
|
#
|
||||||
if {[_confirm_reset $this $cur]} {
|
if {[_confirm_reset $this $cur]} {
|
||||||
@ -211,11 +207,11 @@ method _update_ref {} {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
default {
|
||||||
default {
|
_error $this "Only 'ff' and 'reset' merge is currently supported."
|
||||||
_error $this "Only 'ff' and 'reset' merge is currently supported."
|
return 0
|
||||||
return 0
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user