v4: use repo default branch instead of master
This commit is contained in:
parent
2b471ba2d7
commit
7b32caee77
|
|
@ -54,7 +54,6 @@ docker run -d \
|
||||||
-u$(id -u):$(id -g) \
|
-u$(id -u):$(id -g) \
|
||||||
registry/git-sync:tag \
|
registry/git-sync:tag \
|
||||||
--repo=https://github.com/kubernetes/git-sync \
|
--repo=https://github.com/kubernetes/git-sync \
|
||||||
--branch=master \
|
|
||||||
--root=/tmp/git/root \
|
--root=/tmp/git/root \
|
||||||
--period=30s
|
--period=30s
|
||||||
|
|
||||||
|
|
@ -113,7 +112,7 @@ OPTIONS
|
||||||
"username=<value>" and "password=<value>".
|
"username=<value>" and "password=<value>".
|
||||||
|
|
||||||
--branch <string>, $GIT_SYNC_BRANCH
|
--branch <string>, $GIT_SYNC_BRANCH
|
||||||
The git branch to check out. (default: master)
|
The git branch to check out. (default: <repo's default branch>)
|
||||||
|
|
||||||
--change-permissions <int>, $GIT_SYNC_PERMISSIONS
|
--change-permissions <int>, $GIT_SYNC_PERMISSIONS
|
||||||
Optionally change permissions on the checked-out files to the
|
Optionally change permissions on the checked-out files to the
|
||||||
|
|
@ -272,7 +271,7 @@ EXAMPLE USAGE
|
||||||
|
|
||||||
git-sync \
|
git-sync \
|
||||||
--repo=https://github.com/kubernetes/git-sync \
|
--repo=https://github.com/kubernetes/git-sync \
|
||||||
--branch=master \
|
--branch=main \
|
||||||
--rev=HEAD \
|
--rev=HEAD \
|
||||||
--period=10s \
|
--period=10s \
|
||||||
--root=/mnt/git
|
--root=/mnt/git
|
||||||
|
|
|
||||||
|
|
@ -55,8 +55,8 @@ var flVerbose = pflag.IntP("verbose", "v", 0,
|
||||||
|
|
||||||
var flRepo = pflag.String("repo", envString("GIT_SYNC_REPO", ""),
|
var flRepo = pflag.String("repo", envString("GIT_SYNC_REPO", ""),
|
||||||
"the git repository to clone")
|
"the git repository to clone")
|
||||||
var flBranch = pflag.String("branch", envString("GIT_SYNC_BRANCH", "master"),
|
var flBranch = pflag.String("branch", envString("GIT_SYNC_BRANCH", ""),
|
||||||
"the git branch to check out")
|
"the git branch to check out (defaults to repo's default branch)")
|
||||||
var flRev = pflag.String("rev", envString("GIT_SYNC_REV", "HEAD"),
|
var flRev = pflag.String("rev", envString("GIT_SYNC_REV", "HEAD"),
|
||||||
"the git revision (tag or hash) to check out")
|
"the git revision (tag or hash) to check out")
|
||||||
var flDepth = pflag.Int("depth", envInt("GIT_SYNC_DEPTH", 0),
|
var flDepth = pflag.Int("depth", envInt("GIT_SYNC_DEPTH", 0),
|
||||||
|
|
@ -124,7 +124,7 @@ var flCookieFile = pflag.Bool("cookie-file", envBool("GIT_COOKIE_FILE", false),
|
||||||
"use a git cookiefile (/etc/git-secret/cookie_file) for authentication")
|
"use a git cookiefile (/etc/git-secret/cookie_file) for authentication")
|
||||||
|
|
||||||
var flAskPassURL = pflag.String("askpass-url", envString("GIT_ASKPASS_URL", ""),
|
var flAskPassURL = pflag.String("askpass-url", envString("GIT_ASKPASS_URL", ""),
|
||||||
"a URL to query for git credentials (username=<value> and password=<value>")
|
"a URL to query for git credentials (username=<value> and password=<value>)")
|
||||||
|
|
||||||
var flGitCmd = pflag.String("git", envString("GIT_SYNC_GIT", "git"),
|
var flGitCmd = pflag.String("git", envString("GIT_SYNC_GIT", "git"),
|
||||||
"the git command to run (subject to PATH search, mostly for testing)")
|
"the git command to run (subject to PATH search, mostly for testing)")
|
||||||
|
|
@ -881,7 +881,11 @@ func (git *repoSync) AddWorktreeAndSwap(ctx context.Context, hash string) error
|
||||||
if git.depth != 0 {
|
if git.depth != 0 {
|
||||||
args = append(args, "--depth", strconv.Itoa(git.depth))
|
args = append(args, "--depth", strconv.Itoa(git.depth))
|
||||||
}
|
}
|
||||||
args = append(args, "origin", git.branch)
|
fetch := "HEAD"
|
||||||
|
if git.branch != "" {
|
||||||
|
fetch = git.branch
|
||||||
|
}
|
||||||
|
args = append(args, "origin", fetch)
|
||||||
|
|
||||||
// Update from the remote.
|
// Update from the remote.
|
||||||
if _, err := git.run.Run(ctx, git.root, git.cmd, args...); err != nil {
|
if _, err := git.run.Run(ctx, git.root, git.cmd, args...); err != nil {
|
||||||
|
|
@ -908,7 +912,7 @@ func (git *repoSync) AddWorktreeAndSwap(ctx context.Context, hash string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := git.run.Run(ctx, git.root, git.cmd, "worktree", "add", "--detach", worktreePath, hash, "--no-checkout")
|
_, err := git.run.Run(ctx, git.root, git.cmd, "worktree", "add", "--detach", worktreePath, hash, "--no-checkout")
|
||||||
git.log.V(0).Info("adding worktree", "path", worktreePath, "branch", fmt.Sprintf("origin/%s", git.branch))
|
git.log.V(0).Info("adding worktree", "path", worktreePath, "hash", hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -1037,7 +1041,10 @@ func (git *repoSync) AddWorktreeAndSwap(ctx context.Context, hash string) error
|
||||||
|
|
||||||
// CloneRepo does an initial clone of the git repo.
|
// CloneRepo does an initial clone of the git repo.
|
||||||
func (git *repoSync) CloneRepo(ctx context.Context) error {
|
func (git *repoSync) CloneRepo(ctx context.Context) error {
|
||||||
args := []string{"clone", "--no-checkout", "-b", git.branch}
|
args := []string{"clone", "--no-checkout"}
|
||||||
|
if git.branch != "" {
|
||||||
|
args = append(args, "-b", git.branch)
|
||||||
|
}
|
||||||
if git.depth != 0 {
|
if git.depth != 0 {
|
||||||
args = append(args, "--depth", strconv.Itoa(git.depth))
|
args = append(args, "--depth", strconv.Itoa(git.depth))
|
||||||
}
|
}
|
||||||
|
|
@ -1211,12 +1218,13 @@ func (git *repoSync) GetRevs(ctx context.Context) (string, string, error) {
|
||||||
return "", "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build a ref string, depending on whether the user asked to track HEAD or a tag.
|
// Build a ref string, depending on whether the user asked to track HEAD or
|
||||||
ref := ""
|
// a tag.
|
||||||
if git.rev == "HEAD" {
|
ref := "HEAD"
|
||||||
ref = "refs/heads/" + git.branch
|
if git.rev != "HEAD" {
|
||||||
} else {
|
|
||||||
ref = "refs/tags/" + git.rev
|
ref = "refs/tags/" + git.rev
|
||||||
|
} else if git.branch != "" {
|
||||||
|
ref = "refs/heads/" + git.branch
|
||||||
}
|
}
|
||||||
|
|
||||||
// Figure out what hash the remote resolves ref to.
|
// Figure out what hash the remote resolves ref to.
|
||||||
|
|
@ -1560,7 +1568,7 @@ OPTIONS
|
||||||
"username=<value>" and "password=<value>".
|
"username=<value>" and "password=<value>".
|
||||||
|
|
||||||
--branch <string>, $GIT_SYNC_BRANCH
|
--branch <string>, $GIT_SYNC_BRANCH
|
||||||
The git branch to check out. (default: master)
|
The git branch to check out. (default: <repo's default branch>)
|
||||||
|
|
||||||
--change-permissions <int>, $GIT_SYNC_PERMISSIONS
|
--change-permissions <int>, $GIT_SYNC_PERMISSIONS
|
||||||
Optionally change permissions on the checked-out files to the
|
Optionally change permissions on the checked-out files to the
|
||||||
|
|
@ -1730,7 +1738,7 @@ EXAMPLE USAGE
|
||||||
|
|
||||||
git-sync \
|
git-sync \
|
||||||
--repo=https://github.com/kubernetes/git-sync \
|
--repo=https://github.com/kubernetes/git-sync \
|
||||||
--branch=master \
|
--branch=main \
|
||||||
--rev=HEAD \
|
--rev=HEAD \
|
||||||
--period=10s \
|
--period=10s \
|
||||||
--root=/mnt/git
|
--root=/mnt/git
|
||||||
|
|
|
||||||
|
|
@ -348,13 +348,13 @@ function e2e::head_once_root_exists_but_fails_sanity() {
|
||||||
## FIXME: test when repo is valid git, and is already correct
|
## FIXME: test when repo is valid git, and is already correct
|
||||||
|
|
||||||
##############################################
|
##############################################
|
||||||
# Test default syncing (master)
|
# Test default-branch syncing
|
||||||
##############################################
|
##############################################
|
||||||
function e2e::default_sync_master() {
|
function e2e::default_branch_sync() {
|
||||||
# First sync
|
# First sync
|
||||||
echo "$FUNCNAME 1" > "$REPO"/file
|
echo "$FUNCNAME 1" > "$REPO"/file
|
||||||
git -C "$REPO" commit -qam "$FUNCNAME 1"
|
git -C "$REPO" commit -qam "$FUNCNAME 1"
|
||||||
git -C "$REPO" checkout -q -b master
|
git -C "$REPO" checkout -q -b weird-name
|
||||||
|
|
||||||
GIT_SYNC \
|
GIT_SYNC \
|
||||||
--period=100ms \
|
--period=100ms \
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue