0

I want to run a script that will run tests on a commit, advance X commits forward, and do the tests again, repeating until it can't go further

How do I take a certain commit I am checked-out on and advance it X commits? X could be 10 or 100.

One way I am thinking of, is to dump all commit hashes to a list, and jump on that list, but I wonder if there is a gittier way to do it

Nick Ginanto
  • 31,090
  • 47
  • 134
  • 244
  • 3
    Sounds similar to `git-bisect` – Jamesking56 Apr 28 '16 at 10:19
  • yea but I want to do it manually not for bug searching, just for static analysis of the code. I don't have a bad or good condition. – Nick Ginanto Apr 28 '16 at 10:20
  • If you start at the tip of the branch, you can go backwards. See http://stackoverflow.com/questions/16062358/referring-to-the-previous-next-commit-in-git You could remember the commits you encounter in a list, then work through that in reverse. Note that commits can have both multiple ancestors and successors, so next and prev are not well defined. – masterxilo Apr 28 '16 at 10:23
  • Still sounds like `git-bisect`; you seem to think that *good* and *bad* are exactly that and it's for debugging, rather they are pointers for *Reference A* and *Reference B*; merely to checkout each commit one-by-one between A and B where you mark good or bad, in your case this is irrelevant you can mark all as "good" let it iterate through for you to run your tests on. – Ash Apr 28 '16 at 10:38

2 Answers2

0

Here's a start:

base=master
cur=10
step=3
while (( $cur >= 0 ))
do 
    git show ${base}~${cur}
    ((cur -= $step))
done

Instead of git show you probably want to checkout and run something.

dimid
  • 7,285
  • 1
  • 46
  • 85
0

Because of branches and merges there isn't necessarily a single "next" or "previous" commit even when you are "between" commits A and B:

                  o - o - o
                /           \
... - A - * - o               o - B
                \           /
                  o ------ o

If you are on node * there is an obvious next/previous commit, the next is the rightward node o and the previous is node A. But after you move forward one, what's the next "next" commit? Should we traverse upwards to the three-node line, or downwards to the two-node line?

git bisect does a lot of tricky stuff to minimize the number of nodes tested while also handling (or trying to handle) these branch-and-merge cases.

Mayvbe you are not looking to test some binary condition. For instance, suppose your static analysis tool is simply generating a bunch of metrics and you want to find out, e.g., that "every N commits / minutes / hours / days, metric A tends to go up somewhat while metric B tends to go down, but during this particular period the trend reversed." In this case you will need to define your own metric for "every N commits" or "every N hours" or whatnot, probably by running git rev-list and working with raw commit IDs from then on.

In general, git rev-list is the tool that handles this, and in fact, git bisect itself uses git rev-list with --bisect (see the documentation for details; note that it stores names in the refs/bisect name space so that it can be used iteratively). The rev-list command has several additional bisect variants that you may find useful.

torek
  • 448,244
  • 59
  • 642
  • 775