Skip to content

Commit

Permalink
✨ Add check for detached head
Browse files Browse the repository at this point in the history
To avoid data loss, gut check if the head is detached on commands that modify the working tree
  • Loading branch information
julien040 committed Jan 26, 2023
1 parent 877e3fd commit a5188ee
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/controller/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ func Fix(cmd *cobra.Command, args []string) {

checkIfGitRepoInitialized(wd)

checkIfDetachedHead(wd)

print.Message("You made a mess, huh? Let's fix it!", print.None)
res, err := prompt.InputSelect("What do you want to fix?", options)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions src/controller/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ func Merge(cmd *cobra.Command, args []string) {
}
checkIfGitRepoInitialized(wd)

checkIfDetachedHead(wd)

// Check if working directory is clean
clean, err := executor.IsWorkTreeClean(wd)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions src/controller/revert.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ func Revert(cmd *cobra.Command, args []string) {
// Check if the current directory is a git repository
checkIfGitRepoInitialized(wd)

// Check if the repo is in a detached head state
checkIfDetachedHead(wd)

// Check if Git CLI is installed
checkIfGitInstalled()

Expand Down
2 changes: 2 additions & 0 deletions src/controller/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ func Save(cmd *cobra.Command, args []string) {
// Check if the current directory is a git repository
checkIfGitRepoInitialized(wd)

checkIfDetachedHead(wd)

// Check if the user config is set
verifUserConfig(wd)

Expand Down
3 changes: 3 additions & 0 deletions src/controller/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ func Switch(cmd *cobra.Command, args []string) {
// Check if the current directory is a git repository
checkIfGitRepoInitialized(wd)

// Check if the HEAD is detached
checkIfDetachedHead(wd)

// Check if there are uncommitted changes
clean, err := executor.IsWorkTreeClean(wd)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions src/controller/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ func Sync(cmd *cobra.Command, args []string) {
// Check if the repository is initialized
checkIfGitRepoInitialized(wd)

// Check if the head is detached
checkIfDetachedHead(wd)

// Check if there is uncommited changes
// If there is, we ask the user to commit them
// If there is not, we exit
Expand Down
2 changes: 2 additions & 0 deletions src/controller/undo.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func Undo(cmd *cobra.Command, args []string) {
}
checkIfGitRepoInitialized(wd)

checkIfDetachedHead(wd)

checkIfGitInstalled()

if len(args) == 0 {
Expand Down

0 comments on commit a5188ee

Please sign in to comment.