Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: More Verbose Auto-Commit Messages #51

Open
dylan-k opened this issue Dec 15, 2022 · 5 comments
Open

Feature Request: More Verbose Auto-Commit Messages #51

dylan-k opened this issue Dec 15, 2022 · 5 comments

Comments

@dylan-k
Copy link

dylan-k commented Dec 15, 2022

There's a different extension out there, which can create more detailed commit messages. Even when squashed, it might help to have these details from something like gitdoc. They more closely resemble the so-called Conventional Commits.

I thought to share it here and request this functionality, as it doesn't seem the two work together very well.

@lostintangent
Copy link
Owner

Apologies for the late reply! I was on vacation for a bit. I think this is a great idea, and I actually already do this for my GistPad extension. Out of curiosity: are you mostly interested in the commit message that includes the impacted file names and operation? Or did you also want to include the conventional commit prefix?

@Aincvy
Copy link

Aincvy commented Jun 27, 2023

I'd like to have the list of changed files. I don't know why, perhaps because Gitlab did it this way.

@vergenzt
Copy link

I'd love this too! FWIW I've written a script to do this in the past using the output of git status --porcelain=v1 -z, and using jq to do the core processing. (I also wrapped this up into a git commit-on-save alias to use fswatch to trigger the commits. This repo already handles that part, but I'll include it below for context.)

Here's the scripts, in case they're helpful for anybody else:

# file: ~/.gitconfig
...
[alias]
	summary = "!git status --porcelain=v1 -z | jq -rR git_summarize_changes"
	commit-on-save = "!set -x; fswatch -l20 -0b . | xargs -0n1 git ls-files -z | xargs -0n1 bash -c 'git add -A && git commit -m \"$(git summary)\" && git push'"
# file: ~/.jq
...

def git_summarize_changes: (
  [
    scan("(?x)
      (?: \\A | \\G )
      (?<index_status> (?<is_rename>[RC]) | [^RC] )
      (?<worktree_status> . )
      [ ]
      (?<path> [^\u0000]+ ) 
      (?(<is_rename>) \u0000 (?<renamed_from> [^\u0000]+ ) )
      (?: \\Z | \u0000 )
    ")
    | . as [$index_status, $_, $__, $path, $renamed_path]
    | {$index_status, $path, $renamed_path}
  ]
  | length as $num_files
  | group_by(.index_status)
  | map(

    # https://git-scm.com/docs/git-status#_short_format
    ({
      "M": "update",
      "A": "add",
      "D": "delete",
      "R": "rename",
      "C": "copy",
      "T": "change type of",
    }[.[0].index_status] // empty)

    + " "
    + (
      if $num_files == 1
      then .[] | .path + (if .renamed_path then " from " + .renamed_path else "" end)
      else "\(length) file" + (if length == 1 then "" else "s" end)
      end
    )
  )
  | if length == 0
    then error("No staged git changes")
    else
      join(", ")
      | (.[0:1] | ascii_upcase) + .[1:]
    end
);

I think I did some manual testing when I first wrote this (the details of which have been lost to time), but hopefully it's a starting point.

@dylan-k
Copy link
Author

dylan-k commented Apr 22, 2024

Or did you also want to include the conventional commit prefix?

A prefix might be nice, yes. Perhaps "auto" is a good prefix to have by default, though.

@lostintangent
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants