Skip to content

ENT-14408, CFE-4700: Added option to retain git history when using cfbs convert & Replaced cp/rsync with shutil.copy - #332

Merged
larsewi merged 2 commits into
cfengine:masterfrom
SimonThalvorsen:CFE-4700
Aug 21, 2026
Merged

ENT-14408, CFE-4700: Added option to retain git history when using cfbs convert & Replaced cp/rsync with shutil.copy#332
larsewi merged 2 commits into
cfengine:masterfrom
SimonThalvorsen:CFE-4700

Conversation

@SimonThalvorsen

Copy link
Copy Markdown
Contributor

No description provided.

@olehermanse olehermanse left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you're moving the existing repo into a .old directory? And then adding that to gitignore? That's not what we mean by retain, we want the new project (after conversion) to have (retain) the git history of what happened before conversion.

Essentially, we want cfbs convert to do something equivalent to what I've done in a shell here;

$ cd my-masterfiles
$ ls -a
.git/ promises.cf update.cf [...]
$ mkdir ./my-masterfiles # We could prompt about what the name of the subdirectory should be
$ mv promises.cf update.cf [...] ./my-masterfiles
$ git add ./my-masterfiles
$ git commit -m "Moved CFEngine policy related files to subdirectory to convert this repository into a CFEngine Build project"
$ cfbs convert # (init + add +++)

The existing code (in cfbs convert / init) might not work correctly when .git already exists, in that case we need to fix that.

@SimonThalvorsen

Copy link
Copy Markdown
Contributor Author

Looks like you're moving the existing repo into a .old directory? And then adding that to gitignore? That's not what we mean by retain, we want the new project (after conversion) to have (retain) the git history of what happened before conversion.

Essentially, we want cfbs convert to do something equivalent to what I've done in a shell here;

$ cd my-masterfiles
$ ls -a
.git/ promises.cf update.cf [...]
$ mkdir ./my-masterfiles # We could prompt about what the name of the subdirectory should be
$ mv promises.cf update.cf [...] ./my-masterfiles
$ git add ./my-masterfiles
$ git commit -m "Moved CFEngine policy related files to subdirectory to convert this repository into a CFEngine Build project"
$ cfbs convert # (init + add +++)

The existing code (in cfbs convert / init) might not work correctly when .git already exists, in that case we need to fix that.

Yeah, that makes much more sense now that I think about it. Originally I thought it more as a 'backup' inside the the build-project, but I see what you mean.

@SimonThalvorsen
SimonThalvorsen force-pushed the CFE-4700 branch 2 times, most recently from 488603b to a8b63ac Compare August 18, 2026 10:54
@larsewi larsewi changed the title Added option to retain git history when using cfbs convert & Replaced cp/rsync with shutil.copy ENT-14408, CFE-4700: Added option to retain git history when using cfbs convert & Replaced cp/rsync with shutil.copy Aug 18, 2026

@larsewi larsewi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some smaller nits

Comment thread cfbs/utils.py
Comment thread cfbs/commands.py Outdated
Comment thread cfbs/commands.py Outdated
Comment thread cfbs/commands.py Outdated
Comment thread cfbs/commands.py Outdated
Comment thread cfbs/commands.py Outdated
…nputs

Copied the copytree-function from cf-remote (3.5 compliant version of
copytree w/ dirs_exist_ok)
Ticket: ENT-14408
Changelog: Title

Signed-off-by: Simon Halvorsen <simon.halvorsen@northern.tech>
@SimonThalvorsen
SimonThalvorsen force-pushed the CFE-4700 branch 2 times, most recently from ffdc25d to d65c956 Compare August 20, 2026 10:41
Additionally did a full refactor of the convert_command (~400loc) into
smaller functions for each step in the conversion process

Ticket: CFE-4700
Changelog: Title

Signed-off-by: Simon Halvorsen <simon.halvorsen@northern.tech>

@larsewi larsewi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀 I kind of envisioned it to commit the step-by-step conversion on top of the original commit history when choosing to retain the git history. But I guess that could be another future 3rd option. (Edit: it appears that this is exactly what it does)

Thanks for refactoring this mess! I trust you have thoroughly tested this.

Comment thread cfbs/commands.py
Comment on lines +1225 to +1227
self.backup_dir = (
None
) # type: Optional[str] # temp copy taken before messing with the project

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these parenthesis a Black artifact?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup

@larsewi
larsewi merged commit 3357f7d into cfengine:master Aug 21, 2026
24 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants