Skip to content
Open
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
7 changes: 4 additions & 3 deletions gitops/config.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package gitops

import (
"os"
"os/exec"
"strings"
)

func IsGitRepositoryCurrentDir() bool {
_, err := os.Stat(".git")
// IsGitRepository checks if the current working directory is inside a Git repository.
func IsGitRepository() bool {
cmd := exec.Command("git", "rev-parse", "--is-inside-work-tree")
err := cmd.Run()
return err == nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/appcore/hooks_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ func runHooksStatus(c *cli.Context) error {

// isGitRepository checks if current directory is in a git repository
func isGitRepository() bool {
return gitops.IsGitRepositoryCurrentDir()
return gitops.IsGitRepository()
}

// installHook installs or updates a hook with lrc managed section
Expand Down
24 changes: 24 additions & 0 deletions tests/worktree-hooks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,30 @@ for hook in pre-commit prepare-commit-msg commit-msg post-commit; do
assert_file_not_contains_or_missing "local worktree uninstall removes managed section: $hook" "# BEGIN lrc managed section - DO NOT EDIT" "$WT_LOCAL_HOOKS_DIR/$hook"
done

bold ""
bold "══ Local Hook Management In Subdirectories ════════════════════"

mkdir -p "$LOCAL_REPO_DIR/subdir"
cd "$LOCAL_REPO_DIR/subdir"

lrc hooks install --local >/dev/null
STATUS_OUTPUT_SUBDIR="$(lrc hooks status 2>&1)"

for hook in pre-commit prepare-commit-msg commit-msg post-commit; do
assert_file_contains "subdirectory install adds managed section: $hook" "# BEGIN lrc managed section - DO NOT EDIT" "$WT_LOCAL_HOOKS_DIR/$hook"
done

assert_contains "subdirectory status reports common-dir hooks path" "hooksPath: $WT_LOCAL_HOOKS_DIR" "$STATUS_OUTPUT_SUBDIR"
assert_contains "subdirectory status reports worktree root" "repo: $LOCAL_REPO_DIR" "$STATUS_OUTPUT_SUBDIR"

lrc hooks uninstall --local >/dev/null

for hook in pre-commit prepare-commit-msg commit-msg post-commit; do
assert_file_not_contains_or_missing "subdirectory uninstall removes managed section: $hook" "# BEGIN lrc managed section - DO NOT EDIT" "$WT_LOCAL_HOOKS_DIR/$hook"
done

cd "$LOCAL_REPO_DIR"

bold ""
bold "══ Results ═══════════════════════════════════════════════════"
TOTAL=$((PASS + FAIL))
Expand Down