Skip to content

Commit 922dee0

Browse files
committed
bootlinux: add git dirty check before cloning
Add preliminary checks to detect if the git tree has local modifications before attempting to clone or update. This provides clearer error messages when git operations fail due to uncommitted changes. The issue was discovered when prior kdevops commits inadvertently modified files in the linux kernel tree through overly broad make style operations. When git clone/update encounters a dirty tree, it fails with a generic "Local modifications exist" error that doesn't guide users on resolution. Each build method now checks for dirty trees: - 9p.yml: Checks bootlinux_9p_host_path on control node - targets.yml: Checks target_linux_dir_path on target nodes - builder.yml: Checks target_linux_dir_path on builder nodes The error messages provide clear resolution steps: 1. Commit or stash changes 2. Hard reset the tree 3. Remove the directory for a fresh clone This change improves debugging by: - Failing fast with actionable error messages - Showing which files are modified - Providing multiple resolution options - Preventing confusing git errors downstream Generated-by: Claude AI Signed-off-by: Luis Chamberlain <[email protected]>
1 parent 178e0fb commit 922dee0

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed

playbooks/roles/bootlinux/tasks/build/9p.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,49 @@
7373
run_once: true
7474
delegate_to: localhost
7575

76+
- name: Check if target directory exists for dirty check
77+
stat:
78+
path: "{{ bootlinux_9p_host_path }}"
79+
register: git_dir_stat
80+
run_once: true
81+
delegate_to: localhost
82+
when:
83+
- not bootlinux_tree_set_by_cli|bool
84+
85+
- name: Check if git tree is dirty
86+
command: "git -C {{ bootlinux_9p_host_path }} status --porcelain"
87+
register: git_status
88+
changed_when: false
89+
failed_when: false
90+
run_once: true
91+
delegate_to: localhost
92+
when:
93+
- not bootlinux_tree_set_by_cli|bool
94+
- git_dir_stat.stat.exists
95+
- git_dir_stat.stat.isdir
96+
97+
- name: Fail if git tree has local modifications
98+
fail:
99+
msg: |
100+
Local modifications exist in the destination: {{ bootlinux_9p_host_path }}
101+
102+
The git tree is dirty with uncommitted changes. This prevents safe git operations.
103+
104+
To resolve this, you can:
105+
1. Commit or stash your changes in {{ bootlinux_9p_host_path }}
106+
2. Reset the tree with: git -C {{ bootlinux_9p_host_path }} reset --hard
107+
3. Remove the directory and let kdevops clone fresh: rm -rf {{ bootlinux_9p_host_path }}
108+
109+
Modified files:
110+
{{ git_status.stdout }}
111+
when:
112+
- not bootlinux_tree_set_by_cli|bool
113+
- git_dir_stat.stat.exists
114+
- git_dir_stat.stat.isdir
115+
- git_status.stdout | length > 0
116+
run_once: true
117+
delegate_to: localhost
118+
76119
- name: git clone {{ target_linux_tree }} on the control node
77120
git:
78121
repo: "{{ target_linux_git }}"

playbooks/roles/bootlinux/tasks/build/builder.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,39 @@
3131
when:
3232
- ref_check.rc != 0
3333

34+
- name: Check if target directory exists for dirty check
35+
stat:
36+
path: "{{ target_linux_dir_path }}"
37+
register: git_dir_stat
38+
39+
- name: Check if git tree is dirty
40+
command: "git -C {{ target_linux_dir_path }} status --porcelain"
41+
register: git_status
42+
changed_when: false
43+
failed_when: false
44+
when:
45+
- git_dir_stat.stat.exists
46+
- git_dir_stat.stat.isdir
47+
48+
- name: Fail if git tree has local modifications
49+
fail:
50+
msg: |
51+
Local modifications exist in the destination: {{ target_linux_dir_path }}
52+
53+
The git tree is dirty with uncommitted changes. This prevents safe git operations.
54+
55+
To resolve this, you can:
56+
1. Commit or stash your changes in {{ target_linux_dir_path }}
57+
2. Reset the tree with: git -C {{ target_linux_dir_path }} reset --hard
58+
3. Remove the directory and let kdevops clone fresh: rm -rf {{ target_linux_dir_path }}
59+
60+
Modified files:
61+
{{ git_status.stdout }}
62+
when:
63+
- git_dir_stat.stat.exists
64+
- git_dir_stat.stat.isdir
65+
- git_status.stdout | length > 0
66+
3467
- name: Clone {{ target_linux_tree }}
3568
ansible.builtin.git:
3669
repo: "{{ target_linux_git }}"

playbooks/roles/bootlinux/tasks/build/targets.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,39 @@
3232
when:
3333
- ref_check.rc != 0
3434

35+
- name: Check if target directory exists for dirty check
36+
stat:
37+
path: "{{ target_linux_dir_path }}"
38+
register: git_dir_stat
39+
40+
- name: Check if git tree is dirty
41+
command: "git -C {{ target_linux_dir_path }} status --porcelain"
42+
register: git_status
43+
changed_when: false
44+
failed_when: false
45+
when:
46+
- git_dir_stat.stat.exists
47+
- git_dir_stat.stat.isdir
48+
49+
- name: Fail if git tree has local modifications
50+
fail:
51+
msg: |
52+
Local modifications exist in the destination: {{ target_linux_dir_path }}
53+
54+
The git tree is dirty with uncommitted changes. This prevents safe git operations.
55+
56+
To resolve this, you can:
57+
1. Commit or stash your changes in {{ target_linux_dir_path }}
58+
2. Reset the tree with: git -C {{ target_linux_dir_path }} reset --hard
59+
3. Remove the directory and let kdevops clone fresh: rm -rf {{ target_linux_dir_path }}
60+
61+
Modified files:
62+
{{ git_status.stdout }}
63+
when:
64+
- git_dir_stat.stat.exists
65+
- git_dir_stat.stat.isdir
66+
- git_status.stdout | length > 0
67+
3568
- name: git clone {{ target_linux_tree }} on the target nodes
3669
git:
3770
repo: "{{ target_linux_git }}"

0 commit comments

Comments
 (0)