How to commit a git repository inside another git repository

前端 未结 3 939
甜味超标
甜味超标 2021-01-17 16:32

I\'m developing an application that uses git, so I need to test its integration with git. Inside my git repository, I need to have another repository (my_git_repo/tests/anot

3条回答
  •  粉色の甜心
    2021-01-17 16:45

    I loved @hvd's reply and I think it should be an answer that deserves voting up:

    You could include an already set up sub-repository as a zip file -- or whatever other format you prefer -- and then make your test create or clear a directory and simply unzip the sub-repository there. That said, while it greatly reduces the complexity of running the tests, it greatly increases the complexity of creating and maintaining the tests, so it's not something I recommend.

    There are situations sub-modules are just too complex for a simple issue. My code was already working with the setup similar to the original question. My problem was involving test repos where those repos (3 of them) were going to be used for testing purposes only using actual repos with known commits. So I wanted to add those repos into git just like any other subfolder without the complexity of submodules... this is for testing for crying out loud. I needed the histories to be within those test repos. I noticed that the complexity of submodules is actually greater than the said 'complexity of creating and maintaining the tests'... actually it's simple.

    const GitMockReposWD = Path.resolve(__dirname, 'mocks/git')
    before(`Decompress git mock repos...`, function (done) {
      if (!Fs.existsSync(GitMockReposWD)) {
        console.log(`Decompressing git mock repos...`)
        const Decompress = require('decompress')
        Decompress(Path.resolve(__dirname, 'mocks/git-mock-repos.zip'), GitMockReposWD).then(() => {
          console.log('Done decompressing!')
          done()
        })
      } else {
        console.log(`git mock repos already exist...`)
        done()
      }
    })
    after(`Clean git mock repos...`, function () {
      if (Fs.existsSync(GitMockReposWD)) {
        console.log(`Cleaning git mock repos...`);
        Fs.rmdir(GitMockReposWD, () => {
          console.log(`Done cleaning git mock repos!`)
        })
      }
    })
    

    The above code simply decompresses the test repos before the tests suites are run and cleans them up afterwards. The idea here is to setup the repos as required by your scenario and then add them to an archive. If there are any changes to the repos then you just update the archive.

提交回复
热议问题