开发者

How does Jenkins' 'emulate clean checkout' option work?

开发者 https://www.devze.com 2023-03-11 16:49 出处:网络
Specifically I am wanting to know how to do the \'delete unversion开发者_开发知识库ed/ignored files\' part of the command. I want to do this so I can emulate a clean checkout myself, our repository is

Specifically I am wanting to know how to do the 'delete unversion开发者_开发知识库ed/ignored files' part of the command. I want to do this so I can emulate a clean checkout myself, our repository is big and a full checkout takes a fair while.


This option is implemented in UpdateWithCleanUpdater. From the source,

@Override
protected void preUpdate(ModuleLocation module, File local) throws SVNException, IOException {
    listener.getLogger().println("Cleaning up " + local);

    clientManager.getStatusClient().doStatus(local, null, SVNDepth.INFINITY, false, false, true, false, new ISVNStatusHandler() {
        public void handleStatus(SVNStatus status) throws SVNException {
            SVNStatusType s = status.getCombinedNodeAndContentsStatus();
            if (s == SVNStatusType.STATUS_UNVERSIONED || s == SVNStatusType.STATUS_IGNORED || s == SVNStatusType.STATUS_MODIFIED) {
                listener.getLogger().println("Deleting "+status.getFile());
                try {
                    File f = status.getFile();
                    if (f.isDirectory())
                        hudson.Util.deleteRecursive(f);
                    else
                        f.delete();
                } catch (IOException e) {
                    throw new SVNException(SVNErrorMessage.create(SVNErrorCode.UNKNOWN, e));
                }
            }
        }
    }, null);
}

Looks like the code uses SVNKit to get SVN status and then delete all unversioned, ignored, and modified files and directories.

It surprised me that modified files are deleted instead of reverted, but they will get pulled back in through the SVN update anyway.


Not sure how Jenkins does this, but I'd assume it uses svn status to find unversioned/ignored files.

Here's 2 powershell scripts I use to do this:

#remove_ignored.ps1 (only removes ignored files, leaves unversioned)

param([switch] $WhatIf)

# Find all items with the status of I in svn
# Strip the leading status code and whitespace
# Grab the item for said path (either FileInfo or DirectoryInfo)
$paths = (svn status --no-ignore | Where-Object {$_.StartsWith('I')} | ForEach-Object {$_.SubString(8)} | ForEach-Object {Get-Item -Force $_})

$paths | ForEach-Object {
    if (-not $WhatIf) {
        # Check if the path still exists, in case it was a nested directory or something strange like that
        if ($_.Exists) {
            # If its a directory info, tell it to perform a recursive delete
            if ($_ -is [System.IO.DirectoryInfo]) { $_.Delete($true) }
            else { $_.Delete() }
        }
    }

    Write-Host "Deleted $_"
}

#remove_unversioned.ps1 (removes both ignored and unversioned files)
param([switch] $WhatIf)

# Find all items with the status of I or ? in svn
# Strip the leading status code and whitespace
# Grab the item for said path (either FileInfo or DirectoryInfo)
$paths = (svn status --no-ignore | Where-Object {$_.StartsWith('I') -or $_.StartsWith('?')} | ForEach-Object {$_.SubString(8)} | ForEach-Object {Get-Item -Force $_})

$paths | ForEach-Object {
    if (-not $WhatIf) {
        # Check if the path still exists, in case it was a nested directory or something strange like that
        if ($_.Exists) {
            # If its a directory info, tell it to perform a recursive delete
            if ($_ -is [System.IO.DirectoryInfo]) { $_.Delete($true) }
            else { $_.Delete() }
        }
    }

    Write-Host "Deleted $_"
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号