Bugzilla – Attachment 187545 Details for
Bug 6473
Test bug for Git-bz ✔ ❤ ★
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[#1] Fix attachment upload order
0b87b3f.patch (text/plain), 6.29 KB, created by
Tomás Cohen Arazi (tcohen)
on 2025-10-07 19:07:00 UTC
(
hide
)
Description:
[#1] Fix attachment upload order
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2025-10-07 19:07:00 UTC
Size:
6.29 KB
patch
obsolete
>From 0b87b3f4ac7498d17a3fee573e386465160d7aff Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Tom=C3=A1s=20Cohen=20Arazi?= <tomascohen@theke.io> >Date: Tue, 7 Oct 2025 15:58:10 -0300 >Subject: [PATCH] [#1] Fix attachment upload order >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >Attachments were being uploaded in reverse chronological order (newest first), >which breaks sequential patch application. Added --reverse flag to git rev-list >to ensure commits are returned in chronological order (oldest first). > >- GitBz::Git->rev_list(): Add --reverse flag for chronological ordering >- t/attach_order.t: Test demonstrating issue and expected behavior > >Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io> >--- > lib/GitBz/Git.pm | 3 +- > t/attach_order.t | 143 +++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 145 insertions(+), 1 deletion(-) > create mode 100755 t/attach_order.t > >diff --git a/lib/GitBz/Git.pm b/lib/GitBz/Git.pm >index d87cff3..67a7e18 100644 >--- a/lib/GitBz/Git.pm >+++ b/lib/GitBz/Git.pm >@@ -82,8 +82,9 @@ sub rev_list { > my ( $class, @args ) = @_; > > unshift( @args, '--pretty=format:%s' ); >+ unshift( @args, '--reverse' ); # Add --reverse to get chronological order (oldest first) > unshift( @args, '--max-count=1' ) >- if $args[1] eq 'HEAD'; >+ if $args[2] eq 'HEAD'; # Adjust index due to --reverse insertion > > my $output = $class->run( 'rev-list', @args ); > >diff --git a/t/attach_order.t b/t/attach_order.t >new file mode 100755 >index 0000000..7d82304 >--- /dev/null >+++ b/t/attach_order.t >@@ -0,0 +1,143 @@ >+#!/usr/bin/perl >+ >+use Modern::Perl; >+use Test::More; >+use FindBin; >+use lib "$FindBin::Bin/../lib"; >+ >+=head1 NAME >+ >+t/attach_order.t - Test that attachments are uploaded in correct chronological order >+ >+=head1 DESCRIPTION >+ >+Tests that when attaching multiple commits, they are uploaded in chronological >+order (oldest first) so they can be applied correctly later. >+ >+=cut >+ >+# Simple mock for testing without external dependencies >+{ >+ package MockBug; >+ sub new { >+ my ($class, %args) = @_; >+ bless { %args, _attachments => [] }, $class; >+ } >+ sub id { $_[0]->{id} } >+ sub summary { $_[0]->{summary} } >+ sub status { $_[0]->{status} } >+ sub attachments { $_[0]->{_attachments} } >+ sub add_attachment { >+ my ($self, $patch, $filename, $description, %opts) = @_; >+ push @{$self->{_attachment_order}}, $description; >+ return 1; >+ } >+} >+ >+{ >+ package MockCommands; >+ sub new { >+ my ($class, %args) = @_; >+ bless \%args, $class; >+ } >+} >+ >+subtest 'current behavior - attachments uploaded in reverse chronological order' => sub { >+ plan tests => 4; >+ >+ # Track attachment order >+ my @attachment_order; >+ >+ # Create mock bug that captures attachment order >+ my $bug = MockBug->new( >+ id => 12345, >+ summary => 'Test bug', >+ status => 'NEW', >+ _attachment_order => \@attachment_order >+ ); >+ >+ # Simulate current GitBz::Git->get_commits behavior (reverse chronological) >+ my @commits = ( >+ { id => 'abc123', subject => 'Third commit (newest)' }, >+ { id => 'def456', subject => 'Second commit (middle)' }, >+ { id => 'ghi789', subject => 'First commit (oldest)' }, >+ ); >+ >+ # Simulate current attach_patches behavior >+ for my $commit (@commits) { >+ $bug->add_attachment( >+ "patch content", >+ $commit->{id} . ".patch", >+ $commit->{subject} >+ ); >+ } >+ >+ # Verify current (wrong) behavior >+ is(scalar @attachment_order, 3, 'Three attachments were created'); >+ is($attachment_order[0], 'Third commit (newest)', 'First attachment is newest commit (WRONG)'); >+ is($attachment_order[1], 'Second commit (middle)', 'Second attachment is middle commit'); >+ is($attachment_order[2], 'First commit (oldest)', 'Third attachment is oldest commit (WRONG)'); >+ >+ note("CURRENT BEHAVIOR (BROKEN): " . join(' -> ', @attachment_order)); >+ note("This is backwards! Patches should be applied oldest-first for correct git apply sequence."); >+}; >+ >+subtest 'expected correct behavior - chronological order' => sub { >+ plan tests => 4; >+ >+ my @attachment_order; >+ my $bug = MockBug->new( >+ id => 12345, >+ summary => 'Test bug', >+ status => 'NEW', >+ _attachment_order => \@attachment_order >+ ); >+ >+ # What the corrected behavior should return (chronological order) >+ my @commits = ( >+ { id => 'ghi789', subject => 'First commit (oldest)' }, >+ { id => 'def456', subject => 'Second commit (middle)' }, >+ { id => 'abc123', subject => 'Third commit (newest)' }, >+ ); >+ >+ # Simulate corrected attach_patches behavior >+ for my $commit (@commits) { >+ $bug->add_attachment( >+ "patch content", >+ $commit->{id} . ".patch", >+ $commit->{subject} >+ ); >+ } >+ >+ # Verify correct behavior >+ is(scalar @attachment_order, 3, 'Three attachments were created'); >+ is($attachment_order[0], 'First commit (oldest)', 'First attachment is oldest commit (CORRECT)'); >+ is($attachment_order[1], 'Second commit (middle)', 'Second attachment is middle commit'); >+ is($attachment_order[2], 'Third commit (newest)', 'Third attachment is newest commit (CORRECT)'); >+ >+ note("EXPECTED BEHAVIOR (CORRECT): " . join(' -> ', @attachment_order)); >+ note("This is the correct order for sequential git apply."); >+}; >+ >+subtest 'git rev-list default behavior analysis' => sub { >+ plan tests => 1; >+ >+ # Document the root cause: git rev-list returns newest-first by default >+ my $explanation = <<'EOF'; >+ROOT CAUSE ANALYSIS: >+- git rev-list returns commits in reverse chronological order (newest first) >+- GitBz::Git->get_commits() uses git rev-list without --reverse flag >+- attach_patches() processes commits in the order returned by get_commits() >+- Result: attachments are uploaded newest-first (backwards for applying) >+ >+SOLUTION: >+- Add --reverse flag to git rev-list in GitBz::Git->rev_list() >+- This will return commits in chronological order (oldest first) >+- Attachments will then be uploaded in correct sequence for git apply >+EOF >+ >+ pass("Analysis documented"); >+ note($explanation); >+}; >+ >+done_testing(); >-- >2.51.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 6473
:
4386
|
6837
|
6838
|
6839
|
6840
|
6841
|
6842
|
6843
|
7154
|
7155
|
7567
|
7994
|
7995
|
7996
|
7997
|
8018
|
9807
|
9808
|
9813
|
9831
|
9832
|
9836
|
9854
|
10842
|
10843
|
10844
|
10845
|
10846
|
10847
|
10848
|
10849
|
10850
|
10851
|
10852
|
10853
|
10854
|
10855
|
10856
|
10857
|
10858
|
11540
|
11543
|
11544
|
12502
|
12513
|
12514
|
12515
|
12516
|
12517
|
12518
|
12519
|
13473
|
13673
|
14955
|
14969
|
14970
|
14972
|
15201
|
18949
|
18950
|
18951
|
18952
|
18953
|
18954
|
18955
|
18956
|
18957
|
18958
|
18959
|
18960
|
18961
|
18962
|
18963
|
18971
|
18972
|
19518
|
19519
|
19591
|
19592
|
19871
|
19879
|
19880
|
19881
|
19882
|
20011
|
20012
|
20013
|
20014
|
22477
|
22481
|
22482
|
22496
|
22502
|
22503
|
31958
|
32444
|
32445
|
32446
|
32447
|
32448
|
32449
|
32450
|
32451
|
32452
|
34200
|
34201
|
34625
|
34999
|
35130
|
35269
|
35273
|
35274
|
35275
|
35276
|
35277
|
35279
|
35280
|
35303
|
40954
|
40957
|
45345
|
45349
|
45731
|
45732
|
45733
|
45734
|
47283
|
47284
|
47298
|
47299
|
47300
|
47334
|
47336
|
49083
|
56974
|
61059
|
61069
|
62038
|
65313
|
77301
|
78016
|
79959
|
80178
|
80179
|
80180
|
80181
|
80182
|
84400
|
86644
|
86645
|
87152
|
88128
|
95586
|
95716
|
97394
|
99026
|
99027
|
114217
|
114218
|
114219
|
114220
|
114221
|
114222
|
114223
|
114224
|
114225
|
114226
|
119255
|
121181
|
131891
|
131893
|
131894
|
134862
|
144109
|
144144
|
144671
|
144672
|
144673
|
147183
|
149030
|
149031
|
149032
|
149033
|
160566
|
160567
|
160568
|
182093
|
183107
|
183177
|
183178
|
183179
|
183180
|
183182
|
183183
|
183285
|
183286
|
187209
|
187321
|
187322
|
187323
|
187324
|
187325
|
187326
|
187327
|
187328
|
187329
|
187330
|
187331
|
187332
|
187333
|
187334
|
187335
|
187336
|
187337
|
187338
|
187339
|
187340
|
187341
|
187342
|
187343
|
187344
|
187345
|
187346
|
187347
|
187348
|
187349
|
187350
|
187351
|
187352
|
187353
|
187354
|
187355
|
187356
|
187357
|
187358
|
187359
|
187360
|
187361
|
187362
|
187363
|
187364
|
187365
|
187366
|
187367
|
187368
|
187369
|
187370
|
187371
|
187372
| 187545 |
187546