The Remove Discard files feature is deprecated and the purpose of this article is to guide you on how to completely disable this setting while preserving all integration settings such as project mapping, users’ PATS and other integration settings.
1. Update Git Integration for Jira
Upgrade to the latest version of Git Integration for Jira supporting the Discard cloned files feature (GIJ v4.16 as of now).
Go to the Manage apps page and expand Git Integration for Jira under Installed apps.
Click Update to upgrade the Git Integration for Jira app to the newest version.
2. Verify that a Git client is installed
Make sure that a Git client is installed on the machine where the Jira instance is running.. Use the following command to check the installed Git version:
git --version
3. On Windows, verify installed Powershell version (skip this step for Linux)
Ensure that PowerShell version 5.x or higher is installed on the machine where the Jira instance is running.
4. Disable webhooks on “Webhooks” page
On the Manage repositories page, click Webhooks on the sidebar then click Disabled.
5. Take note of the following General settings
Make sure to write down the following settings and save it for use later:
-
Repository indexing interval
-
Garbage collection and Revision validation interval
-
Git roll up issue tab
-
Git commits issue and project tabs
Then, set the scheduled job frequency to a large value. For example:
-
Repository indexing interval = 100000
-
Garbage collection and Revision validation interval = 100000
Also, disable the following settings to make GIJ repositories temporarily unavailable:
-
Set Git roll up issue tab to Do not display
-
Set Git commits issue and project tabs to Do not display
-
Untick the Enable repository browser setting
-
Untick the Show Git Integration panel on issue pages setting
-
Untick the Enable Automation for Jira (A4J) triggers setting
-
Untick the Enable JQL searching using commit information setting
6. Disable all repositories/integrations via Actions
Click the Disable all button on the Manage repositories page.
7. Clear the indexing queue
On your Jira dashboard Git menu, click Indexing queue.
Click on the Clear queue button to clear the indexing queue.
8a. Powershell script for Windows
#requires -version 5
[CmdletBinding()]
param (
[Parameter(Mandatory=$false,Position=0)]
[string]$FullRun
)
$ErrorActionPreference = 'Stop'
$ScriptDirectory = Split-Path -Path $PSScriptRoot -Leaf
if ( $ScriptDirectory -ne "git-plugin" ) {
Write-Output "The script should be run in jira/home/data/git-plugin directory! Current directory is `"$PSScriptRoot`"."
return
}
function Remove-Tree()
{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string]$Path
)
if ( Test-Path -LiteralPath $Path -PathType Container ) {
@(Get-ChildItem -LiteralPath $Path -Directory -Force).ForEach({ Remove-Tree -Path $_.FullName })
@(Get-ChildItem -LiteralPath $Path -File -Force).ForEach({ Remove-Item -LiteralPath $_.FullName -Force })
}
Remove-Item -LiteralPath $Path -Force
}
function Clear-GitRepo()
{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string]$GitRepoFolder
)
Set-Location -LiteralPath $GitRepoFolder
Write-Output ""
if ( -not (Test-Path -LiteralPath 'config' -PathType Any) ) {
Write-Output "skip $GitRepoFolder folder. It doesn't contain config."
Set-Location -Path ".."
return
}
Write-Output "delete files from $GitRepoFolder except 4 files: config, HEAD, repo.auto.json, repo.auto.json.gitforjira.lock"
@(Get-ChildItem -Force | Where-Object {$_.Name -notin "config", "HEAD", "repo.auto.json", "repo.auto.json.gitforjira.lock"}).ForEach({
Remove-Tree -Path $_.FullName
})
$isHeadExists = Test-Path -LiteralPath 'HEAD' -PathType Any
if ( $isHeadExists ) {
Write-Output "move 'HEAD' to 'HEAD-gij-backup' file"
Move-Item -Path 'HEAD' -Destination 'HEAD-gij-backup' -Force
}
Write-Output "init a bare repository with the same config"
$DummyDir = 'non-existent-git-template-directory'
try {
git init --bare --template=$DummyDir --quiet
}
catch [System.Management.Automation.RemoteException] {
if ( -not ($_.Exception -like "*$DummyDir*") ) {
throw
}
}
if ( $isHeadExists ) {
Write-Output "restore 'HEAD' file"
Move-Item -Path 'HEAD-gij-backup' -Destination 'HEAD' -Force
}
Set-Location -Path ".."
}
function Test-RunType()
{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string]$GitRepoFolder,
[Parameter(Mandatory=$true)]
[boolean]$IsFullRun
)
if( $IsFullRun ) {
Clear-GitRepo -GitRepoFolder $GitRepoFolder
} else {
Write-Output (Split-Path -Path $GitRepoFolder -Leaf)
}
}
git --version
Write-Output ""
$IsFullRunSet = $PSBoundParameters.Count -ge 1
if ( $IsFullRunSet ) {
Write-Output "Processing of Git repositories has been started. It may take several minutes so please be patient."
}
@(Get-ChildItem -Path "." -Directory -Force -Exclude "scripts","weblinking").ForEach({
Test-RunType -GitRepoFolder $_ -IsFullRun $IsFullRunSet
})
8b. ShellScript for Linux
#!/bin/bash
set -eo pipefail
clearGitRepo(){
cd "${1}"
echo ""
if [[ ! -f "config" ]]; then
echo "skip ${1} folder. It doesn't contain config."
cd ..
return 0
fi
echo "delete files from ${1} except 4 files: config, HEAD, repo.auto.json, repo.auto.json.gitforjira.lock"
find . -maxdepth 1 ! -name 'config' ! -name 'HEAD' ! -name 'repo.auto.json' ! -name 'repo.auto.json.gitforjira.lock' ! -name '.' ! -name '..' -exec rm --force --recursive {} ;
IS_HEAD_EXISTS=true
if [[ ! -f "HEAD" ]]; then
IS_HEAD_EXISTS=false
fi
if $IS_HEAD_EXISTS; then
echo "move 'HEAD' to 'HEAD-gij-backup' file"
mv --force HEAD HEAD-gij-backup
fi
dummyDir=non-existent-git-template-directory
echo "init a bare repository with the same config. Ignore the next warning if it says about '${dummyDir}'."
git init --bare --template=${dummyDir} --quiet
if $IS_HEAD_EXISTS; then
echo "restore 'HEAD' file"
mv --force HEAD-gij-backup HEAD
fi
cd ..
}
export -f clearGitRepo
dryOrNot(){
if [ -z "${1}" ]; then
cat <&0
else
xargs --max-args=1 --delimiter='n' bash -c 'clearGitRepo "${0}"'
fi
}
export -f dryOrNot
SCRIPT_DIRECTORY=$(basename $PWD)
if [ "${SCRIPT_DIRECTORY}" != "git-plugin" ]; then
echo "The script should be run in jira/home/data/git-plugin directory! Current directory is '$SCRIPT_DIRECTORY'."
exit 1
fi
git --version
echo ""
ls --directory */ | grep --invert-match --word-regexp --extended-regexp 'scripts/|weblinking/' | dryOrNot "${1}"
9. Review repository folders that will be cleared
Run the script without arguments in jira/home/data/git-plugin
folder to preview which repository folders are going to be cleared.
On Windows (in PowerShell console):
.clearDataInRepositories.ps1
On Linux (Terminal):
./clearDataInRepositories.sh
For mounted shared folders on the same server as Jira, you will need to unmount them first before proceeding to step 10.
If your Jira self-managed instance and Git repositories are on the same server – the git repositories are not affected since the script execution in step 10 will only process the folder where the cloned repositories reside (
jira/home/data/git-plugin
). It is dangerous if any of the folders is not a clone created by the GIJ plugin (i.e. if it’s the origin Git repository and it does not have other full clones).
10. Clear the repository clone folders
The script loops through all the folders in jira/home/data/git-plugin
(where the cloned repositories reside). For each folder, the contents are deleted such as git files structure (except several config files) and initializes a bare Git repository using the same configuration.
Execute the script with one argument in jira/home/data/git-plugin folder on behalf of the Jira user (read here):
On Windows (in PowerShell console):
.clearDataInRepositories.ps1 go
On Linux (Terminal):
./clearDataInRepositories.sh go
11. Disable the Remove Discard files setting
-
Go to General settings (Jira dashboard menu Git ➜ Manage repositories ➜ General settings [left sidebar]).
-
Scroll down to the Advanced settings and click to expand the hidden options.
-
For the Discard cloned files in Jira home directory setting, set it to Keep all cloned files. No storage savings. All features available.
12. Enable all the repositories/integrations back
On the Manage repositories page, click the Enable all to reconnect all integration repositories to Git Integration for Jira.
13. Perform a Reset all of the indexes
On the Manage repositories page, click on Indexing ➜ Reset all indexes.
14. Revert back the Generals settings
Change back the following settings to the saved values from step 5:
-
Repository indexing interval
-
Garbage collection and Revision validation interval
-
Git roll up issue tab
-
Set Git commits issue and project tabs
Also, enable the following settings to make GIJ repositories available again:
-
Tick on the Enable repository browser setting
-
Tick on the Show Git Integration panel on issue pages setting
-
Tick on the Enable Automation for Jira (A4J) triggers setting
-
Tick on the Enable JQL searching using commit information setting
15. Enable back webhooks
On the Manage repositories page, click Webhooks on the sidebar then click Enabled.
Related admin articles
Tips for Jira Administrators (Git Integration for Jira Data Center)
Migrating from Jira 8 to Jira 9 (Git Integration for Jira Data Center)
Upgrades and migrations within same server (Git Integration for Jira Data Center)
Migration to another server (Git Integration for Jira Data Center)
General Settings (Git Integration for Jira Data Center)
Recommended Jira memory settings (Git Integration for Jira Data Center)
Scheduling Jobs (Git Integration for Jira Data Center)
Plugin Data Storage (Git Integration for Jira Data Center)
Administration FAQ (Git Integration for Jira Data Center)
Indexing queue explainer (Git Integration for Jira Data Center)