Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/dotctl/actions/activator.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ def apply(props: ActivatorProps) -> None:
checkout_branch(repo, profile)
log(f"Switched to profile: {profile}")
else:
log(f"Profile {profile} is not available.")
log(f"Profile {profile} is not available.")
return

config = conf_reader(config_file=Path(app_config_file))

if pull_changes(repo):
log("Pulled latest changes from cloud successfully.")
log("Pulled latest changes from cloud successfully.")

if not props.skip_hooks and not props.skip_pre_hooks:
run_hooks(
Expand Down Expand Up @@ -95,4 +95,4 @@ def apply(props: ActivatorProps) -> None:
ignore_errors=props.ignore_hook_errors,
timeout=props.hooks_timeout,
)
log("✅ Profile saved successfully!")
log("✅ Profile applied successfully!")
4 changes: 2 additions & 2 deletions src/dotctl/actions/creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def create(props: CreatorProps):

_, _, _, all_profiles = get_repo_branches(repo)
if props.profile in all_profiles:
log(f"Profile '{props.profile}' already exists.")
log(f"Profile '{props.profile}' already exists.")
return
if props.env or props.config:
if props.config is not None and isinstance(props.config, str):
Expand Down Expand Up @@ -86,4 +86,4 @@ def create(props: CreatorProps):
else:
push_existing_branch(repo=repo)

log(f"Profile '{props.profile}' created and activated successfully.")
log(f"Profile '{props.profile}' created and activated successfully.")
4 changes: 2 additions & 2 deletions src/dotctl/actions/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def exporter(props: ExporterProps) -> None:
checkout_branch(repo, profile)
log(f"Switched to profile: {profile}")
else:
log(f"Profile '{profile}' not found.")
log(f"Profile '{profile}' not found.")
return

# Copy profile files
Expand Down Expand Up @@ -117,7 +117,7 @@ def exporter(props: ExporterProps) -> None:
shutil.move(archive_file, export_profile_path.with_suffix(__EXPORT_EXTENSION__))

log(
f"Successfully exported to {export_profile_path.with_suffix(__EXPORT_EXTENSION__)}"
f"Successfully exported to {export_profile_path.with_suffix(__EXPORT_EXTENSION__)}"
)
finally:
shutil.rmtree(export_profile_path, ignore_errors=True)
10 changes: 5 additions & 5 deletions src/dotctl/actions/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ class ImporterProps:
def importer(props: ImporterProps) -> None:
log("Importing profile...")
if not props.profile:
log("No profile specified")
log("No profile specified")
return

profile_path = Path(props.profile)

if not is_zipfile(profile_path):
log("Invalid Profile file")
log("Invalid Profile file")
return

if profile_path.suffix != __EXPORT_EXTENSION__:
log("Unsupported Profile file")
log("Unsupported Profile file")
return

# Setup variables
Expand All @@ -62,7 +62,7 @@ def importer(props: ImporterProps) -> None:
# Create profile branch
_, remote_profiles, active_profile, all_profiles = get_repo_branches(repo)
if profile_name in all_profiles:
log(f"Profile '{profile_name}' already exists")
log(f"Profile '{profile_name}' already exists")
return

create_branch(repo=repo, branch=profile_name)
Expand Down Expand Up @@ -127,7 +127,7 @@ def importer(props: ImporterProps) -> None:
checkout_branch(repo, active_profile)
log(f"Switched back to profile: {active_profile}")

log("Profile Imported successfully!")
log("Profile Imported successfully!")

finally:
shutil.rmtree(temp_profile_dir, ignore_errors=True)
2 changes: 1 addition & 1 deletion src/dotctl/actions/initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def initialise(props: InitializerProps):
log("Initializing...")

if is_git_repo(props.dest):
log("Repository already initialized.")
log("Repository already initialized.")
return

if props.git_url:
Expand Down
2 changes: 1 addition & 1 deletion src/dotctl/actions/puller.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def pull(props: PullerProps):
try:
changes = pull_changes(repo)
if changes is None:
log(" Profile already up to date.")
log("ℹ️ Profile already up to date.")
elif changes:
log("✅ Pulled latest changes successfully.")

Expand Down
14 changes: 7 additions & 7 deletions src/dotctl/actions/remover.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def remove(props: RemoverProps):

try:
if repo.bare:
print("The repository is bare. No profiles available.")
print("The repository is bare. No profiles available.")
return

if props.fetch:
Expand All @@ -54,16 +54,16 @@ def remove(props: RemoverProps):
# Delete local branch if it exists
if profile in local_profiles:
delete_local_branch(repo, profile)
log(f"Local profile '{profile}' removed successfully.")
log(f"Local profile '{profile}' removed successfully.")
else:
log(f"Profile '{profile}' does not exist locally.")
log(f"Profile '{profile}' does not exist locally.")

# Delete remote branch if it exists
if is_remote_repo(repo=repo):
if profile in remote_profiles:
if props.no_confirm:
delete_remote_branch(repo, profile)
log(f"Remote profile '{profile}' removed successfully.")
log(f"Remote profile '{profile}' removed successfully.")
return
else:
# Ask for confirmation
Expand All @@ -72,13 +72,13 @@ def remove(props: RemoverProps):
)
if confirm.lower() == "y":
delete_remote_branch(repo, profile)
log(f"Remote profile '{profile}' removed successfully.")
log(f"Remote profile '{profile}' removed successfully.")
return
else:
log("Remote profile deletion aborted by user.")
log("🛑 Remote profile deletion aborted by user.")
return

log(f"Profile '{profile}' does not exist on cloud.")
log(f"Profile '{profile}' does not exist on cloud.")

except Exception as e:
raise Exception(f"Unexpected error: {e}")
4 changes: 2 additions & 2 deletions src/dotctl/actions/saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def save(props: SaverProps) -> None:
create_branch(repo=repo, branch=profile)
log(f"Profile '{profile}' created and activated successfully.")
if pull_changes(repo):
log("Pulled latest changes from cloud successfully.")
log("Pulled latest changes from cloud successfully.")

config = conf_reader(config_file=Path(app_config_file))

Expand Down Expand Up @@ -97,4 +97,4 @@ def save(props: SaverProps) -> None:
push_existing_branch(repo=repo)
log("✅ Profile saved successfully!")
else:
log("No changes detected!")
log("ℹ️ No changes detected!")
10 changes: 5 additions & 5 deletions src/dotctl/actions/switcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def switch(props: SwitcherProps):
repo = get_repo(props.profile_dir)

if repo.bare:
log("The repository is bare. No Profile available.")
log("The repository is bare. No Profile available.")
sys.exit(1)

local_profiles, remote_profiles, active_profile, all_profiles = get_repo_branches(
Expand All @@ -52,7 +52,7 @@ def switch(props: SwitcherProps):
)

if profile_name == active_profile:
log(f"Already on the current profile: {profile_name}")
log(f"ℹ️ Already on the current profile: {profile_name}")
return

# Fetch remote branches if requested
Expand All @@ -64,10 +64,10 @@ def switch(props: SwitcherProps):
if profile_name in local_profiles:
# Checkout local branch
checkout_branch(repo, profile_name)
log(f"Switched to profile: {profile_name}")
log(f"Switched to profile: {profile_name}")
elif profile_name in remote_profiles:
# Checkout and track remote branch automatically
checkout_branch(repo, profile_name)
log(f"Downloaded and switched to new profile from cloud: {profile_name}")
log(f"Downloaded and switched to new profile from cloud: {profile_name}")
else:
log(f"Profile '{profile_name}' is not available in the repository.")
log(f"Profile '{profile_name}' is not available in the repository.")
8 changes: 4 additions & 4 deletions src/dotctl/actions/wiper.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def wipe(props: WiperProps):
try:
if props.no_confirm:
shutil.rmtree(props.profile_dir)
log(f"Profile directory '{props.profile_dir}' removed successfully.")
log(f"🗑️ Profile directory '{props.profile_dir}' removed successfully.")
return
else:
# Ask for confirmation
Expand All @@ -42,12 +42,12 @@ def wipe(props: WiperProps):
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
backup_dir = f"{props.profile_dir}_backup_{timestamp}"
shutil.copytree(props.profile_dir, backup_dir)
log(f"Backup directory '{backup_dir}' created successfully.")
log(f"💾 Backup directory '{backup_dir}' created successfully.")
shutil.rmtree(props.profile_dir)
log(f"Profile directory '{props.profile_dir}' removed successfully.")
log(f"🗑️ Profile directory '{props.profile_dir}' removed successfully.")
return
else:
log("Profile wipe process aborted by user.")
log("🛑 Profile wipe process aborted by user.")
return
except Exception as e:
raise Exception(f"Unexpected error: {e}")
19 changes: 11 additions & 8 deletions src/dotctl/handlers/git_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,26 +228,29 @@ def push_new_branch(repo: Repo) -> None:

def pull_changes(repo: Repo) -> bool | None:
is_remote, origin = is_remote_repo(repo)
if not is_remote or origin is None:
log("Warning: Skipping pull. This is not a remote repository.")
if not is_remote or not origin:
log("Warning: Skipping pull from remote repository! Not a remote repo.")
return None

if repo.bare:
raise Exception("Error: The repository is bare. Cannot pull changes.")

git_fetch(repo)

current_branch = repo.active_branch.name
local_commit = repo.commit(current_branch)
remote_commit = repo.commit(f"origin/{current_branch}")
_, remote_profiles, active_profile, _ = get_repo_branches(repo)

if active_profile not in remote_profiles:
return None

local_commit = repo.commit(active_profile)
remote_commit = repo.commit(f"origin/{active_profile}")

if local_commit.hexsha == remote_commit.hexsha:
return None

log("📥 Update found:")
for commit in repo.iter_commits(f"{current_branch}..origin/{current_branch}"):
log(f" - {commit.summary} ({commit.hexsha[:7]})")

for commit in repo.iter_commits(f"{active_profile}..origin/{active_profile}"):
log(f" - {commit.summary} ({commit.hexsha[:7]})")
origin.pull()
return True

Expand Down