diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2026-04-17 17:34:24 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2026-04-17 17:34:24 +0800 |
| commit | 1d8f6ad42cb51cfb8ba8b430b0df93d1769237d0 (patch) | |
| tree | 7b4def4984762ede4dc41633bb10087d051612c5 | |
| parent | d59e107305060b844ef3098774be85566456306d (diff) | |
| download | cvn-1d8f6ad42cb51cfb8ba8b430b0df93d1769237d0.tar.gz | |
Launch editor.
| -rw-r--r-- | vcx | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -139,6 +139,9 @@ sub run_add { sub run_commit { my ($msg) = @_; + if (!defined $msg || $msg eq "") { + $msg = get_commit_message(); + } my $parent_id = read_head() // to_hex_id(0); my $parent_tree_hash = ""; @@ -603,3 +606,37 @@ sub read_head { chomp $val if $val; return $val; } + +sub read_file { + my ($path) = @_; + return "" unless -e $path; + open my $fh, '<:raw', $path or return ""; + my $content = do { local $/; <$fh> }; + close $fh; + return $content; +} + +sub get_commit_message { + my $editor = $ENV{VISUAL} || $ENV{EDITOR} || 'vi'; + my $tmp_file = File::Spec->catfile(TMP_DIR, "COMMIT_EDITMSG"); + my $template = <<"EOF"; + +# Please enter the commit message for your changes. Lines starting +# with '#' will be ignored, and an empty message aborts the commit. +# +# On revision: @{[read_head() // '0']} +EOF + + write_file($tmp_file, $template); + + system($editor, $tmp_file); + my $raw_content = read_file($tmp_file); + my @lines = split(/\n/, $raw_content); + + # Filter out lines starting with # + my $final_msg = join("\n", grep { $_ !~ /^\s*#/ } @lines); + $final_msg =~ s/^\s+|\s+$//g; # Trim whitespace + + unlink($tmp_file); + return ($final_msg ne "") ? $final_msg : undef; +} |
