Storing the project (key) and repository (slug) in config opens up issues with keeping the data accurate. Project keys can be changed, and repositories can be renamed or moved to different projects. A single project key change could trigger updating many repositories, each requiring its own fork of a git config process.
Instead, I think a better approach is to provide this in an environment variable whenever a git command is forked. That means code like this becomes unnecessary:
Instead, you'd be able to simply refer to $STASH_PROJECT and $STASH_REPOSITORY to get the values. (That's more efficient as a bonus, since your script doesn't need to fork off two git config processes to extract the config values.) Since the environment variables would be exported on each process, they'd automatically pick up any key or slug changes, making them more resilient to changes without an additional effort.
STASH versus BITBUCKET for naming the new variables is a sensitive decision. Changing existing $STASH_* environment variables could break things in subtle ways, which is why we've left them as-is, and splitting our naming between STASH and BITBUCKET makes using the "right" variable harder. I'm inclined to use STASH for the new variables for consistency.
There is, of course, the "repository at rest" consideration, where an administrator is looking at a repository on disk and they want to know which Repository it is in the system. An entry in the config file could help there, but only if it's reliably up-to-date with any changes that have been made since the repository was created. For that case, I'm inclined to leave it in the stash-reponame-plugin, which can already be installed on any Bitbucket Server (or Stash, by using a 1.x version) instance to add bitbucket.project and bitbucket.repository config entries (stash.project and stash.repository for 1.x versions) and keep them up-to-date over time.
Best regards,
Bryan Turner
Atlassian Bitbucket
zakaria.boutami
That's correct. Git intentionally does not allow the server to make changes to clones; it's a security consideration, to ensure a malevolent server cannot "attack" clients through their configuration.
Best regards,
Bryan Turner
Atlassian Bitbucket