0

I'm trying to create a nightly process that will create a list of files changed between the last commit of the previous day and the current HEAD of a branch.

I've been looking at the Stash API, which can be found here:

https://developer.atlassian.com/static/rest/stash/3.11.3/stash-rest.html

It looks like /compare/changes and the /diff would be capable of accomplishing the task, but I can only get them to work for single commit changes.

Is there a way to expand it so I can get all the names of files changed between multiple commits?

Ex: All files between commit1 through commit10?

double-beep
  • 5,031
  • 17
  • 33
  • 41

4 Answers4

2

How about this:

https://stash.domain.com/rest/api/latest/projects/{project}/repos/{repository}/changes?since={commit_1}&until=${commit_10}
0

You can give SHA for both the commits involved to the git diff command:

git diff --name-only SHA1 SHA2 

This post provides details on using .. and ... to get the set you might be looking for (if you go for that format - using dot for diff between commits)

Note: --name-only : Show only names of changed files.

Community
  • 1
  • 1
nitishagar
  • 9,038
  • 3
  • 28
  • 40
0

I only glanced at this briefly (and they have some odd terminology, calling these "changesets" instead of "commit" IDs: that would make sense for Mercurial, but not for Git) but the API does take two IDs and this is all you need.

For instance, in your example, you want to see what happened

between commit1 through commit10

The word "between" is a bit suspect (because commits are not necessarily linear in the first place, and because it introduces fencepost errors) but in general, to do this, you just compare (the ID of) commit1 (or its parent, depending on whether you are counting fence posts or fence rails) against (the ID of) commit10.

When doing this with Git, rather than over some annoying REST API, it is expressed as, e.g.:

$ git diff --name-status 1fe9ca7 6631bed

which shows you everything changed in 6631bed vs whatever was in 1fe9ca7, which—due to the algebra of changesets—is the sum of each changeset "between" (there is that slippery word again) the two end points.

Git does not store these changesets; it stores the actual content at each commit. The changesets are therefore produced on demand (by git diff), which is why their terminology seems a bit odd. You identify two actual commits, not a changeset, and git then extracts a changeset.

torek
  • 448,244
  • 59
  • 642
  • 775
0

I think following should work:

  • Let's assume the last commit hash was: abcdefg
  • The branch name is develop, whose head is to be compared with

Following curl request can give you the diff:

curl -s -H "Content-Type: application/json" http(s)://rest/api/1.0/projects/project-key/repos/repo-slug/compare/changes?from=refs/heads/develop&to=abcdefg&limit=1000

Notes:

  • The "limit" param has been added so that this can show till 1000 record. Default pagesize is 25.
  • "jq" is a json parser utility that can be used optionally to parse the response.
    For example, I "pipe" the response of the above curl to following to just get the filenames that have been changed:

    jq '.values|.[]|.path|.toString'

Arnab
  • 1,308
  • 1
  • 13
  • 18