test_git.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import os
  2. import infra.basetest
  3. class TestGit(infra.basetest.BRTest):
  4. config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
  5. """
  6. BR2_PACKAGE_GIT=y
  7. BR2_TARGET_ROOTFS_CPIO=y
  8. # BR2_TARGET_ROOTFS_TAR is not set
  9. """
  10. def test_run(self):
  11. cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
  12. self.emulator.boot(arch="armv5",
  13. kernel="builtin",
  14. options=["-initrd", cpio_file])
  15. self.emulator.login()
  16. # Check the program can execute.
  17. self.assertRunOk("git --version")
  18. # Initialize some git global configuration.
  19. git_cfg = [
  20. ("user.name", "Build Root"),
  21. ("user.email", "build.root@localhost.localdomain"),
  22. ("color.ui", "false"),
  23. ("init.defaultBranch", "master"),
  24. ("core.pager", "")
  25. ]
  26. for cfg_name, cfg_value in git_cfg:
  27. cmd = f"git config --global {cfg_name} '{cfg_value}'"
  28. self.assertRunOk(cmd)
  29. # Run a sequence of few git commands.
  30. commands = [
  31. "mkdir workdir",
  32. "cd workdir",
  33. "git init",
  34. "echo 'Hello World' > file.txt",
  35. "git add file.txt",
  36. "git commit -as -m 'Initial commit'",
  37. "git checkout -b my_branch",
  38. "sed -i 's/World/Buildroot/g' file.txt",
  39. "git status",
  40. "git commit -as -m 'Replace World by Buildroot'",
  41. "git format-patch -M -n -s -o patches master",
  42. "ls -al patches/*.patch",
  43. "git checkout -b another_branch master",
  44. "git am patches/*.patch",
  45. "git diff --exit-code my_branch another_branch",
  46. "git tag -a -m 'Tagged v1.0' v1.0",
  47. "git log"
  48. ]
  49. for cmd in commands:
  50. self.assertRunOk(cmd)