Skip to content

Commit 7c0e396

Browse files
authored
Merge pull request moby#5096 from jedevc/git-checkout-umask
git: ensure exec option is propagated to child git clis
2 parents 58b8e1f + 899cac1 commit 7c0e396

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

source/git/source_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,21 @@ func testFetchByTag(t *testing.T, tag, expectedCommitSubject string, isAnnotated
373373
require.NoError(t, err)
374374
defer lm.Unmount()
375375

376+
st, err := os.Lstat(filepath.Join(dir, "subdir"))
377+
require.NoError(t, err)
378+
379+
require.True(t, st.IsDir())
380+
require.Equal(t, strconv.FormatInt(0755, 8), strconv.FormatInt(int64(st.Mode()&os.ModePerm), 8))
381+
376382
dt, err := os.ReadFile(filepath.Join(dir, "def"))
377383
require.NoError(t, err)
378384
require.Equal(t, "bar\n", string(dt))
379385

386+
st, err = os.Lstat(filepath.Join(dir, "def"))
387+
require.NoError(t, err)
388+
389+
require.Equal(t, strconv.FormatInt(0644, 8), strconv.FormatInt(int64(st.Mode()&os.ModePerm), 8))
390+
380391
dt, err = os.ReadFile(filepath.Join(dir, "foo13"))
381392
if hasFoo13File {
382393
require.NoError(t, err)
@@ -692,7 +703,9 @@ func setupGitRepo(t *testing.T) gitRepoFixture {
692703
"git commit -m initial",
693704
"git tag --no-sign a/v1.2.3",
694705
"echo bar > def",
695-
"git add def",
706+
"mkdir subdir",
707+
"echo subcontents > subdir/subfile",
708+
"git add def subdir",
696709
"git commit -m second",
697710
"git tag -a -m \"this is an annotated tag\" v1.2.3",
698711
"echo foo > bar",

source/git/source_unix_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//go:build !windows
2+
// +build !windows
3+
4+
package git
5+
6+
import "syscall"
7+
8+
func init() {
9+
// Reset umask to zero to match buildkitd and to make sure the tests do not rely on standard umask from the host.
10+
syscall.Umask(0)
11+
}

util/gitutil/git_cli.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,20 +119,13 @@ func NewGitCLI(opts ...Option) *GitCLI {
119119
// New returns a new git client with the same config as the current one, but
120120
// with the given options applied on top.
121121
func (cli *GitCLI) New(opts ...Option) *GitCLI {
122-
c := &GitCLI{
123-
git: cli.git,
124-
dir: cli.dir,
125-
workTree: cli.workTree,
126-
gitDir: cli.gitDir,
127-
args: append([]string{}, cli.args...),
128-
streams: cli.streams,
129-
sshAuthSock: cli.sshAuthSock,
130-
sshKnownHosts: cli.sshKnownHosts,
131-
}
122+
clone := *cli
123+
clone.args = append([]string{}, cli.args...)
124+
132125
for _, opt := range opts {
133-
opt(c)
126+
opt(&clone)
134127
}
135-
return c
128+
return &clone
136129
}
137130

138131
// Run executes a git command with the given args.

0 commit comments

Comments
 (0)