1

I'm following the gitflow model for a data science project, and I would like to automatically change the version number inside one file and commit it, after creating a new release branch. The new version name should just be the name of the release branch.

I think the git hook for post-checkout is probably the best option, but I can't understand how to use the arguments it receives to check if the checkout was a branch creation or a checkout to an existing branch, nor how to get the name of the newly create release branch.

phd
  • 82,685
  • 13
  • 120
  • 165
Rui Bastos
  • 56
  • 7
  • 1
    Automatic versioning perhaps may work, while better to have signed tag for each source release you do. – 0andriy Sep 09 '19 at 14:28
  • @0andriy How does automatic versioning works? – Rui Bastos Sep 12 '19 at 10:32
  • In a way you described it. I never use such approach and consider only (signed) tags. – 0andriy Sep 12 '19 at 11:04
  • Per https://stackoverflow.com/questions/14297606/git-hook-when-a-new-branch-is-created-and-or-pushed, you may want to try the update hook. – alex Sep 12 '19 at 14:39
  • @alex it seems like that only works on pushing, since it's a server-side hook, and I would need it to be a local operation. – Rui Bastos Sep 17 '19 at 10:32
  • Why on earth would you want to do this with hooks? Make a damn new-release script that starts a branch and bumps the version. – jthill Sep 22 '19 at 19:42
  • @jthill because I didn't want to change anything in the way things are done. Instead of creating a new script that I would call _instead_ of creating a new branch, I wanted to incorporate this in the regular workflow. – Rui Bastos May 26 '20 at 09:39

1 Answers1

0

It would make more sense to use pre-push or pre-commit to do this than post-checkout to avoid commits that contain only a version bump and no code changes. However, in terms of getting the version change done, you’ll need to be more specific about your code base. Is the version kept in a json file? Are you on a Unix? Windows?

shallow.alchemy
  • 530
  • 4
  • 14
  • I would actually prefer to to have it on checkout, and having a commit only for the version bump. In terms of the codebase, I'm on Windows and have the version number inside a python script. I guess it actually makes more sense to keep the file in a standalone file, so I'm going to change that. – Rui Bastos Oct 09 '19 at 08:37