Fossil SCM

fossil-scm / test / merge-history.test
Blame History Raw 155 lines
1
#
2
# Copyright (c) 2026 D. Richard Hipp
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the Simplified BSD License (also
6
# known as the "2-Clause License" or "FreeBSD License".)
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but without any warranty; without even the implied warranty of
10
# merchantability or fitness for a particular purpose.
11
#
12
# Author contact information:
13
# [email protected]
14
# http://www.hwaci.com/drh/
15
#
16
############################################################################
17
#
18
# The check-ins that "fossil merge --cherrypick" and "fossil merge
19
# --backout" record, and the check-in and user that "fossil annotate"
20
# and "fossil blame" report for each line of a file after those merges
21
# and a full merge.
22
#
23
24
set path [file dirname [info script]]
25
26
require_no_open_checkout
27
28
# Returns the P-card and Q-cards of the manifest of CHECKIN as a list of
29
# lines.
30
#
31
proc mergehist_cards {checkin} {
32
fossil artifact $checkin
33
return [regexp -all -inline -line {^[PQ] .*$} $::RESULT]
34
}
35
36
# Returns the check-in hash prefix and the text of each line of the
37
# output of "fossil annotate" or "fossil blame", as a list of pairs.
38
#
39
proc mergehist_lines {result} {
40
set lines [list]
41
foreach line [split $result \n] {
42
if {[regexp {^([0-9a-f]+) \S+ +(?:\d+|\S+): (.*)$} $line -> h text]} {
43
lappend lines [list $h $text]
44
}
45
}
46
return $lines
47
}
48
49
test_setup
50
51
commit_file a.txt "1\n2\n3\n4\n5\n" "mh-c1" --user-override alice
52
set c1 [checkin_hash mh-c1]
53
54
write_file a.txt "1\n2-trunk\n3\n4\n5\n"
55
fossil commit -m "mh-c2" --user-override bob
56
set c2 [checkin_hash mh-c2]
57
58
fossil update $c1
59
write_file a.txt "1\n2\n3\n4-feature\n5\n"
60
fossil commit -m "mh-f1" --branch mh-feature --user-override carol
61
set f1 [checkin_hash mh-f1]
62
write_file a.txt "1\n2\n3\n4-feature\n5\n6-feature\n"
63
commit_file g.txt "g\n" "mh-f2" --user-override carol
64
set f2 [checkin_hash mh-f2]
65
66
###############################################################################
67
#
68
# "fossil merge --cherrypick" applies the changes of one check-in: the
69
# edit of f1 and not the line and file that f2 adds. The check-in that
70
# follows has one parent and a Q-card "+F1".
71
#
72
fossil update trunk
73
fossil merge --cherrypick $f1
74
fossil commit -m "mh-pick" --user-override dave
75
set pick [checkin_hash mh-pick]
76
77
test_eq merge-history-cherrypick-content [read_file a.txt] \
78
"1\n2-trunk\n3\n4-feature\n5\n"
79
test_eq merge-history-cherrypick-no-g [file exists g.txt] 0
80
test_eq merge-history-cherrypick-cards [mergehist_cards $pick] \
81
[list "P $c2" "Q +$f1"]
82
83
###############################################################################
84
#
85
# "fossil merge --backout" reverses the changes of one check-in, here
86
# the edit of c2. The check-in that follows has one parent and a
87
# Q-card "-C2". A backout of the parent itself is recorded without a
88
# Q-card, so these tests back out an earlier check-in.
89
#
90
fossil merge --backout $c2
91
fossil commit -m "mh-backout" --user-override erin
92
set backout [checkin_hash mh-backout]
93
94
test_eq merge-history-backout-content [read_file a.txt] \
95
"1\n2\n3\n4-feature\n5\n"
96
test_eq merge-history-backout-cards [mergehist_cards $backout] \
97
[list "P $pick" "Q -$c2"]
98
99
###############################################################################
100
#
101
# A full merge of the branch brings in both of its check-ins, and the
102
# check-in that follows has two parents.
103
#
104
fossil merge mh-feature
105
fossil commit -m "mh-merge" --user-override frank
106
set merge [checkin_hash mh-merge]
107
108
test_eq merge-history-merge-content [read_file a.txt] \
109
"1\n2\n3\n4-feature\n5\n6-feature\n"
110
test_eq merge-history-merge-g [read_file g.txt] "g\n"
111
test_eq merge-history-merge-cards [mergehist_cards $merge] \
112
[list "P $backout $f2"]
113
114
###############################################################################
115
#
116
# "fossil annotate" follows the primary parent of each check-in, so it
117
# reports each line that came in with the merge as changed by the merge
118
# check-in, and the other lines as changed by the trunk check-in that
119
# last changed them: the backout for line 2, and the cherrypick for
120
# line 4.
121
#
122
set expected [list \
123
[list $c1 1] [list $backout 2] [list $c1 3] \
124
[list $pick 4-feature] [list $c1 5] [list $merge 6-feature]]
125
126
fossil annotate a.txt
127
set annotated [mergehist_lines $RESULT]
128
test_eq merge-history-annotate-count [llength $annotated] 6
129
foreach got $annotated want $expected {
130
lassign $got gotHash gotText
131
lassign $want wantHash wantText
132
test_eq merge-history-annotate-$wantText-text $gotText $wantText
133
test_eq merge-history-annotate-$wantText-checkin \
134
[string range $wantHash 0 [string length $gotHash]-1] $gotHash
135
}
136
137
# "fossil blame" reports the same check-ins, with the user who made each.
138
#
139
set users [dict create $c1 alice $pick dave $backout erin $merge frank]
140
fossil blame a.txt
141
set n 0
142
foreach line [split $RESULT \n] {
143
if {![regexp {^([0-9a-f]+) \S+ +(\S+): (.*)$} $line -> h user text]} {
144
continue
145
}
146
set wantHash [lindex $expected $n 0]
147
test_eq merge-history-blame-$text-user $user [dict get $users $wantHash]
148
incr n
149
}
150
test_eq merge-history-blame-count $n 6
151
152
###############################################################################
153
154
test_cleanup
155

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button