arxanas / git-branchless

High-velocity, monorepo-scale workflow for Git
Apache License 2.0
3.37k stars 80 forks source link

`--color` option does not always work #1308

Open benoit-pierre opened 1 month ago

benoit-pierre commented 1 month ago

Description of the bug

▸ git sl --color always | cat
# → no colors…

▸ git branchless smartlog --color always | cat
# → no colors…

▸ git branchless --color always smartlog | cat
# → colors!

Expected behavior

Colors in all 3 cases, no matter the position of the --color xxx option in the command line.

Actual behavior

Inconsistent behavior.

Version of rustc

rustc 1.75.0 (82e1608df 2023-12-21)

Automated bug report

No response

Version of git-branchless

git-branchless-opts 0.8.0

Version of git

git version 2.45.0

arxanas commented 1 month ago

Hi @benoit-pierre! I hope you're doing well. It's been a while since we corresponded on Plover-related stuff!

Unfortunately, I think this feature never worked as intended: https://github.com/arxanas/git-branchless/pull/512. It seems like that PR caused the flag to be accepted in all positions, but, for whatever reason, the actual value is only processed in some positions. I see this note in the documentation now:

NOTE: Global arguments only propagate down, not up (to parent commands), however their values once a user uses them will be propagated back up to parents. In effect, this means one should define all global arguments at the top level, however it doesn’t matter where the user uses the global argument.

That being said, it might also be a misuse of the way that we parse global options while ignoring errors.

I don't know what the best solution is in this case —

mfulbright commented 1 month ago

Hi - new git-branchless user here. I just wanted to say I was trying to figure out how to set up a pager for 'smartlog' output, while also keeping the color, and had no idea at all why it wasn't working. Every variation of git sl --color=always | less -R I tried was not maintaining the colors. Thank you very much Benoit! git branchless --color=always smartlo | less -R is working for me now.

(As an aside - are the rest of git-branchless users not piping smartlog output to a pager? Or they are, and just aren't having colored output? I can barely imagine living like that!)

talios commented 1 month ago

On 27 May 2024 at 2:57:46 PM, Mark Fulbright @.***> wrote:

(As an aside - are the rest of git-branchless users not piping smartlog output to a pager? Or they are, and just aren't having colored output? I can barely imagine living like that!)

Your smartlog is LONG enough to NEED a pager? That sounds like a no-merge smell….

-- "Great artists are extremely selfish and arrogant things" — Steven Wilson, Porcupine Tree

arxanas commented 1 month ago

I've also started seeing some applications permit global options only at the top-level, before any subcommands, which doesn't seem wholly unreasonable to me.

This wouldn't work for most cases of aliases, namely git sl --color=XXX, so probably not a good option here.