Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1#!/usr/bin/env bash2# Copyright (c) The Bitcoin Core developers3# Distributed under the MIT software license, see the accompanying4# file COPYING or https://opensource.org/license/mit.5export LC_ALL=C.UTF-86set -o errexit -o pipefail8# Source the common prelude, which:9# 1. Checks if we're at the top directory of the Bitcoin Core repository10# 2. Defines a few common functions and variables11#12# shellcheck source=libexec/prelude.bash13source "$(dirname "${BASH_SOURCE[0]}")/libexec/prelude.bash"15# Parse supported args16FORCE=017if [[ $* == "--force" ]]; then18FORCE=119elif [ $# != 0 ]; then20echo "Script only takes optional --force arg."21exit 122fi24###################25## Sanity Checks ##26###################28################29# Required non-builtin commands should be invokable30################32check_tools cat mkdir make git guix35#############36## Clean ##37#############39# Usage: under_dir MAYBE_PARENT MAYBE_CHILD40#41# If MAYBE_CHILD is a subdirectory of MAYBE_PARENT, print the relative path42# from MAYBE_PARENT to MAYBE_CHILD. Otherwise, return 1 as the error code.43#44# NOTE: This does not perform any symlink-resolving or path canonicalization.45#46under_dir() {47local path_residue48path_residue="${2##"${1}"}"49if [ -z "$path_residue" ] || [ "$path_residue" = "$2" ]; then50return 151else52echo "$path_residue"53fi54}56# Usage: dir_under_git_root MAYBE_CHILD57#58# If MAYBE_CHILD is under the current git repository and exists, print the59# relative path from the git repository's top-level directory to MAYBE_CHILD,60# otherwise, exit with an error code.61#62dir_under_git_root() {63local rv64rv="$(under_dir "$(git_root)" "$1")"65[ -n "$rv" ] && echo "$rv"66}68shopt -s nullglob69found_precious_dirs_files=( "${version_base_prefix}"*/"${var_base_basename}/precious_dirs" ) # This expands to an array of directories...70shopt -u nullglob72exclude_flags=()74for precious_dirs_file in "${found_precious_dirs_files[@]}"; do75# Make sure the precious directories (e.g. SOURCES_PATH, BASE_CACHE, SDK_PATH)76# are excluded from git-clean77echo "Found precious_dirs file: '${precious_dirs_file}'"79# Exclude the precious_dirs file itself80if dirs_file_exclude_fragment=$(dir_under_git_root "$(dirname "$precious_dirs_file")"); then81exclude_flags+=( --exclude="${dirs_file_exclude_fragment}/precious_dirs" )82fi84# Read each 'name=dir' pair from the precious_dirs file85while IFS='=' read -r name dir; do86# Add an exclusion flag if the precious directory is under the git root.87if under=$(dir_under_git_root "$dir"); then88echo "Avoiding ${name}: ${under}"89exclude_flags+=( --exclude="$under" )90fi91done < "$precious_dirs_file"92done94if [[ $FORCE == 0 ]]; then95git clean -nxdff "${exclude_flags[@]}"97read -p "Proceed? (y/n) " -r98if [[ ! $REPLY =~ ^[Yy]$ ]]; then99echo "Aborted."100exit 1101fi102fi104git clean -xdff "${exclude_flags[@]}"
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.