How can I create all possible git status?

Background:

We are currently using git for version control in the web application I'm working on. There is an editor, so there is also a web interface for git.

One of our use cases is that people can also control git repositories from the command line, so the web interface should be able to somehow handle any strange state in which it finds the repository.

Question:

For testing, it would be great to get the git repository with the file in any possible state, so I could check if all possible conditions are being processed. Reading "man git -status (1)" I calculated the possible 24 states (not counting the ignored ones) that the file might be.

I just figured out how to create 17 of these states.

Here are the XY codes (see git-status ) from states that I don't know how to reproduce.

D           M    deleted from index
C        [ MD]   copied in index
D           D    unmerged, both deleted
A           U    unmerged, added by us
U           A    unmerged, added by them

There is a gist on github with a ruby ​​script that creates every state that I already know how to reproduce, I would like to do what is completed.

+4
source share
2 answers

What is it worth, based on the source, there is no way to get "copied to the index" today:

wt-status.c:            status = d->index_status;
wt-status.c:            if (!d->index_status)
wt-status.c:                    d->index_status = p->status;
wt-status.c:                    d->index_status = DIFF_STATUS_UNMERGED;
wt-status.c:                    d->index_status = DIFF_STATUS_ADDED;
wt-status.c:            if (!d->index_status ||
wt-status.c:                d->index_status == DIFF_STATUS_UNMERGED)
wt-status.c:    if (d->index_status)
wt-status.c:            color_fprintf(s->fp, color(WT_STATUS_UPDATED, s), "%c", 
wt-status.h:    int index_status;

( index_status - , ). , U A, p->status p->status. :

static void wt_status_collect_changes_index(struct wt_status *s)
{
        struct rev_info rev;
        struct setup_revision_opt opt;

        init_revisions(&rev, NULL);
        memset(&opt, 0, sizeof(opt));
        opt.def = s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference;
        setup_revisions(0, NULL, &rev, &opt);

        if (s->ignore_submodule_arg) {
                DIFF_OPT_SET(&rev.diffopt, OVERRIDE_SUBMODULE_CONFIG);
                handle_ignore_submodules_arg(&rev.diffopt, s->ignore_submodule_arg);
        }

        rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
        rev.diffopt.format_callback = wt_status_collect_updated_cb;
        rev.diffopt.format_callback_data = s;
        rev.diffopt.detect_rename = 1;
        rev.diffopt.rename_limit = 200;
        rev.diffopt.break_opt = 0;
        copy_pathspec(&rev.prune_data, &s->pathspec);
        run_diff_index(&rev, 1);
}

diff : detect_rename DIFF_DETECT_RENAME (1 - #define, ) 200. detect_rename DIFF_DETECT_COPY (2), C.

, wt-status.c (. ), :

$ git status --short
 M wt-status.c
$ git mv zlib.c zzy.c; cp zzy.c zzz.c; git add zzz.c; git status --short
 M wt-status.c
R  zlib.c -> zzy.c
A  zzz.c
$ ./git-status --short
 M wt-status.c
C  zlib.c -> zzy.c
R  zlib.c -> zzz.c

, --find-copies-harder - , , :

$ git mv zzy.c zlib.c; ./git-status --short
 M wt-status.c
A  zzz.c

, DIFF_OPT_SET:

$ git diff
diff --git a/wt-status.c b/wt-status.c
index 4e55810..06310e3 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -494,7 +494,8 @@ static void wt_status_collect_changes_index(struct wt_status
        rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
        rev.diffopt.format_callback = wt_status_collect_updated_cb;
        rev.diffopt.format_callback_data = s;
-       rev.diffopt.detect_rename = 1;
+       rev.diffopt.detect_rename = DIFF_DETECT_COPY;
+       DIFF_OPT_SET(&rev.diffopt, FIND_COPIES_HARDER);
        rev.diffopt.rename_limit = 200;
        rev.diffopt.break_opt = 0;
        copy_pathspec(&rev.prune_data, &s->pathspec);
$ ./git-status --short
 M wt-status.c
C  zlib.c -> zzz.c

, , : -)

+2

git, , , @torek, , stackoverflow.

git , : , @torek, , , git.

+2

Source: https://habr.com/ru/post/1534497/