On Tue, Apr 9, 2013 at 6:05 PM, Tommaso Cucinotta <tomm...@lyx.org> wrote:
> Ok, really really wanting to use git status --porcelain, we can go for the 
> following (but I hate it).
> Let me write it in shell code:

I guess I can't get you to give up on this :(

:)

So, to find out if a path is in a workspace:

        git rev-parse --show-toplevel 2>/dev/null

The exit status will be 128 if $PWD is not in a workspace, else it
will be 0.  The top-level directory will be output to stdout.

> gitout=$(git-status --porcelain $file)"

This will exit(128) if not in a workspace and will write nothing to
stdout.  Else it will write something to stdout.

But note!  The CWD of git needs to be in the workspace where $file
might be, so what you want is something more like:

if [[ "$file" = /* ]]; then
  file_dirname=${file%/*}
elif [[ "$file" = */* ]]; then
  file_dirname=$PWD/${file%/*}
else
  file_dirname=$PWD
fi
gitout=$(cd "$file_dirname" && git status --porcelain ${file##*/}"")


> if  [ -f $file ]; then
>   if [ "$gitout" == "" ]; then
>     // ON REPO

Let's get the terminology right.  This means we're not in a workspace.

In git we have three things that might matter to LyX:

 - the workspace (that's where the files are checked out and editable,
though we don't say that files are checked out)

 - the "index" (which may have pre-staged changes from the workspace,
allowing the user to accumulate more non-staged changes in the
workspace -- an incredibly useful feature!)

 - a repo, which is what's found in the .git directory, and what remotes are.

The moment a file is in the index or in the local repo we say it's "tracked".

There may be many remote repos.  We don't generally care whether a
given file is in some remote -- we only care whether we have an
untracked file, or whether we have changes to a "tracked" file, and
whether those changes are staged or not.

> But again, git ls-files seems WAY EASIER.

This will tell you if a file is tracked, not whether it has unstaged
or uncommitted changes.

And like git status it will want its $CWD to be inside a workspace.

So, to wrap up, I think you want:

    fork(), chdir() to the directory containing the file, exec() git
status --porcelain, and parse the result in the parent process (read
via a pipe), then display the status (for each file making up a LyX
document).

Nico
--

Reply via email to