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

git status --porcelain is actually good for larger repositories #5

Closed
julienw opened this issue Oct 15, 2020 · 1 comment
Closed

git status --porcelain is actually good for larger repositories #5

julienw opened this issue Oct 15, 2020 · 1 comment

Comments

@julienw
Copy link

julienw commented Oct 15, 2020

Hey!
I found your blogpost about checking if your git working directory is dirty in:
https://github.com/remarkablemark/remarkablemark.github.io/blob/master/_posts/2017/2017-10-12-check-git-dirty.md

I can't comment with disqus so I thought I would left this as an issue, I hope you don't mind :-)

At the end you mention --porcelain, stating that it's less efficient for larger repositories. Well that's not been my experience, this is the command I use on very large repositories:

git status --porcelain --ignore-submodules -unormal

I use it as part of a larger "git prompt" command I use in BASH:

function _git_prompt() {
  local branch=`LC_ALL=C git symbolic-ref --short -q HEAD 2>&1`
  if ! [[ "$branch" =~ ot\ a\ git\ repo ]]; then
    if [[ -z "$branch" ]]; then
      # This command doesn't give the most obvious name sometimes
      branch=`LC_ALL=C git describe --all --contains --abbrev=4 HEAD 2> /dev/null`
    fi

    local git_status="`LC_ALL=C git status --porcelain --ignore-submodules -unormal 2>&1`"
    if [[ -z "$git_status" ]]; then
            local ansi=42
        elif [[ ! "$git_status" =~ ?? ]]; then
            local ansi=45
        else
            local ansi=43
        fi
        test "$branch" != master -a "$branch" != main || branch=' '
        echo -n '\[\e[0;37;'"$ansi"';1m\]'"$branch"'\[\e[0m\] '
    fi
}

From my experience this is notably faster than alternatives in very large repositories.

Hope this helps :-)

@remarkablemark
Copy link
Owner

remarkablemark commented Oct 27, 2020

Thank you for the comment @julienw! I'll update the blog post with your findings.

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

2 participants