Skip to content

How to use GitClientBase.get_commit_diffs method (v4_0) #70

Closed

Description

@WladdGorshenin

I'm trying to use GitClientBase.get_commit_diffs method (v4_0) as follows:

diifs=git_client.get_commit_diffs(
    repository_id=repo_id, 
    project=proj_id,
    diff_common_commit=None,
    top=None, 
    skip=None, 
    base_version_descriptor=GitBaseVersionDescriptor(version=src_commit_id), 
    target_version_descriptor=GitTargetVersionDescriptor(version=dst_commit_id)
)

I specify repository_id, project_id and IDs for two commits from the repository. But the method returns something different which looks like a recent commit in the repo.

What I do wrong?

Activity

  1. tedchamb commented on May 18, 2018

    @tedchamb
    Member

    The python api is a thin wrapper around our REST APIs. Take a look at our REST documentation here on this particular API which has a few examples.

    https://docs.microsoft.com/en-us/rest/api/vsts/git/diffs/get?view=vsts-rest-4.1

    If this doesn't clear things up, enable logging by doing the following:

    `import logging

    logging.basicConfig(level=logging.DEBUG)`

    Then send us the request/response of the command, after scrubbing any personal data.

  2. WladdGorshenin commented on May 30, 2018

    @WladdGorshenin
    Author

    Hi Ted,

    I'm coming back to the question. Here is the scrubbed debug information:

    DEBUG:root:Route template: {project}/_apis/{area}/repositories/{repositoryId}/diffs/commits
    DEBUG:msrest.pipeline:Configuring request: timeout=100, verify=True, cert=None
    DEBUG:msrest.pipeline:Configuring proxies: ''
    DEBUG:msrest.pipeline:Evaluate proxies against ENV settings: True
    DEBUG:msrest.pipeline:Configuring redirects: allow=True, max=30
    DEBUG:msrest.pipeline:Configuring retry: max_retries=3, backoff_factor=0.8, max_backoff=90
    DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): xxxxxxx.visualstudio.com
    DEBUG:urllib3.connectionpool:https://xxxxxxx.visualstudio.com:443 "GET /xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/_apis/git/repositories/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/diffs/commits?diffCommonCommit=false&$top=2&$skip=0&baseVersionDescriptor.baseVersionType=commit&baseVersionDescriptor.baseVersion=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&targetVersionDescriptor.targetVersionType=commit&targetVersionDescriptor.targetVersion=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx HTTP/1.1" 200 254
    

    and scrubbed response:

    {'ahead_count': 0,
     'all_changes_included': True,
     'base_commit': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
     'behind_count': 0,
     'change_counts': {},
     'changes': [],
     'common_commit': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
     'target_commit': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'}
    

    It seems something is wrong with VSTS API.

  3. jianges commented on May 30, 2018

    @jianges

    Hi,
    I'm sorry that our rest api doc isn't super clear. While you specify a commit as a version descriptor, you would also need to specify the version type. e.g.:
    https://jianges.visualstudio.com/myProject/_apis/git/repositories/718efd9e-6ca0-42de-9df1-a35035c14b4c/diffs/commits?baseVersionType=commit&baseVersion=4081f4d0a3219d4d9bd8ee6cf444f16320d4e573&targetVersionType=commit&targetVersion=46f39e2e222eeb5104351f149902aec2137b2d8d&api-version=4.1-preview

    Please notice both baseVersionType=commit and targetVersionType=commit query parameters are required since both baseVersion and targetVersion points to commitIds.

    Thanks,
    Jiange

  4. tedchamb commented on May 30, 2018

    @tedchamb
    Member

    The issue has been identified and we are working on a fix.

  5. WladdGorshenin commented on May 31, 2018

    @WladdGorshenin
    Author

    Hi JIANGE SUN (@jianges), thank you for the note. I tried your link but got 401 error. Probably there is some authorization issue.

  6. jianges commented on May 31, 2018

    @jianges

    You won't have permission to access my personal vsts account. But you can try it on your own vsts account by following the same url format and it should work.
    BTW, commit diff rest api should fail with meaningful error message while neither baseVersion and targetVersion query parameters are provided instead of returning the "empty" diff from your default branch's tip commit. We're working on a fix on that as well.

  7. tedchamb commented on May 31, 2018

    @tedchamb
    Member

    This will be fixed with #73

  8. tedchamb commented on May 31, 2018

    @tedchamb
    Member

    Version 0.1.7 has been published to pypi and has the fix. Thanks for reporting this issue.

    https://github.com/Microsoft/vsts-python-api/releases/tag/0.1.7

  9. tedchamb commented on Jun 1, 2018

    @tedchamb
    Member

    WladdGorshenin I have reopened the issue. Can you repost your new question, with example request/response so we can investigate? Be sure to scrub any personal data.

  10. jianges commented on Jun 1, 2018

    @jianges

    WladdGorshenin I just tried both $skip and $top=2 query parameters and verified they work as expected. The Ahead/Behind counts are the commit counts between base and target commits and they won't be impacted by the bsvskip (@Skip) and Top (@top). bsvskip (@Skip) and Top (@top) will control the list of items returned from the api.
    You won't be able to access this URL but I'm including it here so you can try out something similar on your own account:
    https://jianges.visualstudio.com/myProject/_apis/git/repositories/myRepo/diffs/commits?$skip=1&$top=2&baseVersionType=commit&baseVersion=4081f4d0a3219d4d9bd8ee6cf444f16320d4e573&targetVersionType=commit&targetVersion=46f39e2e222eeb5104351f149902aec2137b2d8d&api-version=4.1-preview

  11. WladdGorshenin commented on Jun 1, 2018

    @WladdGorshenin
    Author

    Hi guys, sorry for the false alarm. Everything works as expected.

  12. WladdGorshenin commented on Jun 1, 2018

    @WladdGorshenin
    Author

    By the way, what would be the best recipe to reproduce 'git diff commitA commitB -- file' results with VSTS? My goal is for each tuple (commit, overlapping_commit, file) find out the number of lines in the file touched by both commits?

  13. tedchamb commented on Jun 1, 2018

    @tedchamb
    Member

    WladdGorshenin I'm glad the api is working for you now. I am going to go ahead close this bug. Since your last question is related to the api itself and not specifically the python library, the best place to ask your question is at the following url. Please submit your question there, and we can make sure someone looks at it.

    https://docs.microsoft.com/en-us/rest/api/vsts/git/diffs?view=vsts-rest-4.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions