views:

123

answers:

3

My version number looks like 0.1.3 and has two components:

  • 0.1 (the tag)
  • 3 (commits after tag)

All this information easy to obtain from git describe --tags.

For version 0.1.3 git describe may look like

0.1-3-g53d4dec

All of this works fine, but I'm looking for the number of commits affecting only a given subtree, not the whole repo. I don't want to change the version number if something within examples/ or test/ changed, but I do if something within src/ changed.

Basically, I'm looking for git describe --relative src/ that works along the same lines as git log --relative.

+2  A: 

It sounds like the easiest thing to do would be to write a short script - call git-describe to determine what tag you're basing off of, then do something like git log --pretty=%H $tag.. -- $path | wc -l to count the commits.

Jefromi
This do not work correctly. I've added example into the question.
NV
Change `$tag` to `$tag..` to exclude everything contained in the tag. Otherwise it is used as the starting point instead of the stopping point (you probably want to start at HEAD and work back, up to (but not including) `$tag`).
Chris Johnsen
Sorry about the typo. And yes, as Chris suggests, rev-list is slightly smoother than log with the pretty stuff suppressed. You do still need the describe to determine what tag is, of course.
Jefromi
+1  A: 

I came up this this:

git log $tag.. --pretty=%h --relative $path | wc -l

Or even simpler:

git log --oneline $tag.. -- $path | wc -l

Thanks guys from irc://irc.freenode.net/git

I've tested:

git init
Initialized empty Git repository in /private/tmp/test/.git/
$ touch a
$ git add a
$ git commit -m 'first'
[master (root-commit) f8529fc] f
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 a
$ git tag -m 'F' v0.1
$ git tag
v0.1
$ mkdir src
$ touch src/b
$ git add src/b
$ git commit
[master a5345cd] B
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 src/b
$ git log --oneline $tag.. -- $path | wc -l
       1

1 commit after last tag within src/. That's right.

NV
Right, the important part is `v0.1..`, which is the same as `v0.1..HEAD`, which is the same as `^v0.1 HEAD`, which is the same as `--not v0.1 HEAD`. They all mean everything reachable by HEAD, but not reachable from v0.1. See “SPECIFYING REVISIONS” in git-rev-parse(1) http://www.kernel.org/pub/software/scm/git/docs/git-rev-parse.html
Chris Johnsen
+1  A: 

If you are scripting Git, you should really use the “plumbing” commands instead of the “porcelain” commands (see git(1). In this case, the most likely candidate seems like git rev-list.

git rev-list --full-history v0.1.. -- src | wc -l
Chris Johnsen