summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2026-04-17 17:34:24 +0800
committerSadeep Madurange <sadeep@asciimx.com>2026-04-17 17:34:24 +0800
commit1d8f6ad42cb51cfb8ba8b430b0df93d1769237d0 (patch)
tree7b4def4984762ede4dc41633bb10087d051612c5
parentd59e107305060b844ef3098774be85566456306d (diff)
downloadcvn-1d8f6ad42cb51cfb8ba8b430b0df93d1769237d0.tar.gz
Launch editor.
-rw-r--r--vcx37
1 files changed, 37 insertions, 0 deletions
diff --git a/vcx b/vcx
index b5997f3..f2a9d27 100644
--- a/vcx
+++ b/vcx
@@ -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;
+}