Skip to content

Commit fe2205c

Browse files
committed
mirror: Add debug for pruning refs
Signed-off-by: Andrei Gherzan <andrei@gherzan.com>
1 parent e653925 commit fe2205c

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

git.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,21 @@ func extraSpecs(repo *git.Repository, refs []*plumbing.Reference) ([]config.RefS
112112

113113
// pruneRemote removes all the references in a remote that are not available in
114114
// the repo.
115-
func pruneRemote(remote *git.Remote, auth transport.AuthMethod, repo *git.Repository) error {
115+
func pruneRemote(conf Config, logger *Logger, remote *git.Remote, auth transport.AuthMethod, repo *git.Repository) error {
116116
refs, err := remote.List(&git.ListOptions{
117117
Auth: auth,
118118
})
119119
if err != nil {
120120
return fmt.Errorf("failed to list the destination remote: %w", err)
121121
}
122122

123-
deleteSpecs, err := extraSpecs(repo, refs)
124-
if err != nil {
125-
return fmt.Errorf("failed to get the prune specs: %w", err)
126-
}
123+
deleteRefs, _ := extraRefs(repo, refs)
124+
125+
deleteSpecs := refsToDeleteSpecs(deleteRefs)
127126

128127
if len(deleteSpecs) > 0 {
128+
logger.Debug(conf.Debug, "Pruning the following refs:", deleteRefs)
129+
129130
err := remote.Push(&git.PushOptions{
130131
RemoteName: remote.Config().Name,
131132
Auth: auth,
@@ -134,6 +135,8 @@ func pruneRemote(remote *git.Remote, auth transport.AuthMethod, repo *git.Reposi
134135
if err != nil && errors.Is(err, git.NoErrAlreadyUpToDate) {
135136
return fmt.Errorf("failed to prune destination: %w", err)
136137
}
138+
} else {
139+
logger.Debug(conf.Debug, "No refs found to prune.")
137140
}
138141

139142
return nil
@@ -259,7 +262,7 @@ func pushWithAuth(conf Config, logger *Logger, stagingRepo *git.Repository) erro
259262
// with the prunning with a separate push.
260263
logger.Info("Pruning the destination...")
261264

262-
err = pruneRemote(dst, auth, stagingRepo)
265+
err = pruneRemote(conf, logger, dst, auth, stagingRepo)
263266
if err != nil {
264267
return nil
265268
}

git_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ func TestDoMirror(t *testing.T) {
552552
conf := Config{
553553
SrcRepo: srcRepoPath,
554554
DstRepo: dstRepoPath,
555+
Debug: true,
555556
SSH: SSHConf{
556557
PrivateKey: testSSHKey,
557558
KnownHosts: testKnownHost,

0 commit comments

Comments
 (0)