Fossil SCM

Extend command coverage. bundle and export are tested by roundtripping, and so is patch create/revert/patch apply. Also test merge, branch, zip and tarball.

danshearer 2026-11-11 10:51 UTC test-suite-new
Commit c96895f393b6db59c78f0e12491ab3eacef63c78772e162784b7b6208395599d
+3 -1
--- test/README.md
+++ test/README.md
@@ -54,11 +54,13 @@
5454
## Coverage
5555
5656
| Area | Test files |
5757
| --- | --- |
5858
| Check-ins and the working tree | `amend`, `clean`, `commit-warning`, `mv-rm`, `revert`, `stash`, `symlinks`, `update` |
59
-| Merges | `merge1` to `merge6`, `merge_exe`, `merge_renames`, `merge_renames_2`, `merge_warn` |
59
+| Branches and tags | `branch-tag` |
60
+| Merges, cherrypicks, backouts, and annotate and blame after them | `merge1` to `merge6`, `merge-history`, `merge_exe`, `merge_renames`, `merge_renames_2`, `merge_warn` |
61
+| Git export and import, bundles, patches, ZIP and tarball archives | `roundtrip` |
6062
| Diffs and deltas | `delta1`, `diff` |
6163
| Settings | `settings`, `settings-repo`, `set-manifest` |
6264
| Wiki, attachments and unversioned files | `wiki`, `unversioned` |
6365
| TH1 scripting | `th1`, `th1-docs`, `th1-hooks`, `th1-repo`, `th1-taint`, `th1-tcl` |
6466
| JSON API | `json` |
6567
6668
ADDED test/branch-tag.test
6769
ADDED test/merge-history.test
6870
ADDED test/roundtrip.test
--- test/README.md
+++ test/README.md
@@ -54,11 +54,13 @@
54 ## Coverage
55
56 | Area | Test files |
57 | --- | --- |
58 | Check-ins and the working tree | `amend`, `clean`, `commit-warning`, `mv-rm`, `revert`, `stash`, `symlinks`, `update` |
59 | Merges | `merge1` to `merge6`, `merge_exe`, `merge_renames`, `merge_renames_2`, `merge_warn` |
 
 
60 | Diffs and deltas | `delta1`, `diff` |
61 | Settings | `settings`, `settings-repo`, `set-manifest` |
62 | Wiki, attachments and unversioned files | `wiki`, `unversioned` |
63 | TH1 scripting | `th1`, `th1-docs`, `th1-hooks`, `th1-repo`, `th1-taint`, `th1-tcl` |
64 | JSON API | `json` |
65
66 DDED test/branch-tag.test
67 DDED test/merge-history.test
68 DDED test/roundtrip.test
--- test/README.md
+++ test/README.md
@@ -54,11 +54,13 @@
54 ## Coverage
55
56 | Area | Test files |
57 | --- | --- |
58 | Check-ins and the working tree | `amend`, `clean`, `commit-warning`, `mv-rm`, `revert`, `stash`, `symlinks`, `update` |
59 | Branches and tags | `branch-tag` |
60 | Merges, cherrypicks, backouts, and annotate and blame after them | `merge1` to `merge6`, `merge-history`, `merge_exe`, `merge_renames`, `merge_renames_2`, `merge_warn` |
61 | Git export and import, bundles, patches, ZIP and tarball archives | `roundtrip` |
62 | Diffs and deltas | `delta1`, `diff` |
63 | Settings | `settings`, `settings-repo`, `set-manifest` |
64 | Wiki, attachments and unversioned files | `wiki`, `unversioned` |
65 | TH1 scripting | `th1`, `th1-docs`, `th1-hooks`, `th1-repo`, `th1-taint`, `th1-tcl` |
66 | JSON API | `json` |
67
68 DDED test/branch-tag.test
69 DDED test/merge-history.test
70 DDED test/roundtrip.test
--- a/test/branch-tag.test
+++ b/test/branch-tag.test
@@ -0,0 +1,138 @@
1
+##########################
2
+#
3
+# Creating, closing and reopening a branch, and adding and cancelling a
4
+# tag, a tag with a value and a propagating tag.
5
+#
6
+
7
+set path [file dirname [info script]]
8
+
9
+require_no_open_checkout
10
+
11
+# Returns the hash of the check-in of the open repository whose comment
12
+# is COMMENT.
13
+#
14
+proc branchtag_hash {comment} {
15
+ fossil timeline -t ci -n 0 -F {%H %c}
16
+ regexp -line "^(\[0-9a-f\]+) $comment\$" $::RESULT -> hash
17
+ return $hash
18
+}
19
+
20
+# Returns the hash of the current check-out.
21
+#
22
+proc branchtag_current {} {
23
+ fossil timeline before current -n 1 -t ci -F %H
24
+ return [first_data_line]
25
+}
26
+
27
+# Returns the output lines of the last command, without leading and
28
+# trailing white space, as a sorted list.
29
+#
30
+proc branchtag_lines {} {
31
+ set lines [list]
32
+ foreach line [split [normalize_result] \n] {
33
+ lappend lines [string trim $line]
34
+ }
35
+ return [lsort $lines]
36
+}
37
+
38
+test_setup
39
+
40
+write_file a.txt "a\n"
41
+fossil add a.txt
42
+fossil commit -m "bt-c1"
43
+set c1 [branchtag_hash bt-c1]
44
+write_file a.txt "a2\n"
45
+fossil commit -m "bt-c2"
46
+set c2 [branchtag_hash bt-c2]
47
+
48
+###############################################################################
49
+#
50
+# A new branch is listed as open, and a check-in on it stays on it.
51
+#
52
+fossil branch new bt-branch $c2
53
+fossil branch list
54
+test_eq branch-tag-new-listed [branchtag_lines] \
55
+ [lsort [list bt-branch {* trunk}]]
56
+
57
+fossil update bt-branch
58
+fossil branch current
59
+test_eq branch-tag-new-current [normalize_result] bt-branch
60
+write_file a.txt "on branch\n"
61
+fossil commit -m "bt-b1"
62
+fossil branch current
63
+test_eq branch-tag-new-commit [normalize_result] bt-branch
64
+
65
+###############################################################################
66
+#
67
+# A closed branch is listed only with --closed, and a check-in on it is
68
+# refused. Reopened, it is listed as open and accepts check-ins.
69
+#
70
+fossil branch close bt-branch
71
+fossil branch list
72
+test_eq branch-tag-close-open-list [branchtag_lines] [list trunk]
73
+fossil branch list --closed
74
+test_eq branch-tag-close-closed-list [branchtag_lines] [list {* bt-branch}]
75
+
76
+write_file a.txt "on closed branch\n"
77
+fossil commit -m "bt-on-closed" -expectError
78
+test_eq branch-tag-close-commit [normalize_result] \
79
+ "cannot commit against a closed leaf"
80
+
81
+fossil branch reopen bt-branch
82
+fossil branch list
83
+test_eq branch-tag-reopen-list [branchtag_lines] [list {* bt-branch} trunk]
84
+fossil commit -m "bt-b2"
85
+fossil branch current
86
+test_eq branch-tag-reopen-commit [normalize_result] bt-branch
87
+
88
+###############################################################################
89
+#
90
+# A tag on a check-in is listed for that check-in only, and "fossil
91
+# update TAG" moves the check-out to it. Cancelled, the tag is not
92
+# listed and "fossil update TAG" fails.
93
+#
94
+fossil update trunk
95
+fossil tag add bt-rel $c1
96
+fossil tag list $c1
97
+test_eq branch-tag-add-list [branchtag_lines] [list branch=trunk bt-rel trunk]
98
+fossil tag list $c2
99
+test_eq branch-tag-add-other [branchtag_lines] [list branch=trunk trunk]
100
+
101
+fossil update bt-rel
102
+test_eq branch-tag-add-update [branchtag_current] $c1
103
+
104
+fossil update trunk
105
+fossil tag cancel bt-rel $c1
106
+fossil tag list $c1
107
+test_eq branch-tag-cancel-list [branchtag_lines] [list branch=trunk trunk]
108
+fossil update bt-rel -expectError
109
+test_eq branch-tag-cancel-update [branchtag_current] $c2
110
+
111
+###############################################################################
112
+#
113
+# A tag with a value is listed as NAME=VALUE.
114
+#
115
+fossil tag add bt-value $c1 hello
116
+fossil tag list $c1
117
+test_eq branch-tag-value-list [branchtag_lines] \
118
+ [list branch=trunk bt-value=hello trunk]
119
+
120
+###############################################################################
121
+#
122
+# A propagating tag is listed for the check-in and its descendants on
123
+# the branch. Cancelled on the check-in, it is not listed for either.
124
+#
125
+fossil tag add --propagate bt-prop $c1
126
+fossil tag list $c2
127
+test_eq branch-tag-propagate-descendant [branchtag_lines] \
128
+ [list branch=trunk bt-prop trunk]
129
+
130
+fossil tag cancel bt-prop $c1
131
+fossil tag list $c1
132
+test_eq branch-tag-propagate-cancel [branchtag_lines] \
133
+ [list branch=trunk bt-value=hello trunk]
134
+fossil tag list $c2
135
+test_eq branch-tag-propagate-cancel-descendant [branchtag_lines] \
136
+ [list branch=trunk trunk]
137
+
138
+########################################
--- a/test/branch-tag.test
+++ b/test/branch-tag.test
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/test/branch-tag.test
+++ b/test/branch-tag.test
@@ -0,0 +1,138 @@
1 ##########################
2 #
3 # Creating, closing and reopening a branch, and adding and cancelling a
4 # tag, a tag with a value and a propagating tag.
5 #
6
7 set path [file dirname [info script]]
8
9 require_no_open_checkout
10
11 # Returns the hash of the check-in of the open repository whose comment
12 # is COMMENT.
13 #
14 proc branchtag_hash {comment} {
15 fossil timeline -t ci -n 0 -F {%H %c}
16 regexp -line "^(\[0-9a-f\]+) $comment\$" $::RESULT -> hash
17 return $hash
18 }
19
20 # Returns the hash of the current check-out.
21 #
22 proc branchtag_current {} {
23 fossil timeline before current -n 1 -t ci -F %H
24 return [first_data_line]
25 }
26
27 # Returns the output lines of the last command, without leading and
28 # trailing white space, as a sorted list.
29 #
30 proc branchtag_lines {} {
31 set lines [list]
32 foreach line [split [normalize_result] \n] {
33 lappend lines [string trim $line]
34 }
35 return [lsort $lines]
36 }
37
38 test_setup
39
40 write_file a.txt "a\n"
41 fossil add a.txt
42 fossil commit -m "bt-c1"
43 set c1 [branchtag_hash bt-c1]
44 write_file a.txt "a2\n"
45 fossil commit -m "bt-c2"
46 set c2 [branchtag_hash bt-c2]
47
48 ###############################################################################
49 #
50 # A new branch is listed as open, and a check-in on it stays on it.
51 #
52 fossil branch new bt-branch $c2
53 fossil branch list
54 test_eq branch-tag-new-listed [branchtag_lines] \
55 [lsort [list bt-branch {* trunk}]]
56
57 fossil update bt-branch
58 fossil branch current
59 test_eq branch-tag-new-current [normalize_result] bt-branch
60 write_file a.txt "on branch\n"
61 fossil commit -m "bt-b1"
62 fossil branch current
63 test_eq branch-tag-new-commit [normalize_result] bt-branch
64
65 ###############################################################################
66 #
67 # A closed branch is listed only with --closed, and a check-in on it is
68 # refused. Reopened, it is listed as open and accepts check-ins.
69 #
70 fossil branch close bt-branch
71 fossil branch list
72 test_eq branch-tag-close-open-list [branchtag_lines] [list trunk]
73 fossil branch list --closed
74 test_eq branch-tag-close-closed-list [branchtag_lines] [list {* bt-branch}]
75
76 write_file a.txt "on closed branch\n"
77 fossil commit -m "bt-on-closed" -expectError
78 test_eq branch-tag-close-commit [normalize_result] \
79 "cannot commit against a closed leaf"
80
81 fossil branch reopen bt-branch
82 fossil branch list
83 test_eq branch-tag-reopen-list [branchtag_lines] [list {* bt-branch} trunk]
84 fossil commit -m "bt-b2"
85 fossil branch current
86 test_eq branch-tag-reopen-commit [normalize_result] bt-branch
87
88 ###############################################################################
89 #
90 # A tag on a check-in is listed for that check-in only, and "fossil
91 # update TAG" moves the check-out to it. Cancelled, the tag is not
92 # listed and "fossil update TAG" fails.
93 #
94 fossil update trunk
95 fossil tag add bt-rel $c1
96 fossil tag list $c1
97 test_eq branch-tag-add-list [branchtag_lines] [list branch=trunk bt-rel trunk]
98 fossil tag list $c2
99 test_eq branch-tag-add-other [branchtag_lines] [list branch=trunk trunk]
100
101 fossil update bt-rel
102 test_eq branch-tag-add-update [branchtag_current] $c1
103
104 fossil update trunk
105 fossil tag cancel bt-rel $c1
106 fossil tag list $c1
107 test_eq branch-tag-cancel-list [branchtag_lines] [list branch=trunk trunk]
108 fossil update bt-rel -expectError
109 test_eq branch-tag-cancel-update [branchtag_current] $c2
110
111 ###############################################################################
112 #
113 # A tag with a value is listed as NAME=VALUE.
114 #
115 fossil tag add bt-value $c1 hello
116 fossil tag list $c1
117 test_eq branch-tag-value-list [branchtag_lines] \
118 [list branch=trunk bt-value=hello trunk]
119
120 ###############################################################################
121 #
122 # A propagating tag is listed for the check-in and its descendants on
123 # the branch. Cancelled on the check-in, it is not listed for either.
124 #
125 fossil tag add --propagate bt-prop $c1
126 fossil tag list $c2
127 test_eq branch-tag-propagate-descendant [branchtag_lines] \
128 [list branch=trunk bt-prop trunk]
129
130 fossil tag cancel bt-prop $c1
131 fossil tag list $c1
132 test_eq branch-tag-propagate-cancel [branchtag_lines] \
133 [list branch=trunk bt-value=hello trunk]
134 fossil tag list $c2
135 test_eq branch-tag-propagate-cancel-descendant [branchtag_lines] \
136 [list branch=trunk trunk]
137
138 ########################################
--- a/test/merge-history.test
+++ b/test/merge-history.test
@@ -0,0 +1,143 @@
1
+##########################
2
+#
3
+# The check-ins that "fossil merge --cherrypick" and "fossil merge
4
+# --backout" record, and the check-in and user that "fossil annotate"
5
+# and "fossil blame" report for each line of a file after those merges
6
+# and a full merge.
7
+#
8
+
9
+set path [file dirname [info script]]
10
+
11
+require_no_ophash of the check-in of the open repository whose comment
12
+# is COMMENT.
13
+#
14
+proc mergehist_hash {comment} {
15
+ fossil timeline -t ci -n 0 -F {%H %c}
16
+ regexp -line "^(\[0-9a-f\]+) [string map {. \\.} $comment]\$" \
17
+ $::RESU]
18
+
19
+require_no_open_checkout
20
+
21
+# Returns the P-card and Q-cards of the manifest of CHECKIN as a list of
22
+# lines.
23
+#
24
+proc mergehist_cards {checkin} {
25
+ fossil artifact $checkin
26
+ return [regexp -all -inline -line {^[PQ] .*$} $::RESULT]
27
+}
28
+
29
+# Returns the check-in hash prefix and the text of each line of the
30
+# output of "fossil annotate" or "fossil blame", as a list of pairs.
31
+#
32
+proc mergehist_lines {result} {
33
+ set lines [list]
34
+ foreach line [split $result \n] {
35
+ if {[regexp {^([0-9a-f]+) \S+ +(?:\d+|\S+): (.*)$} $line -> h text]} {
36
+ lappend lines [list $h $text]
37
+ }
38
+ }
39
+ rewrite_file a.txt "1\n2\n3\n4\n5\n"
40
+fossil add a.txtt "1\n2\n3\n4-feature\c11" --branch mh-feaalice
41
+set c1 [mergehist_hash mh-c1]
42
+
43
+write_file a.txt "1\n2-trunk\n3\n4\n5\n"
44
+fossil commit -m "mh-c2" -mergehistverride bob
45
+set c2 [checkin_hash mh-c2]
46
+
47
+fossil update $c1
48
+write_file a.txt "1\n2\n3\n4-feature\n5\n"
49
+fossil commit -m "mh-f1" --branch mh-feature --umergehist_hash mh-f1]
50
+write_file a.txt "1\n2\n3\n4-feature\n5\n6-feature\n"
51
+write_file gt "1\n2\n3\n4-feature\n5\n"
52
+fossil commit -m "mh-f1" --branch mh-feature --user-override carol
53
+set f1 [checkin_hash mh-f1]
54
+write_file a.txt "1\n2\n3\n4-feature\n5\n6-feature\n"
55
+commit_file g.txt "g\n" "mh-f2" --user-override carol
56
+set f2 [checkin_hash mh-f2]
57
+
58
+###############################################################################
59
+#
60
+# "fossil merge --cherrypick" applies the changes of one check-in: the
61
+# edit of f1 and not the line and file that f2 adds. The check-in that
62
+# follows has one parent and a Q-card "+F1".
63
+#
64
+fossil update trunk
65
+fossil merge --cherrypick $f1
66
+fossil commit -m "mh-pick" --user-override dave
67
+set pick [checkin_hash mh-pick]
68
+
69
+test_eq merge-history-cherrypick-content [read_file a.txt] \
70
+ "1\n2-trunk\n3\n4-feature\n5\n"
71
+test_eq merge-history-cherrypick-no-g [file exists g.txt] 0
72
+test_eq merge-history-cherrypick-cards [mergehist_cards $pick] \
73
+ [list "P $c2" "Q +$f1"]
74
+
75
+###############################################################################
76
+#
77
+# "fossil merge --backout" reverses the changes of one check-in, here
78
+# the edit of c2. The check-in that follows has one parent and a
79
+# Q-card "-C2". A backout of the parent itself is recorded without a
80
+# Q-card, so these tests back out an earlier check-in.
81
+#
82
+fossil merge --backout $c2
83
+fossil commit -m "mh-backout" --user-override erin
84
+set backout [checkin_hash mh-backout]
85
+
86
+test_eq merge-history-backout-content [read_file a.txt] \
87
+ "1\n2\n3\n4-feature\n5\n"
88
+test_eq merge-history-backout-cards [mergehist_cards $backout] \
89
+ [list "P $pick" "Q -$c2"]
90
+
91
+###############################################################################
92
+#
93
+# A full merge of the branch brings in both of its check-ins, and the
94
+# check-in that follows has two parents.
95
+#
96
+fossil merge mh-feature
97
+fossil commit -m "mh-merge" --user-override frank
98
+set merge [checkin_hash mh-merge]
99
+
100
+test_eq merge-history-merge-content [read_file a.txt] \
101
+ "1\n2\n3\n4-feature\n5\n6-feature\n"
102
+test_eq merge-history-merge-g [read_file g.txt] "g\n"
103
+test_eq merge-history-merge-cards [mergehist_cards $merge] \
104
+ [list "P $backout $f2"]
105
+
106
+###############################################################################
107
+#
108
+# "fossil annotate" follows the primary parent of each check-in, so it
109
+# reports each line that came in with the merge as changed by the merge
110
+# check-in, and the other lines as changed by the trunk check-in that
111
+# last changed them: the backout for line 2, and the cherrypick for
112
+# line 4.
113
+#
114
+set expected [list \
115
+ [list $c1 1] [list $backout 2] [list $c1 3] \
116
+ [list $pick 4-feature] [list $c1 5] [list $merge 6-feature]]
117
+
118
+fossil annotate a.txt
119
+set annotated [mergehist_lines $RESULT]
120
+test_eq merge-history-annotate-count [llength $annotated] 6
121
+foreach got $annotated want $expected {
122
+ lassign $got gotHash gotText
123
+ lassign $want wantHash wantText
124
+ test_eq merge-history-annotate-$wantText-text $gotText $wantText
125
+ test_eq merge-history-annotate-$wantText-checkin \
126
+ [string range $wantHash 0 [string length $gotHash]-1] $gotHash
127
+}
128
+
129
+# "fossil blame" reports the same check-ins, with the user who made each.
130
+#
131
+set users [dict create $c1 alice $pick dave $backout erin $merge frank]
132
+fossil blame a.txt
133
+set n 0
134
+foreach line [split $RESULT \n] {
135
+ if {![regexp {^([0-9a-f]+) \S+ +(\S+): (.*)$} $line -> h user text]} {
136
+ continue
137
+ }
138
+ set wantHash [lindex $expected $n 0]
139
+ test_eq merge-history-blame-$text-user $user [dict get $users $wantHash]
140
+ incr n
141
+}
142
+test_eq merge-history-blame-count $n 6
143
+
--- a/test/merge-history.test
+++ b/test/merge-history.test
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/test/merge-history.test
+++ b/test/merge-history.test
@@ -0,0 +1,143 @@
1 ##########################
2 #
3 # The check-ins that "fossil merge --cherrypick" and "fossil merge
4 # --backout" record, and the check-in and user that "fossil annotate"
5 # and "fossil blame" report for each line of a file after those merges
6 # and a full merge.
7 #
8
9 set path [file dirname [info script]]
10
11 require_no_ophash of the check-in of the open repository whose comment
12 # is COMMENT.
13 #
14 proc mergehist_hash {comment} {
15 fossil timeline -t ci -n 0 -F {%H %c}
16 regexp -line "^(\[0-9a-f\]+) [string map {. \\.} $comment]\$" \
17 $::RESU]
18
19 require_no_open_checkout
20
21 # Returns the P-card and Q-cards of the manifest of CHECKIN as a list of
22 # lines.
23 #
24 proc mergehist_cards {checkin} {
25 fossil artifact $checkin
26 return [regexp -all -inline -line {^[PQ] .*$} $::RESULT]
27 }
28
29 # Returns the check-in hash prefix and the text of each line of the
30 # output of "fossil annotate" or "fossil blame", as a list of pairs.
31 #
32 proc mergehist_lines {result} {
33 set lines [list]
34 foreach line [split $result \n] {
35 if {[regexp {^([0-9a-f]+) \S+ +(?:\d+|\S+): (.*)$} $line -> h text]} {
36 lappend lines [list $h $text]
37 }
38 }
39 rewrite_file a.txt "1\n2\n3\n4\n5\n"
40 fossil add a.txtt "1\n2\n3\n4-feature\c11" --branch mh-feaalice
41 set c1 [mergehist_hash mh-c1]
42
43 write_file a.txt "1\n2-trunk\n3\n4\n5\n"
44 fossil commit -m "mh-c2" -mergehistverride bob
45 set c2 [checkin_hash mh-c2]
46
47 fossil update $c1
48 write_file a.txt "1\n2\n3\n4-feature\n5\n"
49 fossil commit -m "mh-f1" --branch mh-feature --umergehist_hash mh-f1]
50 write_file a.txt "1\n2\n3\n4-feature\n5\n6-feature\n"
51 write_file gt "1\n2\n3\n4-feature\n5\n"
52 fossil commit -m "mh-f1" --branch mh-feature --user-override carol
53 set f1 [checkin_hash mh-f1]
54 write_file a.txt "1\n2\n3\n4-feature\n5\n6-feature\n"
55 commit_file g.txt "g\n" "mh-f2" --user-override carol
56 set f2 [checkin_hash mh-f2]
57
58 ###############################################################################
59 #
60 # "fossil merge --cherrypick" applies the changes of one check-in: the
61 # edit of f1 and not the line and file that f2 adds. The check-in that
62 # follows has one parent and a Q-card "+F1".
63 #
64 fossil update trunk
65 fossil merge --cherrypick $f1
66 fossil commit -m "mh-pick" --user-override dave
67 set pick [checkin_hash mh-pick]
68
69 test_eq merge-history-cherrypick-content [read_file a.txt] \
70 "1\n2-trunk\n3\n4-feature\n5\n"
71 test_eq merge-history-cherrypick-no-g [file exists g.txt] 0
72 test_eq merge-history-cherrypick-cards [mergehist_cards $pick] \
73 [list "P $c2" "Q +$f1"]
74
75 ###############################################################################
76 #
77 # "fossil merge --backout" reverses the changes of one check-in, here
78 # the edit of c2. The check-in that follows has one parent and a
79 # Q-card "-C2". A backout of the parent itself is recorded without a
80 # Q-card, so these tests back out an earlier check-in.
81 #
82 fossil merge --backout $c2
83 fossil commit -m "mh-backout" --user-override erin
84 set backout [checkin_hash mh-backout]
85
86 test_eq merge-history-backout-content [read_file a.txt] \
87 "1\n2\n3\n4-feature\n5\n"
88 test_eq merge-history-backout-cards [mergehist_cards $backout] \
89 [list "P $pick" "Q -$c2"]
90
91 ###############################################################################
92 #
93 # A full merge of the branch brings in both of its check-ins, and the
94 # check-in that follows has two parents.
95 #
96 fossil merge mh-feature
97 fossil commit -m "mh-merge" --user-override frank
98 set merge [checkin_hash mh-merge]
99
100 test_eq merge-history-merge-content [read_file a.txt] \
101 "1\n2\n3\n4-feature\n5\n6-feature\n"
102 test_eq merge-history-merge-g [read_file g.txt] "g\n"
103 test_eq merge-history-merge-cards [mergehist_cards $merge] \
104 [list "P $backout $f2"]
105
106 ###############################################################################
107 #
108 # "fossil annotate" follows the primary parent of each check-in, so it
109 # reports each line that came in with the merge as changed by the merge
110 # check-in, and the other lines as changed by the trunk check-in that
111 # last changed them: the backout for line 2, and the cherrypick for
112 # line 4.
113 #
114 set expected [list \
115 [list $c1 1] [list $backout 2] [list $c1 3] \
116 [list $pick 4-feature] [list $c1 5] [list $merge 6-feature]]
117
118 fossil annotate a.txt
119 set annotated [mergehist_lines $RESULT]
120 test_eq merge-history-annotate-count [llength $annotated] 6
121 foreach got $annotated want $expected {
122 lassign $got gotHash gotText
123 lassign $want wantHash wantText
124 test_eq merge-history-annotate-$wantText-text $gotText $wantText
125 test_eq merge-history-annotate-$wantText-checkin \
126 [string range $wantHash 0 [string length $gotHash]-1] $gotHash
127 }
128
129 # "fossil blame" reports the same check-ins, with the user who made each.
130 #
131 set users [dict create $c1 alice $pick dave $backout erin $merge frank]
132 fossil blame a.txt
133 set n 0
134 foreach line [split $RESULT \n] {
135 if {![regexp {^([0-9a-f]+) \S+ +(\S+): (.*)$} $line -> h user text]} {
136 continue
137 }
138 set wantHash [lindex $expected $n 0]
139 test_eq merge-history-blame-$text-user $user [dict get $users $wantHash]
140 incr n
141 }
142 test_eq merge-history-blame-count $n 6
143
--- a/test/roundtrip.test
+++ b/test/roundtrip.test
@@ -0,0 +1,301 @@
1
+#
2
+# Round trips: "fossil export --git" into "fossil import --git",
3
+# "fossil bundle export" into "fossil bundle import", "fossil patch
4
+# create" into "fossil patch apply", and the files in "fossil zip" and
5
+# "fossil tarball" compared with the files of the check-in.
6
+#
7
+
8
+set path [file dirname [info script]]
9
+
10
+require_no_open_checkout
11
+
12
+# Returns the F-cards of the manifest of CHECKIN in REPO, sorted, as a
13
+# list of {NAME HASH} pairs.
14
+#
15
+proc roundtrip_files {repo checkin} {
16
+ fossil artifact $checkin -R $repo
17
+ set files [list]
18
+ foreach line [split $::RESULT \n] {
19
+ if {[regexp {^F (\S+) (\S+)} $line -> name hash]} {
20
+ lappend files [list $name $hash]
21
+ }
22
+ }
23
+ return [lsort $files]
24
+}
25
+
26
+# Returns the check-ins of REPO as a dictionary from comment to
27
+# {BRANCH HASH}. The comments of the check-ins in these tests are
28
+# distinct.
29
+#
30
+proc roundtrip_checkins {repo} {
31
+ fossil timeline -R $repo -t ci -n 0 -F {%H|%b|%c}
32
+ set result [dict create]
33
+ foreach line [split $::RESULT \n] {
34
+ if {[regexp {^([0-9a-f]{40,})\|([^|]*)\|(.*)$} $line -> hash branch c]} {
35
+ dict set result $c [list $branch $hash]
36
+ }
37
+ }
38
+ return $result
39
+}
40
+
41
+# Returns the files of an archive as a dictionary from name to content,
42
+# without the top-level directory PREFIX and without directories.
43
+# FORMAT is "zip" or "tarball".
44
+#
45
+proc roundtrip_archive_files {fileName format prefix} {
46
+ set fd [open $fileName rb]
47
+ set data [read $fd]
48
+ close $fd
49
+ set result [dict create]
50
+ if {$format eq "tarball"} {
51
+ set data [zlib gunzip $data]
52
+ set pos 0
53
+ while {$pos + 512 <= [string length $data]} {
54
+ set header [string range $data $pos [expr {$pos + 511}]]
55
+ binary scan $header a100a24a12a12a8a1a100a6a2a32a32a8a8a155 \
56
+ name x sizeText x x type x magic x x x x x tarPrefix
57
+ set name [string trimright $name \0]
58
+ if {$name eq ""} break
59
+ set tarPrefix [string trimright $tarPrefix \0]
60
+ if {$tarPrefix ne ""} {set name $tarPrefix/$name}
61
+ set size [scan [string trim $sizeText "\0 "] %o]
62
+ set start [expr {$pos + 512}]
63
+ if {$type eq "0" || $type eq "\0"} {
64
+ dict set result $name \
65
+ [string range $data $start [expr {$start + $size - 1}]]
66
+ }
67
+ set pos [expr {$start + (($size + 511) / 512) * 512}]
68
+ }
69
+ } else {
70
+ set end [string last "PK\x05\x06" $data]
71
+ binary scan $data @[expr {$end + 10}]su count
72
+ binary scan $data @[expr {$end + 16}]iu pos
73
+ for {set i 0} {$i < $count} {incr i} {
74
+ binary scan $data @${pos}a4x6sux4x4iuiusususu \
75
+ sig method csize usize nameLen extraLen commentLen
76
+ binary scan $data @[expr {$pos + 42}]iu localPos
77
+ set name [string range $data [expr {$pos + 46}] \
78
+ [expr {$pos + 45 + $nameLen}]]
79
+ set pos [expr {$pos + 46 + $nameLen + $extraLen + $commentLen}]
80
+ if {[string index $name end] eq "/"} continue
81
+ binary scan $data @[expr {$localPos + 26}]susu localNameLen localExtraLen
82
+ set start [expr {$localPos + 30 + $localNameLen + $localExtraLen}]
83
+ set content [string range $data $start [expr {$start + $csize - 1}]]
84
+ if {$method == 8} {
85
+ set content [zlib inflate $content]
86
+ }
87
+ dict set result $name $content
88
+ }
89
+ }
90
+ set files [dict create]
91
+ dict for {name content} $result {
92
+ if {[string first $prefix/ $name] == 0} {
93
+ dict set files [string range $name [string length $prefix/] end] \
94
+ $content
95
+ } else {
96
+ dict set files $name $content
97
+ }
98
+ }
99
+ return $files
100
+}
101
+
102
+# Returns the files of CHECKIN in the open repository as a dictionary
103
+# from name to content.
104
+#
105
+proc roundtrip_checkin_files {checkin} {
106
+ set files [dict create]
107
+ fossil ls -r $checkin
108
+ foreach name [split [string trim $::RESULT] \n] {
109
+ set fd [open "|[list $::fossilexe cat -r $checkin $name]" rb]
110
+ dict set files $name [read $fd]
111
+ close $fd
112
+ }
113
+ return $files
114
+}
115
+
116
+# Returns a dictionary from the name of each file in the current
117
+# directory and below, except those in SKIP, to its content.
118
+#
119
+proc roundtrip_dir_files {{dir .} {skip {}}} {
120
+ set files [dict create]
121
+ foreach f [glob -nocomplain -directory $dir -tails *] {
122
+ set p [expr {$dir eq "." ? $f : "$dir/$f"}]
123
+ if {$p in $skip} continue
124
+ if {[file isdirectory $p]} {
125
+ set files [dict merge $files [roundtrip_dir_files $p $skip]]
126
+ } else {
127
+ dict set files $p [read_file $p]
128
+ }
129
+ }
130
+ return $files
131
+}
132
+
133
+###############################################################################
134
+#
135
+# A history with a branch, a rename, a deletion, a merge and a file
136
+# with no newline at its end.
137
+#
138
+test_setup
139
+set repo [file join [pwd] .rep.fossil]
140
+
141
+write_file a.txt "one\ntwo\nthree\n"
142
+write_file b.txt "b\n"
143
+file mkdir sub
144
+write_file sub/c.txt "c\n"
145
+write_file noeol.txt "no newline"
146
+fossil add a.txt b.txt sub noeol.txt
147
+fossil commit -m "rt-c1"
148
+
149
+write_file a.txt "one\nTWO\nthree\n"
150
+write_file d.txt "d\n"
151
+fossil add d.txt
152
+fossil commit -m "rt-c2"
153
+
154
+fossil branch new rt-feature current
155
+fossil update rt-feature
156
+write_file a.txt "one\nTWO\nthree\nfour\n"
157
+fossil commit -m "rt-f1"
158
+write_file b.txt "b2\n"
159
+fossil commit -m "rt-f2"
160
+
161
+fossil update trunk
162
+fossil rm --hard d.txt
163
+fossil mv --hard sub/c.txt sub/c2.txt
164
+fossil commit -m "rt-c3"
165
+fossil merge rt-feature
166
+fossil commit -m "rt-c4"
167
+
168
+set original [roundtrip_checkins $repo]
169
+test_eq roundtrip-setup-checkins [lsort [dict keys $original]] \
170
+ [lsort {rt-c1 rt-c2 rt-c3 rt-c4 rt-f1 rt-f2 {initial empty check-in}
171
+ {Create new branch named "rt-feature"}}]
172
+
173
+###############################################################################
174
+#
175
+# "fossil export --git" into "fossil import --git": each check-in keeps
176
+# its comment, its branch and its files with their content.
177
+#
178
+exec $::fossilexe export --git > export.git
179
+fossil import --git imported.fossil export.git
180
+set imported [roundtrip_checkins imported.fossil]
181
+
182
+test_eq roundtrip-git-checkins [lsort [dict keys $imported]] \
183
+ [lsort [dict keys $original]]
184
+
185
+dict for {comment info} $original {
186
+ if {![dict exists $imported $comment]} continue
187
+ lassign $info branch ciHash
188
+ lassign [dict get $imported $comment] importedBranch importedHash
189
+ set label [string trim [regsub -all {[^A-Za-z0-9]+} $comment -] -]
190
+ test_eq roundtrip-git-branch-$label $importedBranch $branch
191
+ test_eq roundtrip-git-files-$label \
192
+ [roundtrip_files imported.fossil $importedHash] \
193
+ [roundtrip_files $repo $ciHash]
194
+}
195
+
196
+# The merge keeps both parents: its P-card lists two check-ins.
197
+#
198
+fossil artifact [lindex [dict get $imported rt-c4] 1] -R imported.fossil
199
+regexp -line {^P (.*)$} $RESULT -> parents
200
+test_eq roundtrip-git-merge-parents [llength $parents] 2
201
+
202
+file delete export.git imported.fossil
203
+
204
+###############################################################################
205
+#
206
+# "fossil bundle export" of a branch, and "fossil bundle import
207
+# --publish" into a clone made before the branch: the clone then has
208
+# each check-in of the branch under the same hash, with the same files.
209
+#
210
+fossil clone $repo clone.fossil
211
+
212
+fossil update trunk
213
+fossil branch new rt-bundled current
214
+fossil update rt-bundled
215
+write_file a.txt "bundled\n"
216
+fossil commit -m "rt-b1"
217
+write_file e.txt "e\n"
218
+fossil add e.txt
219
+fossil commit -m "rt-b2"
220
+fossil update trunk
221
+
222
+fossil bundle export rt.bundle --branch rt-bundled
223
+fossil bundle import rt.bundle --publish -R clone.fossil
224
+
225
+set afterBundle [roundtrip_checkins clone.fossil]
226
+foreach comment {rt-b1 rt-b2} {
227
+ set ciHash [lindex [dict get [roundtrip_checkins $repo] $comment] 1]
228
+ test_eq "roundtrip-bundle-hash-$comment" \
229
+ [lindex [dict get $afterBundle $comment] 1] $ciHash
230
+ test_eq "roundtrip-bundle-files-$comment" \
231
+ [roundtrip_files clone.fossil $ciHash] [roundtrip_files $repo $ciHash]
232
+}
233
+fossil cat e.txt -r rt-bundled -R clone.fossil
234
+test_eq roundtrip-bundle-content $RESULT "e"
235
+
236
+file delete rt.bundle clone.fossil
237
+
238
+###############################################################################
239
+#
240
+# "fossil patch create" of uncommitted changes, then "fossil revert" and
241
+# "fossil patch apply": the check-out has the same changes and files.
242
+#
243
+fossil update trunk
244
+write_file a.txt "patched\n"
245
+write_file new.txt "new\n"
246
+fossil add new.txt
247
+fossil rm --hard b.txt
248
+fossil mv --hard sub/c2.txt sub/c3.txt
249
+write_file noeol.txt "still no newline"
250
+
251
+fossil changes
252
+set changesBefore [normalize_result]
253
+set filesBefore [roundtrip_dir_files . {rt.patch}]
254
+
255
+fossil patch create rt.patch
256
+
257
+# The patch records the name of the computer it was made on. fossil
258
+# reads the name from the "hostname" program, so where that program is
259
+# missing, the name is empty and the shell's error atter case or in its domain.
260
+#
261
+fossil sqlite3 --no-repository rt.patch \
262
+ "SELECT value FROM cfg WHERE key='hostname'"
263
+if {[auto_execok hostnaConstraint knownc hostname]]
264
+ set hostnameConstraint ""
265
+}
266
+test_eq roundtrip-patch-h[info hostname] \
267
+ $hostnameConstraint
268
+
269
+fossil revert
270
+file delete new.txt
271
+fossil changes
272
+test_eq roundtrip-patch-reverted [normalize_result] ""
273
+
274
+fossil patch apply rt.patch
275
+fossil changes
276
+test_eq roundtrip-patch-changes [normalize_result] $changesBefore
277
+test_eq roundtrip-patch-files [roundtrip_dir_files . {rt.patch}] $filesBefore
278
+
279
+fossil revert
280
+file delete new.txt rt.patch
281
+
282
+###############################################################################
283
+#
284
+# The files in "fossil zip" and "fossil tarball" of a check-in are the
285
+# files of the check-in, with the same content.
286
+#
287
+set mergeHash [lindex [dict get $original rt-c4] 1]
288
+set expected [roundtrip_checkin_files $mergeHash]
289
+test_eq roundtrip-archive-names [lsort [dict keys $expected]] \
290
+ {a.txt b.txt noeol.txt sub/c2.txt}
291
+fossil zip $mergeHash rt.zip --name rt
292
+test_eq roundtrip-zip-files \
293
+ [roundtrip_archive_files rt.zip zip rt] $expected
294
+fossil tarball $mergeHash rt.tar.gz --name rt
295
+test_eq roundtrip-tarball-files \
296
+ [roundtrip_archive_files rt.tar.gz tarball rt] $expected
297
+file delete rt.zip rt.tar.gz
298
+
299
+###############################################################################
300
+
301
+test_cleanup
--- a/test/roundtrip.test
+++ b/test/roundtrip.test
@@ -0,0 +1,301 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/test/roundtrip.test
+++ b/test/roundtrip.test
@@ -0,0 +1,301 @@
1 #
2 # Round trips: "fossil export --git" into "fossil import --git",
3 # "fossil bundle export" into "fossil bundle import", "fossil patch
4 # create" into "fossil patch apply", and the files in "fossil zip" and
5 # "fossil tarball" compared with the files of the check-in.
6 #
7
8 set path [file dirname [info script]]
9
10 require_no_open_checkout
11
12 # Returns the F-cards of the manifest of CHECKIN in REPO, sorted, as a
13 # list of {NAME HASH} pairs.
14 #
15 proc roundtrip_files {repo checkin} {
16 fossil artifact $checkin -R $repo
17 set files [list]
18 foreach line [split $::RESULT \n] {
19 if {[regexp {^F (\S+) (\S+)} $line -> name hash]} {
20 lappend files [list $name $hash]
21 }
22 }
23 return [lsort $files]
24 }
25
26 # Returns the check-ins of REPO as a dictionary from comment to
27 # {BRANCH HASH}. The comments of the check-ins in these tests are
28 # distinct.
29 #
30 proc roundtrip_checkins {repo} {
31 fossil timeline -R $repo -t ci -n 0 -F {%H|%b|%c}
32 set result [dict create]
33 foreach line [split $::RESULT \n] {
34 if {[regexp {^([0-9a-f]{40,})\|([^|]*)\|(.*)$} $line -> hash branch c]} {
35 dict set result $c [list $branch $hash]
36 }
37 }
38 return $result
39 }
40
41 # Returns the files of an archive as a dictionary from name to content,
42 # without the top-level directory PREFIX and without directories.
43 # FORMAT is "zip" or "tarball".
44 #
45 proc roundtrip_archive_files {fileName format prefix} {
46 set fd [open $fileName rb]
47 set data [read $fd]
48 close $fd
49 set result [dict create]
50 if {$format eq "tarball"} {
51 set data [zlib gunzip $data]
52 set pos 0
53 while {$pos + 512 <= [string length $data]} {
54 set header [string range $data $pos [expr {$pos + 511}]]
55 binary scan $header a100a24a12a12a8a1a100a6a2a32a32a8a8a155 \
56 name x sizeText x x type x magic x x x x x tarPrefix
57 set name [string trimright $name \0]
58 if {$name eq ""} break
59 set tarPrefix [string trimright $tarPrefix \0]
60 if {$tarPrefix ne ""} {set name $tarPrefix/$name}
61 set size [scan [string trim $sizeText "\0 "] %o]
62 set start [expr {$pos + 512}]
63 if {$type eq "0" || $type eq "\0"} {
64 dict set result $name \
65 [string range $data $start [expr {$start + $size - 1}]]
66 }
67 set pos [expr {$start + (($size + 511) / 512) * 512}]
68 }
69 } else {
70 set end [string last "PK\x05\x06" $data]
71 binary scan $data @[expr {$end + 10}]su count
72 binary scan $data @[expr {$end + 16}]iu pos
73 for {set i 0} {$i < $count} {incr i} {
74 binary scan $data @${pos}a4x6sux4x4iuiusususu \
75 sig method csize usize nameLen extraLen commentLen
76 binary scan $data @[expr {$pos + 42}]iu localPos
77 set name [string range $data [expr {$pos + 46}] \
78 [expr {$pos + 45 + $nameLen}]]
79 set pos [expr {$pos + 46 + $nameLen + $extraLen + $commentLen}]
80 if {[string index $name end] eq "/"} continue
81 binary scan $data @[expr {$localPos + 26}]susu localNameLen localExtraLen
82 set start [expr {$localPos + 30 + $localNameLen + $localExtraLen}]
83 set content [string range $data $start [expr {$start + $csize - 1}]]
84 if {$method == 8} {
85 set content [zlib inflate $content]
86 }
87 dict set result $name $content
88 }
89 }
90 set files [dict create]
91 dict for {name content} $result {
92 if {[string first $prefix/ $name] == 0} {
93 dict set files [string range $name [string length $prefix/] end] \
94 $content
95 } else {
96 dict set files $name $content
97 }
98 }
99 return $files
100 }
101
102 # Returns the files of CHECKIN in the open repository as a dictionary
103 # from name to content.
104 #
105 proc roundtrip_checkin_files {checkin} {
106 set files [dict create]
107 fossil ls -r $checkin
108 foreach name [split [string trim $::RESULT] \n] {
109 set fd [open "|[list $::fossilexe cat -r $checkin $name]" rb]
110 dict set files $name [read $fd]
111 close $fd
112 }
113 return $files
114 }
115
116 # Returns a dictionary from the name of each file in the current
117 # directory and below, except those in SKIP, to its content.
118 #
119 proc roundtrip_dir_files {{dir .} {skip {}}} {
120 set files [dict create]
121 foreach f [glob -nocomplain -directory $dir -tails *] {
122 set p [expr {$dir eq "." ? $f : "$dir/$f"}]
123 if {$p in $skip} continue
124 if {[file isdirectory $p]} {
125 set files [dict merge $files [roundtrip_dir_files $p $skip]]
126 } else {
127 dict set files $p [read_file $p]
128 }
129 }
130 return $files
131 }
132
133 ###############################################################################
134 #
135 # A history with a branch, a rename, a deletion, a merge and a file
136 # with no newline at its end.
137 #
138 test_setup
139 set repo [file join [pwd] .rep.fossil]
140
141 write_file a.txt "one\ntwo\nthree\n"
142 write_file b.txt "b\n"
143 file mkdir sub
144 write_file sub/c.txt "c\n"
145 write_file noeol.txt "no newline"
146 fossil add a.txt b.txt sub noeol.txt
147 fossil commit -m "rt-c1"
148
149 write_file a.txt "one\nTWO\nthree\n"
150 write_file d.txt "d\n"
151 fossil add d.txt
152 fossil commit -m "rt-c2"
153
154 fossil branch new rt-feature current
155 fossil update rt-feature
156 write_file a.txt "one\nTWO\nthree\nfour\n"
157 fossil commit -m "rt-f1"
158 write_file b.txt "b2\n"
159 fossil commit -m "rt-f2"
160
161 fossil update trunk
162 fossil rm --hard d.txt
163 fossil mv --hard sub/c.txt sub/c2.txt
164 fossil commit -m "rt-c3"
165 fossil merge rt-feature
166 fossil commit -m "rt-c4"
167
168 set original [roundtrip_checkins $repo]
169 test_eq roundtrip-setup-checkins [lsort [dict keys $original]] \
170 [lsort {rt-c1 rt-c2 rt-c3 rt-c4 rt-f1 rt-f2 {initial empty check-in}
171 {Create new branch named "rt-feature"}}]
172
173 ###############################################################################
174 #
175 # "fossil export --git" into "fossil import --git": each check-in keeps
176 # its comment, its branch and its files with their content.
177 #
178 exec $::fossilexe export --git > export.git
179 fossil import --git imported.fossil export.git
180 set imported [roundtrip_checkins imported.fossil]
181
182 test_eq roundtrip-git-checkins [lsort [dict keys $imported]] \
183 [lsort [dict keys $original]]
184
185 dict for {comment info} $original {
186 if {![dict exists $imported $comment]} continue
187 lassign $info branch ciHash
188 lassign [dict get $imported $comment] importedBranch importedHash
189 set label [string trim [regsub -all {[^A-Za-z0-9]+} $comment -] -]
190 test_eq roundtrip-git-branch-$label $importedBranch $branch
191 test_eq roundtrip-git-files-$label \
192 [roundtrip_files imported.fossil $importedHash] \
193 [roundtrip_files $repo $ciHash]
194 }
195
196 # The merge keeps both parents: its P-card lists two check-ins.
197 #
198 fossil artifact [lindex [dict get $imported rt-c4] 1] -R imported.fossil
199 regexp -line {^P (.*)$} $RESULT -> parents
200 test_eq roundtrip-git-merge-parents [llength $parents] 2
201
202 file delete export.git imported.fossil
203
204 ###############################################################################
205 #
206 # "fossil bundle export" of a branch, and "fossil bundle import
207 # --publish" into a clone made before the branch: the clone then has
208 # each check-in of the branch under the same hash, with the same files.
209 #
210 fossil clone $repo clone.fossil
211
212 fossil update trunk
213 fossil branch new rt-bundled current
214 fossil update rt-bundled
215 write_file a.txt "bundled\n"
216 fossil commit -m "rt-b1"
217 write_file e.txt "e\n"
218 fossil add e.txt
219 fossil commit -m "rt-b2"
220 fossil update trunk
221
222 fossil bundle export rt.bundle --branch rt-bundled
223 fossil bundle import rt.bundle --publish -R clone.fossil
224
225 set afterBundle [roundtrip_checkins clone.fossil]
226 foreach comment {rt-b1 rt-b2} {
227 set ciHash [lindex [dict get [roundtrip_checkins $repo] $comment] 1]
228 test_eq "roundtrip-bundle-hash-$comment" \
229 [lindex [dict get $afterBundle $comment] 1] $ciHash
230 test_eq "roundtrip-bundle-files-$comment" \
231 [roundtrip_files clone.fossil $ciHash] [roundtrip_files $repo $ciHash]
232 }
233 fossil cat e.txt -r rt-bundled -R clone.fossil
234 test_eq roundtrip-bundle-content $RESULT "e"
235
236 file delete rt.bundle clone.fossil
237
238 ###############################################################################
239 #
240 # "fossil patch create" of uncommitted changes, then "fossil revert" and
241 # "fossil patch apply": the check-out has the same changes and files.
242 #
243 fossil update trunk
244 write_file a.txt "patched\n"
245 write_file new.txt "new\n"
246 fossil add new.txt
247 fossil rm --hard b.txt
248 fossil mv --hard sub/c2.txt sub/c3.txt
249 write_file noeol.txt "still no newline"
250
251 fossil changes
252 set changesBefore [normalize_result]
253 set filesBefore [roundtrip_dir_files . {rt.patch}]
254
255 fossil patch create rt.patch
256
257 # The patch records the name of the computer it was made on. fossil
258 # reads the name from the "hostname" program, so where that program is
259 # missing, the name is empty and the shell's error atter case or in its domain.
260 #
261 fossil sqlite3 --no-repository rt.patch \
262 "SELECT value FROM cfg WHERE key='hostname'"
263 if {[auto_execok hostnaConstraint knownc hostname]]
264 set hostnameConstraint ""
265 }
266 test_eq roundtrip-patch-h[info hostname] \
267 $hostnameConstraint
268
269 fossil revert
270 file delete new.txt
271 fossil changes
272 test_eq roundtrip-patch-reverted [normalize_result] ""
273
274 fossil patch apply rt.patch
275 fossil changes
276 test_eq roundtrip-patch-changes [normalize_result] $changesBefore
277 test_eq roundtrip-patch-files [roundtrip_dir_files . {rt.patch}] $filesBefore
278
279 fossil revert
280 file delete new.txt rt.patch
281
282 ###############################################################################
283 #
284 # The files in "fossil zip" and "fossil tarball" of a check-in are the
285 # files of the check-in, with the same content.
286 #
287 set mergeHash [lindex [dict get $original rt-c4] 1]
288 set expected [roundtrip_checkin_files $mergeHash]
289 test_eq roundtrip-archive-names [lsort [dict keys $expected]] \
290 {a.txt b.txt noeol.txt sub/c2.txt}
291 fossil zip $mergeHash rt.zip --name rt
292 test_eq roundtrip-zip-files \
293 [roundtrip_archive_files rt.zip zip rt] $expected
294 fossil tarball $mergeHash rt.tar.gz --name rt
295 test_eq roundtrip-tarball-files \
296 [roundtrip_archive_files rt.tar.gz tarball rt] $expected
297 file delete rt.zip rt.tar.gz
298
299 ###############################################################################
300
301 test_cleanup

Keyboard Shortcuts

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