rkotze/git-mob

Allow per repo `<repo>/.git-coauthors` file

tlabeeuw opened this issue · 4 comments

Summary

Instead of only having a global ~/.git-coauthors file, I would like to have a per repo one that can be maintained by the entire team and checked in.

Motivation

This allows us consistancy in maintaining the authors file, and all the advantages of it being tracked by git (history, blame, etc).

Describe alternatives you've considered

Using the env variable GITMOB_COAUTHORS_PATH doesn't work as we work with many repos which belong to different teams.

Additional context

I am willing to submit a PR if that would help. Its an easy enough change. Something to the following file https://github.com/rkotze/git-mob/blob/master/packages/git-mob-core/src/git-mob-api/git-authors/index.js#L107-L111 like:

const { silentRun } = require('../silent-run');

function pathToCoAuthors() {
  if (process.env.GITMOB_COAUTHORS_PATH) {
    return process.env.GITMOB_COAUTHORS_PATH;
  }

  const gitCoAuthorsFilename = process.env.fetch("GITMOB_COAUTHORS_FILENAME", ".git-coauthors");
  const repoAuthorsFile = path.join(gitRootDir(), gitCoAuthorsFilename);

  return fs.existsSync(repoAuthorsFile)
    ? repoAuthorsFile
    : path.join(os.homedir(), gitCoAuthorsFilename);
}

function gitRootDir(gitCoAuthorsFilename) {
  const response = silentRun("git rev-parse --show-toplevel");
  return response.stdout.trim();
}

Obviously the PR would need to add tests and actually cope with errors and such. Also there is a second place that would need to change: https://github.com/rkotze/git-mob/blob/master/packages/git-mob/src/git-authors/index.js#L7-L8.

And don't know if the env var GITMOB_COAUTHORS_FILENAME is really necessary. Maybe requires too many changes since this is hard coded all over the place.

Hi @tlabeeuw

I like the idea of having a local .git-coauthors file overriding the global co-authors.

I don't think there is a need to provide an env var to change the file name GITMOB_COAUTHORS_FILENAME prefer to keep this internal.

At the moment I'm migrating to use git-mob-core package which is why there are two references to figuring out the path.

It would be handy to provide a config with a relative path to help organise where the file lives in the repo.

It would be great if you could create a PR for this. Please comment if you do decide to and assign yourself. Thanks.

Your suggested changes look to be in the correct place and you can get the root dir here.

Please read the small contribution guide.

Great thanks @rkotze,

I will submit a PR by End of Week. Ill duplicate the code in both areas.

Thanks for your contribution @tlabeeuw. Released in git mob v2.4.0.