Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning more information in FetchResult #823

Closed
compnski opened this issue Jul 12, 2022 · 2 comments · Fixed by #832
Closed

Returning more information in FetchResult #823

compnski opened this issue Jul 12, 2022 · 2 comments · Fixed by #832
Labels
enhancement more-info-needed More information is required in order to investigate

Comments

@compnski
Copy link

What are your thoughts on adding more information to FetchResult?

I'd like to know the updated branches and especially deleted branches.

Currently I can get this via outputHandler(), but it's messy since I can't return a result through.

Are you open to a PR that adds these fields? Are they deliberately elided (or non-standard between servers)?

Possible format for FetchResult

export interface FetchResult {
  raw: string
  remote: string | null
  branches: {
    name: string
    tracking: string
  }[]
  tags: {
    name: string
    tracking: string
  }[]
  updated: {
    name: string
    tracking: string
    to: string
    from: string
  }[]
  deleted: {
    tracking: string
  }[]
}

LineParsers

  new LineParser(/- \[deleted]\s+\S+\s*-> (.+)$/, (result, [tracking]) => {
    result.deleted.push({
      tracking,
    })
  }),
  new LineParser(/\s*([^.]+)\.\.(\S+)\s+(\S+)\s*-> (.+)$/, (result, [to, from, name, tracking]) => {
    result.updated.push({
      name,
      tracking,
      to,
      from,
    })
  }),
@steveukx steveukx changed the title Returning more information in ResultResult Returning more information in FetchResult Jul 12, 2022
@steveukx
Copy link
Owner

Hi, as the changes are additive this would be welcomed as a PR.

To help you create the PR - this is a stub of an integration for you that sets up a remote repo with local clone, modifies the remote then fetches those changes in the local.

// ./simple-git/test/integration/fetch.spec.ts

import { createTestContext, newSimpleGit, setUpInit, SimpleGitTestContext } from '../__fixtures__';

describe('fetch', () => {
   let context: SimpleGitTestContext;
   let upstream: string;
   let local: string;

   beforeEach(async () => context = await createTestContext());
   beforeEach(async () => {
      upstream = await context.dir('upstream');
      local = context.path('local');
      await context.file(['upstream', 'file']);

      await givenRemote(upstream);
      await givenLocal(upstream, local);
   });

   it('fetches updates', async () => {
      await givenRemoteChanges(upstream);
      const result = await newSimpleGit(local).fetch();

      expect(result).toEqual( ... );
   })

   /**
    * Sets up the repo to be used as a local - by cloning the remote
    */
   async function givenLocal(upstream: string, local: string) {
      await newSimpleGit(context.root).clone(upstream, local);
      await setUpInit({git: newSimpleGit(local)});
   }

   /**
    * Sets up the repo to be used as a remote
    */
   async function givenRemote(upstream: string) {
      const git = newSimpleGit(upstream);
      await setUpInit({git});
      await git.add('.');
      await git.commit('first');
   }

   /**
    * Configure the remote with changes to be retrieved when using fetch on the local
    */
   async function givenRemoteChanges(upstream: string) {
      const git = newSimpleGit(upstream);
      await git.raw('tag', 'alpha');
      await git.raw('checkout', '-b', 'bravo');
      await context.file(['upstream', 'another-file']);
      await git.add('.');
      await git.commit('second');
   }
})

@steveukx steveukx added enhancement more-info-needed More information is required in order to investigate labels Jul 13, 2022
@compnski
Copy link
Author

compnski commented Jul 18, 2022

Thanks! The skeleton integration test was extremely helpful. I like the fixtures you've got set up.

PR: #827

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement more-info-needed More information is required in order to investigate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants