Skip to content

Commit bee866f

Browse files
angavrilovpaulusmack
authored andcommitted
gitk: Allow forcing branch creation if it already exists
If gitk knows that the branch the user tries to create exists, it should ask whether it should overwrite it. This way the user can either decide to choose a new name, or move the head while preserving the reflog. Signed-off-by: Alexander Gavrilov <[email protected]> Signed-off-by: Paul Mackerras <[email protected]>
1 parent d375ef9 commit bee866f

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

gitk

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7727,24 +7727,42 @@ proc mkbrgo {top} {
77277727

77287728
set name [$top.name get]
77297729
set id [$top.sha1 get]
7730+
set cmdargs {}
7731+
set old_id {}
77307732
if {$name eq {}} {
77317733
error_popup [mc "Please specify a name for the new branch"]
77327734
return
77337735
}
7736+
if {[info exists headids($name)]} {
7737+
if {![confirm_popup [mc \
7738+
"Branch '%s' already exists. Overwrite?" $name]]} {
7739+
return
7740+
}
7741+
set old_id $headids($name)
7742+
lappend cmdargs -f
7743+
}
77347744
catch {destroy $top}
7745+
lappend cmdargs $name $id
77357746
nowbusy newbranch
77367747
update
77377748
if {[catch {
7738-
exec git branch $name $id
7749+
eval exec git branch $cmdargs
77397750
} err]} {
77407751
notbusy newbranch
77417752
error_popup $err
77427753
} else {
7743-
set headids($name) $id
7744-
lappend idheads($id) $name
7745-
addedhead $id $name
77467754
notbusy newbranch
7747-
redrawtags $id
7755+
if {$old_id ne {}} {
7756+
movehead $id $name
7757+
movedhead $id $name
7758+
redrawtags $old_id
7759+
redrawtags $id
7760+
} else {
7761+
set headids($name) $id
7762+
lappend idheads($id) $name
7763+
addedhead $id $name
7764+
redrawtags $id
7765+
}
77487766
dispneartags 0
77497767
run refill_reflist
77507768
}

0 commit comments

Comments
 (0)