• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CyberShadow / aconfmgr / 734

23 Nov 2026 09:31PM UTC coverage: 80.637% (-10.7%) from 91.339%
734

push

github

CyberShadow
diff: Exit with status 1 if differences were found

Like diff itself, so that scripts can use 'aconfmgr diff' to check
whether the system's files match the configuration (discussions #128
and #242). Previously, the exit status was always 0 unless an error
occurred.

The original version of a packaged file is now saved to a temporary
file instead of being piped into diff, as the pipeline ran the
function which examines diff's exit status in a subshell.

This is a breaking change for scripts which assume that a non-zero
status from 'aconfmgr diff' indicates an error.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

41 of 46 new or added lines in 8 files covered. (89.13%)

435 existing lines in 25 files now uncovered.

3444 of 4271 relevant lines covered (80.64%)

301.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.11
/src/diff.bash
1
# diff.bash
2

3
# This file contains the implementation of aconfmgr's 'diff' command.
4

5
# Run diff, and record whether it found any differences
6
# (in AconfDiff's found_differences).
7
function AconfDiffRun() {
8
        local status=0
5 ✔
9
        "${diff_args[@]}" "$@" 1>&2 || status=$?
8 ✔
10
        case "$status" in
5 ✔
11
                0)
12
                        ;;
13
                1)
14
                        found_differences=true
3 ✔
15
                        ;;
16
                *)
NEW
17
                        FatalError 'diff exited with status %d.\n' "$status"
×
18
                        ;;
19
        esac
20
}
21

22
# Like AconfDiffRun, but substitutes the original version
23
# of the given file from its package for "-" in the arguments.
24
function AconfDiffRunWithOriginal() {
25
        local file=$1
2 ✔
26
        shift
2 ✔
27

28
        local package
2 ✔
29
        package=$(pacman --quiet --query --owns "$file")
4 ✔
30

31
        # Not piped into diff directly, as that would run AconfDiffRun in a subshell.
32
        local original="$tmp_dir"/diff-original
2 ✔
33
        AconfGetPackageOriginalFile "$package" "$file" > "$original"
2 ✔
34
        AconfDiffRun "$@" < "$original"
2 ✔
35
        rm "$original"
2 ✔
36
}
37

38
function AconfDiff() {
39
        AconfCompileOutput
5 ✔
40
        AconfCompileSystem
5 ✔
41

42
        local diff_args=("${diff_opts[@]}" --unified --recursive --no-dereference)
10 ✔
43

44
        local found_path=false
5 ✔
45
        local found_differences=false
5 ✔
46
        local arg
5 ✔
47
        for arg in "${aconfmgr_action_args[@]}"
5 ✔
48
        do
49
                if [[ "$arg" == -* ]]
5 ✔
50
                then
51
                        # Assume this is an option to be passed to diff (such as -a)
52
                        diff_args+=("$arg")
53
                elif [[ "$arg" == /* ]]
5 ✔
54
                then
55
                        # Show diff for this path
56
                        if [[ ! -e "$system_dir"/files"$arg" ]] && grep -qFx "$arg" "$tmp_dir"/owned-files
6 ✔
57
                        then
58
                                # File is owned by a package - retrieve package version
59
                                AconfDiffRunWithOriginal "$arg" - "$output_dir"/files"$arg"
1 ✔
60
                        elif [[ ! -e "$output_dir"/files"$arg" ]] && grep -qFx "$arg" "$tmp_dir"/owned-files
5 ✔
61
                        then
62
                                AconfDiffRunWithOriginal "$arg" "$system_dir"/files"$arg" -
1 ✔
63
                        else
64
                                AconfDiffRun "$system_dir"/files"$arg" "$output_dir"/files"$arg"
3 ✔
65
                        fi
66
                        found_path=true
5 ✔
67
                else
68
                        FatalError 'Don'\''t know what to do with diff argument: %s\n' "$(Color Y "%q" "$arg")"
×
69
                fi
70
        done
71

72
        if ! $found_path
5 ✔
73
        then
74
                # This is currently too messy:
75
                if false
×
76
                then
77
                        AconfDiffRun "$system_dir" "$output_dir"
×
78
                fi
79

80
                # For now, reserve argument-less invocation:
81
                FatalError 'Specify an absolute path to diff (or %s to diff all files).\n' "$(Color C /)"
×
82
        fi
83

84
        # Like diff, exit with status 1 if there were any differences.
85
        if $found_differences
5 ✔
86
        then
87
                Exit 1
3 ✔
88
        fi
89
}
90

91
: # include in coverage
98 ✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc