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

Filter using git log -L #3543

Open
georgeguimaraes opened this issue May 2, 2024 · 2 comments
Open

Filter using git log -L #3543

georgeguimaraes opened this issue May 2, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@georgeguimaraes
Copy link

git log -L enables us to see the history of commits for the range of lines we pass to it:
https://git-scm.com/docs/git-log#Documentation/git-log.txt--Lltstartgtltendgtltfilegt

I use it with Neovim's visual mode to see how a piece of code changed over time and who made those changes.

As an example, I'm using neogit for it:

      {
        "<leader>gl",
        function()
          local file = vim.fn.expand("%")
          vim.cmd([[execute "normal! \<ESC>"]])
          local line_start = vim.fn.getpos("'<")[2]
          local line_end = vim.fn.getpos("'>")[2]
          require("neogit").action("log", "log_current", { "-L" .. line_start .. "," .. line_end .. ":" .. file })()
        end,
        desc = "Neogit Log for this range",
        mode = "v",
      },

It would be great if I could see it in a lazygit window.

@georgeguimaraes georgeguimaraes added the enhancement New feature or request label May 2, 2024
@stefanhaller
Copy link
Collaborator

I want this too. Currently I use gitk for this, which has it built in; I have a very small VS Code extension which launches gitk and passes it the currently selected line range. This works great for me, but yes, being able to do it in lazygit would be nice.

What I'm unsure about is how we would do this in lazygit. As a neovim user you'd probably want to open a new instance in a new tab or buffer or whatever that's called in neovim; I'm unfamiliar with it, so I can only guess. For users of IDEs such as VS Code it's a lot less clear how to solve this. Personally I don't use VS Code's builtin terminal for lazygit; I usually have lazygit running in a terminal tab (separate application), so I wouldn't want to have a command that creates a new terminal tab and starts a new instance of lazygit there.

So what we'd need is a command-line mode of lazygit where it can talk to running instances of itself, to find ones that have the current repo open; if there is more than one, or none, it's probably ok to just error out. Then tell that instance to show the log for the line range. (We could later use it for other fun things like blaming.)

This wouldn't address the problem that you still have to bring the terminal app to the front, and make it show the right tab, but I suppose we can leave the former to the scripting layer between the IDE and lazygit, and ignore the latter. :)

Or am I misunderstanding something about the feature request?

@georgeguimaraes
Copy link
Author

What I'm unsure about is how we would do this in lazygit. As a neovim user you'd probably want to open a new instance in a new tab or buffer or whatever that's called in neovim

Yes, In Neovim, I'd open a new floating window with lazygit in it with these new options passed in. In fact, I'm using Lazyvim (https://github.com/LazyVim/LazyVim) a distro with a bunch of pre-made configurations for Neovim, that has some integrations already made for lazygit (much lazyness in this paragraph).

In other words, for me (and potential neovim users), we'd need the lazygit cli options to launch a new instance with the commits from git log -Lxx:yy example.lua in it. No need to find running instances.

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

No branches or pull requests

2 participants