Skip to content

Commit a19b98f

Browse files
committed
Support for base-commit in patch files
Previously the script always tried to resolve indexes, with this it alsos upports the base-commit mention often used in postgres patches.
1 parent 97ebf58 commit a19b98f

2 files changed

Lines changed: 31 additions & 4 deletions

File tree

public/scripts/hackorum-patch

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,12 +396,21 @@ class HackorumPatch
396396
return @options[:base_commit]
397397
end
398398

399+
patch_files = Dir.glob(File.join(patch_files_dir, "*.patch")).sort
400+
return detect_default_branch_head if patch_files.empty?
401+
402+
# First, check for base-commit line (from git format-patch --base)
403+
base_commit = detect_base_commit_from_base_line(patch_files)
404+
if base_commit
405+
puts "[OK] Base commit: #{base_commit} (from base-commit line)"
406+
puts ""
407+
return base_commit
408+
end
409+
410+
# Fall back to index hash detection
399411
puts "Detecting base commit from patch index entries..."
400412

401-
patch_files = Dir.glob(File.join(patch_files_dir, "*.patch")).sort
402413
first_patch = patch_files.first
403-
return detect_default_branch_head unless first_patch
404-
405414
index_hashes = []
406415
new_file_count = 0
407416
content = File.read(first_patch)
@@ -445,6 +454,21 @@ class HackorumPatch
445454
base_commit
446455
end
447456

457+
def detect_base_commit_from_base_line(patch_files)
458+
files_to_check = [patch_files.first, patch_files.last].uniq
459+
460+
files_to_check.each do |patch_file|
461+
content = File.read(patch_file)
462+
if content =~ /^base-commit:\s*([0-9a-f]{40})\s*$/
463+
base_commit = $1
464+
puts "Found base-commit line in #{File.basename(patch_file)}: #{base_commit[0..11]}..."
465+
return base_commit
466+
end
467+
end
468+
469+
nil
470+
end
471+
448472
def detect_default_branch_head
449473
%w[origin/master master].each do |ref|
450474
if system("git rev-parse --verify #{ref} > /dev/null 2>&1")

public/scripts/hackorum-patch.changelog.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
{
55
"version": "1.1.0",
66
"date": "2026-01-21",
7-
"changes": ["Added version check to notify users of updates"]
7+
"changes": [
8+
"Added version check to notify users of updates",
9+
"Added support for base-commit line from git format-patch --base"
10+
]
811
},
912
{
1013
"version": "1.0.0",

0 commit comments

Comments
 (0)