11// Package git allows to interact with Git.
2+ //
3+ // Deprecated: The git package is scheduled for removal in Terratest v2. Each
4+ // helper here wraps a single git command (for example, git rev-parse or
5+ // git describe); call git directly with os/exec instead. There is no public
6+ // replacement; the package is being dropped.
27package git
38
49import (
@@ -14,9 +19,8 @@ import (
1419// GetCurrentBranchName retrieves the current branch name or an empty string
1520// in case of detached state. Fails the test if an error occurs.
1621//
17- // Deprecated: Use [GetCurrentBranchNameContext] instead, which supports context
18- // cancellation and accepts an explicit working directory rather than relying on
19- // the process working directory.
22+ // Deprecated: scheduled for removal in Terratest v2. Shell out to git directly, e.g.
23+ // exec.Command("git", "branch", "--show-current").Output() (empty when detached).
2024func GetCurrentBranchName (t testing.TestingT ) string {
2125 return GetCurrentBranchNameContext (t , context .Background (), "" )
2226}
@@ -25,6 +29,9 @@ func GetCurrentBranchName(t testing.TestingT) string {
2529// string in case of detached state. The dir parameter specifies the working
2630// directory for the git command; if empty, the process working directory is
2731// used. Fails the test if an error occurs.
32+ //
33+ // Deprecated: scheduled for removal in Terratest v2. Shell out to git directly, e.g.
34+ // exec.CommandContext(ctx, "git", "branch", "--show-current") with cmd.Dir = dir, then .Output().
2835func GetCurrentBranchNameContext (t testing.TestingT , ctx context.Context , dir string ) string {
2936 out , err := GetCurrentBranchNameContextE (t , ctx , dir )
3037 if err != nil {
@@ -38,9 +45,8 @@ func GetCurrentBranchNameContext(t testing.TestingT, ctx context.Context, dir st
3845// in case of detached state. Uses git branch --show-current, which was
3946// introduced in git v2.22. Falls back to git rev-parse for older versions.
4047//
41- // Deprecated: Use [GetCurrentBranchNameContextE] instead, which supports
42- // context cancellation and accepts an explicit working directory rather than
43- // relying on the process working directory.
48+ // Deprecated: scheduled for removal in Terratest v2. Shell out to git directly, e.g.
49+ // exec.Command("git", "branch", "--show-current").Output() (empty when detached).
4450func GetCurrentBranchNameE (t testing.TestingT ) (string , error ) {
4551 return GetCurrentBranchNameContextE (t , context .Background (), "" )
4652}
@@ -50,6 +56,9 @@ func GetCurrentBranchNameE(t testing.TestingT) (string, error) {
5056// introduced in git v2.22. Falls back to git rev-parse for older versions.
5157// The dir parameter specifies the working directory for the git command; if
5258// empty, the process working directory is used.
59+ //
60+ // Deprecated: scheduled for removal in Terratest v2. Shell out to git directly, e.g.
61+ // exec.CommandContext(ctx, "git", "branch", "--show-current") with cmd.Dir = dir, then .Output().
5362func GetCurrentBranchNameContextE (t testing.TestingT , ctx context.Context , dir string ) (string , error ) {
5463 cmd := exec .CommandContext (ctx , "git" , "branch" , "--show-current" )
5564 cmd .Dir = dir
@@ -70,9 +79,8 @@ func GetCurrentBranchNameContextE(t testing.TestingT, ctx context.Context, dir s
7079// GetCurrentBranchNameOldE retrieves the current branch name or an empty
7180// string in case of detached state using git rev-parse --abbrev-ref HEAD.
7281//
73- // Deprecated: Use [GetCurrentBranchNameOldContextE] instead, which supports
74- // context cancellation and accepts an explicit working directory rather than
75- // relying on the process working directory.
82+ // Deprecated: scheduled for removal in Terratest v2. Shell out to git directly, e.g.
83+ // exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD").Output() (prints "HEAD" when detached; map it to "").
7684func GetCurrentBranchNameOldE (t testing.TestingT ) (string , error ) {
7785 return GetCurrentBranchNameOldContextE (t , context .Background (), "" )
7886}
@@ -82,6 +90,9 @@ func GetCurrentBranchNameOldE(t testing.TestingT) (string, error) {
8290// This is a fallback for git versions older than v2.22 that lack
8391// git branch --show-current. The dir parameter specifies the working directory
8492// for the git command; if empty, the process working directory is used.
93+ //
94+ // Deprecated: scheduled for removal in Terratest v2. Shell out to git directly, e.g.
95+ // exec.CommandContext(ctx, "git", "rev-parse", "--abbrev-ref", "HEAD") with cmd.Dir = dir, then .Output().
8596func GetCurrentBranchNameOldContextE (t testing.TestingT , ctx context.Context , dir string ) (string , error ) {
8697 cmd := exec .CommandContext (ctx , "git" , "rev-parse" , "--abbrev-ref" , "HEAD" )
8798 cmd .Dir = dir
@@ -103,9 +114,8 @@ func GetCurrentBranchNameOldContextE(t testing.TestingT, ctx context.Context, di
103114// (non-annotated) tag, or exact tag value if the tag points to the current
104115// commit. Fails the test if an error occurs.
105116//
106- // Deprecated: Use [GetCurrentGitRefContext] instead, which supports context
107- // cancellation and accepts an explicit working directory rather than relying on
108- // the process working directory.
117+ // Deprecated: scheduled for removal in Terratest v2. Shell out to git directly: try
118+ // git branch --show-current, then git describe --tags when detached.
109119func GetCurrentGitRef (t testing.TestingT ) string {
110120 return GetCurrentGitRefContext (t , context .Background (), "" )
111121}
@@ -115,6 +125,9 @@ func GetCurrentGitRef(t testing.TestingT) string {
115125// commit. The dir parameter specifies the working directory for the git
116126// command; if empty, the process working directory is used. Fails the test if
117127// an error occurs.
128+ //
129+ // Deprecated: scheduled for removal in Terratest v2. Shell out to git directly: try
130+ // git branch --show-current, then git describe --tags when detached (set cmd.Dir = dir).
118131func GetCurrentGitRefContext (t testing.TestingT , ctx context.Context , dir string ) string {
119132 out , err := GetCurrentGitRefContextE (t , ctx , dir )
120133 if err != nil {
@@ -128,9 +141,8 @@ func GetCurrentGitRefContext(t testing.TestingT, ctx context.Context, dir string
128141// (non-annotated) tag, or exact tag value if the tag points to the current
129142// commit.
130143//
131- // Deprecated: Use [GetCurrentGitRefContextE] instead, which supports context
132- // cancellation and accepts an explicit working directory rather than relying on
133- // the process working directory.
144+ // Deprecated: scheduled for removal in Terratest v2. Shell out to git directly: try
145+ // git branch --show-current, then git describe --tags when detached.
134146func GetCurrentGitRefE (t testing.TestingT ) (string , error ) {
135147 return GetCurrentGitRefContextE (t , context .Background (), "" )
136148}
@@ -139,6 +151,9 @@ func GetCurrentGitRefE(t testing.TestingT) (string, error) {
139151// (non-annotated) tag, or exact tag value if the tag points to the current
140152// commit. The dir parameter specifies the working directory for the git
141153// command; if empty, the process working directory is used.
154+ //
155+ // Deprecated: scheduled for removal in Terratest v2. Shell out to git directly: try
156+ // git branch --show-current, then git describe --tags when detached (set cmd.Dir = dir).
142157func GetCurrentGitRefContextE (t testing.TestingT , ctx context.Context , dir string ) (string , error ) {
143158 out , err := GetCurrentBranchNameContextE (t , ctx , dir )
144159 if err != nil {
@@ -160,9 +175,8 @@ func GetCurrentGitRefContextE(t testing.TestingT, ctx context.Context, dir strin
160175// GetTagE retrieves the lightweight (non-annotated) tag or exact tag value if
161176// the tag points to the current commit.
162177//
163- // Deprecated: Use [GetTagContextE] instead, which supports context
164- // cancellation and accepts an explicit working directory rather than relying on
165- // the process working directory.
178+ // Deprecated: scheduled for removal in Terratest v2. Shell out to git directly, e.g.
179+ // exec.Command("git", "describe", "--tags").Output().
166180func GetTagE (t testing.TestingT ) (string , error ) {
167181 return GetTagContextE (t , context .Background (), "" )
168182}
@@ -171,6 +185,9 @@ func GetTagE(t testing.TestingT) (string, error) {
171185// value if the tag points to the current commit. The dir parameter specifies
172186// the working directory for the git command; if empty, the process working
173187// directory is used.
188+ //
189+ // Deprecated: scheduled for removal in Terratest v2. Shell out to git directly, e.g.
190+ // exec.CommandContext(ctx, "git", "describe", "--tags") with cmd.Dir = dir, then .Output().
174191func GetTagContextE (t testing.TestingT , ctx context.Context , dir string ) (string , error ) {
175192 cmd := exec .CommandContext (ctx , "git" , "describe" , "--tags" )
176193 cmd .Dir = dir
@@ -186,16 +203,18 @@ func GetTagContextE(t testing.TestingT, ctx context.Context, dir string) (string
186203// GetRepoRoot retrieves the path to the root directory of the repo. Fails the
187204// test if there is an error.
188205//
189- // Deprecated: Use [GetRepoRootContext] instead, which supports context
190- // cancellation and accepts an explicit working directory rather than relying on
191- // the process working directory.
206+ // Deprecated: scheduled for removal in Terratest v2. Shell out to git directly, e.g.
207+ // exec.Command("git", "rev-parse", "--show-toplevel").Output().
192208func GetRepoRoot (t testing.TestingT ) string {
193209 return GetRepoRootContext (t , context .Background (), "" )
194210}
195211
196212// GetRepoRootContext retrieves the path to the root directory of the repo. The
197213// dir parameter specifies the working directory for the git command; if empty,
198214// the process working directory is used. Fails the test if there is an error.
215+ //
216+ // Deprecated: scheduled for removal in Terratest v2. Shell out to git directly, e.g.
217+ // exec.CommandContext(ctx, "git", "rev-parse", "--show-toplevel") with cmd.Dir = dir, then .Output().
199218func GetRepoRootContext (t testing.TestingT , ctx context.Context , dir string ) string {
200219 out , err := GetRepoRootContextE (t , ctx , dir )
201220 require .NoError (t , err )
@@ -205,16 +224,18 @@ func GetRepoRootContext(t testing.TestingT, ctx context.Context, dir string) str
205224
206225// GetRepoRootE retrieves the path to the root directory of the repo.
207226//
208- // Deprecated: Use [GetRepoRootContextE] instead, which supports context
209- // cancellation and accepts an explicit working directory rather than relying on
210- // the process working directory.
227+ // Deprecated: scheduled for removal in Terratest v2. Shell out to git directly, e.g.
228+ // exec.Command("git", "rev-parse", "--show-toplevel").Output().
211229func GetRepoRootE (t testing.TestingT ) (string , error ) {
212230 return GetRepoRootContextE (t , context .Background (), "" )
213231}
214232
215233// GetRepoRootContextE retrieves the path to the root directory of the repo.
216234// The dir parameter specifies the working directory for the git command; if
217235// empty, the process working directory is used.
236+ //
237+ // Deprecated: scheduled for removal in Terratest v2. Shell out to git directly, e.g.
238+ // exec.CommandContext(ctx, "git", "rev-parse", "--show-toplevel") with cmd.Dir = dir, then .Output().
218239func GetRepoRootContextE (t testing.TestingT , ctx context.Context , dir string ) (string , error ) {
219240 if dir == "" {
220241 cwd , err := os .Getwd ()
@@ -231,14 +252,17 @@ func GetRepoRootContextE(t testing.TestingT, ctx context.Context, dir string) (s
231252// GetRepoRootForDir retrieves the path to the root directory of the repo in
232253// which dir resides. Fails the test if there is an error.
233254//
234- // Deprecated: Use [GetRepoRootForDirContext] instead, which supports context
235- // cancellation .
255+ // Deprecated: scheduled for removal in Terratest v2. Shell out to git directly, e.g.
256+ // exec.Command("git", "rev-parse", "--show-toplevel") with cmd.Dir = dir, then .Output() .
236257func GetRepoRootForDir (t testing.TestingT , dir string ) string {
237258 return GetRepoRootForDirContext (t , context .Background (), dir )
238259}
239260
240261// GetRepoRootForDirContext retrieves the path to the root directory of the
241262// repo in which dir resides. Fails the test if there is an error.
263+ //
264+ // Deprecated: scheduled for removal in Terratest v2. Shell out to git directly, e.g.
265+ // exec.CommandContext(ctx, "git", "rev-parse", "--show-toplevel") with cmd.Dir = dir, then .Output().
242266func GetRepoRootForDirContext (t testing.TestingT , ctx context.Context , dir string ) string {
243267 out , err := GetRepoRootForDirContextE (t , ctx , dir )
244268 require .NoError (t , err )
@@ -249,14 +273,17 @@ func GetRepoRootForDirContext(t testing.TestingT, ctx context.Context, dir strin
249273// GetRepoRootForDirE retrieves the path to the root directory of the repo in
250274// which dir resides.
251275//
252- // Deprecated: Use [GetRepoRootForDirContextE] instead, which supports context
253- // cancellation .
276+ // Deprecated: scheduled for removal in Terratest v2. Shell out to git directly, e.g.
277+ // exec.Command("git", "rev-parse", "--show-toplevel") with cmd.Dir = dir, then .Output() .
254278func GetRepoRootForDirE (t testing.TestingT , dir string ) (string , error ) {
255279 return GetRepoRootForDirContextE (t , context .Background (), dir )
256280}
257281
258282// GetRepoRootForDirContextE retrieves the path to the root directory of the
259283// repo in which dir resides.
284+ //
285+ // Deprecated: scheduled for removal in Terratest v2. Shell out to git directly, e.g.
286+ // exec.CommandContext(ctx, "git", "rev-parse", "--show-toplevel") with cmd.Dir = dir, then .Output().
260287func GetRepoRootForDirContextE (t testing.TestingT , ctx context.Context , dir string ) (string , error ) {
261288 cmd := exec .CommandContext (ctx , "git" , "rev-parse" , "--show-toplevel" )
262289 cmd .Dir = dir
0 commit comments