Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

trust-origin-git-config 3.1 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
  1. #!/usr/bin/env python
  2. # This script facilitates trusting/distrusting of the repo-wide .gitconfig
  3. #
  4. # trust:
  5. # tools/trust-origin-git-config
  6. # or
  7. # tools/trust-origin-git-config -e
  8. # which is the same as:
  9. # git config --local include.path ../.gitconfig
  10. #
  11. # distrust:
  12. # tools/trust-origin-git-config -d
  13. # which is the same as:
  14. # git config --local --unset include.path
  15. #
  16. # note: windows users, not using bash emulation, will need to invoke this tool as:
  17. # python tools\trust-origin-git-config
  18. import sys
  19. if sys.hexversion < 0x03060000: sys.exit("!!! Please re-run this script with python-3.6 or higher")
  20. import os, argparse, subprocess
  21. parser = argparse.ArgumentParser()
  22. parser.add_argument('-e', '--enable', action="store_true", help="Trust repo-wide .gitconfig (default action)")
  23. parser.add_argument('-d', '--disable', action="store_true", help="Distrust repo-wide .gitconfig")
  24. parser.add_argument('-t', '--test', action="store_true", help="Validate repo-wide .gitconfig config")
  25. args = parser.parse_args()
  26. # test exec bit
  27. def validate_script():
  28. filepath = os.path.join('tools', 'fastai-nbstripout')
  29. # check that we can execute the script
  30. cmd = f"{filepath} -h"
  31. #print(f"Executing: {cmd}")
  32. result = subprocess.run(cmd.split(), shell=False, check=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  33. # we don't care for the output, just to see that it works
  34. if result.returncode != 0:
  35. print(f"Can't execute {filepath}")
  36. if result.stderr: print(f"Error: {result.stderr.decode('utf-8')}")
  37. def trust_enable():
  38. #validate_script()
  39. cmd = "git config --local include.path ../.gitconfig"
  40. print(f"Executing: {cmd}")
  41. result = subprocess.run(cmd.split(), shell=False, check=False, stderr=subprocess.PIPE)
  42. if result.returncode == 0:
  43. print("Success: repo's .gitconfig is now trusted")
  44. else:
  45. print("Failed to trust repo's .gitconfig")
  46. if result.stderr: print(f"Error: {result.stderr.decode('utf-8')}")
  47. def trust_disable():
  48. cmd = "git config --local --unset include.path"
  49. print(f"Executing: {cmd}")
  50. result = subprocess.run(cmd.split(), shell=False, check=False, stderr=subprocess.PIPE)
  51. if result.returncode == 0:
  52. print("Success: repo's .gitconfig is now distrusted")
  53. else:
  54. print("Failed to distrust repo's .gitconfig")
  55. if result.stderr: print(f"Error: {result.stderr.decode('utf-8')}")
  56. def trust_test():
  57. #validate_script()
  58. cmd = "git config --list --show-origin"
  59. print(f"Executing: {cmd}")
  60. result = subprocess.run(cmd.split(), shell=False, check=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  61. if result.returncode == 0:
  62. out = result.stdout.decode('utf-8')
  63. if ".git/../.gitconfig" in out and "filter.fastai-nbstripout-code" in out:
  64. print("Check: repo's .gitconfig is trusted")
  65. else:
  66. print("Check: repo's .gitconfig is not trusted, re-run with -e option to trust it")
  67. else:
  68. print(f"Failed to run {cmd}")
  69. if result.stderr: print(f"Error: {result.stderr.decode('utf-8')}")
  70. if args.test: trust_test()
  71. elif args.disable: trust_disable()
  72. else: trust_enable()
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...