Skip to content

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

Open
SimonThalvorsen wants to merge 2 commits into
cfengine:masterfrom
SimonThalvorsen:CFE-4700
Open

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

Conversation

@SimonThalvorsen

Copy link
Copy Markdown
Contributor

No description provided.

…nputs

Ticket: ENT-14408
Changelog: Title

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

@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.

Ticket: CFE-4700
Changelog: Title

Signed-off-by: Simon Halvorsen <simon.halvorsen@northern.tech>
@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
pass


def copytree_merge(src, dst, ignore=None):

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.

You can mention in the commit message that this was copied from cf-remote

Comment thread cfbs/commands.py
@@ -1208,9 +1211,27 @@ def analyze_command(

@cfbs_command("convert")
def convert_command(non_interactive=False, offline=False):

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.

We should really think about refactoring this function (400 lines of spagetti).

Comment thread cfbs/commands.py
# a pre-existing `.git`-directory was moved or removed below,
# so restore the original directory (including its `.git`) from
# the backup we took before touching anything
print("Restoring '%s' to its original state..." % path_string)

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.

Would be helpful for the sake readability to pass this string as an argument to the function.

Comment thread cfbs/commands.py
Comment on lines +1261 to +1262
# back up the directory before doing anything destructive to it, so
# a failure can restore it to its original state instead of leaving it half-converted

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.

Maybe you can move this logic to a separate function so that this function does not get even longer. And avoid defining it inside this function like the others. It's problematic, because they have access to variables in the outer scope. Which can have unintended side effects that are really hard to debug.

Comment thread cfbs/commands.py
Comment on lines +1231 to +1232
cp(backup_dir, path_string)
rm(backup_dir, missing_ok=True)

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.

Should probably sync the directory after cp and before rm. Otherwise the files disappear in e.g. a power outage

Comment thread cfbs/commands.py
non_interactive,
)
except:
cfbs_convert_cleanup()

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.

Maybe we should check these things up front before doing anything?

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.

3 participants