26

We're running into some workflow issues in the switch from hg to git (business requirement). In hg, we used to restrict outsource studios' access to proprietary code by creating subrepos with specific permissions settings. Our main hg repos would then have branches that pointed to the appropriate Source or DLL subrepos so they could easily be switched between.

The problem we're running into is that mimicking this setup in git seems impossible. Switching branches to one that does not contain a specific submodules does not delete the files of that submodule locally (intended git behavior). This creates a tedious manual deletion step that would likely cause problems if we rolled it out to the less technical people in the office. We need a system where people can checkout the tip from any other commit in the history and are guaranteed to have a working project, which can't happen if submodule content is not deleted in the current system.

Are there any alternatives in git to what we're trying to do?

Konstantin
  • 260
  • 2
  • 5
  • We're looking into adding a custom action into SourceTree that calls git clean -ffd, which lets us use the old workflow, but adds an extra step to our team's process – Konstantin Nov 03 '14 at 16:23
  • possible duplicate of [Push a branch of a git repo to a new remote (github), hiding its history](http://stackoverflow.com/questions/4020553/push-a-branch-of-a-git-repo-to-a-new-remote-github-hiding-its-history) – Paul Sweatte Nov 11 '14 at 23:10
  • That post is somewhat related. We both have the same goal, but are approaching it from totally different angles. There may be a solution that could work for both of us, but I'm not sure. – Konstantin Nov 13 '14 at 15:47
  • 2
    Have you looked at `git-repo`? http://stackoverflow.com/a/24847587/1049112 – onionjake Jun 20 '15 at 07:55
  • Client side tools like SourceTree and SmartGit can help with these types of issues with submodules in Git. Are you open to using a client? – Patrick O'Hara Sep 02 '15 at 14:49
  • Yes, we were using SourceTree and still found no solution. In the end, we managed to make a case for keeping hg and have switched back. – Konstantin Sep 03 '15 at 16:48

1 Answers1

1

You could use a post-checkout client side hook. Basically, when you switch branches to one that uses another submodule, the post-checkout hook will be run. In this hook, you can simply add code to remove all submodules that are not used by the current branch.

As hooks are not synced between remotes and local repos, you can follow this suggestion for getting the hooks to the people who will clone your repository.

Community
  • 1
  • 1
houtanb
  • 3,852
  • 20
  • 21