Skip to content

Instantly share code, notes, and snippets.

@darkounet
Created September 12, 2016 12:24
Show Gist options
  • Save darkounet/50f554cba55338b4093baa68265955db to your computer and use it in GitHub Desktop.
Save darkounet/50f554cba55338b4093baa68265955db to your computer and use it in GitHub Desktop.
Gitlab fix error import/export Pipeline & protected Branches
#!/bin/bash
#
#
# Thanks to https://gist.github.com/hilbix/3e7dbe86f4e155a369a67293e8511e73
# Fix Failed to replace pipelines because one or more of the new records could not be saved.
# Fix Failed to replace protected_branches because one or more of the new records could not be saved.
# Usage : ./clean_gitlab_export.sh 2016-09-12_14-09-835_GROUP_project_export.tar.gz
Project=$1
if [[ -s "$Project" ]]; then
echo $Project exist
else
exit 1
fi
tmp_folder=$( mktemp -d )
tar Cxfz "$tmp_folder" "$Project"
test -s "$tmp_folder/VERSION"
test -s "$tmp_folder/project.bundle"
test -s "$tmp_folder/project.json"
python - "$tmp_folder/project.json" <<'EOF'
import json
import sys
with open(sys.argv[1]) as r:
data = json.load(r)
data['pipelines'] = []
data['protected_branches'] = []
with open(sys.argv[1], 'w') as w:
json.dump(data, w, separators=(',',':'))
EOF
tar Ccfz "$tmp_folder" "$Project.fixed" .
echo "$Project.fixed written"
@firoz2456
Copy link

Thanks for the shell script. It really help us

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment