Skip to content

Feature: Support quoted arguments #272

@TheodorRene

Description

@TheodorRene

Man page from git-rev-parse:

       [<refname>]@{<date>}, e.g. master@{yesterday}, HEAD@{5 minutes ago}
           A ref followed by the suffix @ with a date specification enclosed in a brace pair (e.g.
           {yesterday}, {1 month 2 weeks 3 days 1 hour 1 second ago} or {1979-02-26 18:30:00})
           specifies the value of the ref at a prior point in time. This suffix may only be used
           immediately following a ref name and the ref must have an existing log
           ($GIT_DIR/logs/<ref>). Note that this looks up the state of your local ref at a given time;
           e.g., what was in your local master branch last week. If you want to look at commits made
           during certain times, see --since and --until.

:DiffviewOpen develop...HEAD@{1 days ago} will not work. From what I gather its because the parsing of symmetric diffs is only based on the first argument of a whitespace split diff.
GitAdapter:rev_parse takes develop...HEAD@{1 since GitAdapter:diffview_options gives it only args[0]. The best would be some custom logic to parse the arguments instead of solely on whitespace. I might have a crack at this over the weekend, I'm just a bit unsure where this should be placed.

It could either be mashed in here, not passing state.fargs, but a list after some custom split logic:

-- diffview.lua
command("DiffviewOpen", function(state)
    print(vim.inspect(state))
  diffview.open(unpack(state.fargs))
end, { nargs = "*", complete = completion })

or here:

-- git/init.lua
function GitAdapter:diffview_options(args)
  local default_args = config.get_config().default_args.DiffviewOpen
  local argo = arg_parser.parse(vim.tbl_flatten({ default_args, args }))
  local rev_arg = argo.args[1]

  local left, right = self:parse_revs(rev_arg, {
    cached = argo:get_flag({ "cached", "staged" }),
    imply_local = argo:get_flag("imply-local"),
  })

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions