Skip to content

Commit

Permalink
Merge pull request #9 from julien040/feature
Browse files Browse the repository at this point in the history
Add additionnal infos in whereami and status | Prevent bug in merge
  • Loading branch information
julien040 authored Feb 1, 2023
2 parents 9723267 + 6bc52d8 commit cdb4b80
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
16 changes: 11 additions & 5 deletions src/controller/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ func Merge(cmd *cobra.Command, args []string) {

}

currentBranch, err := executor.GetCurrentBranch(wd)
if err != nil {
exitOnError("Sorry, I can't get the current branch 😢", err)
}

var branch string

askForBranch := func() string {
Expand Down Expand Up @@ -72,6 +77,12 @@ func Merge(cmd *cobra.Command, args []string) {
if err != nil {
exitOnError("Sorry, I can't check if the branch exists 😢", err)
}

if branch == currentBranch {
print.Message("You can't merge %s into itself 😢", print.Error, branch)
branch = askForBranch()
}

// If not, ask him
if !exists {
print.Message(fmt.Sprintf("I'm sorry, but the branch %s doesn't exist 😢", branch), print.Error)
Expand All @@ -82,11 +93,6 @@ func Merge(cmd *cobra.Command, args []string) {
branch = askForBranch()
}

currentBranch, err := executor.GetCurrentBranch(wd)
if err != nil {
exitOnError("Sorry, I can't get the current branch 😢", err)
}

// Prompt the user to sync his changes
// If the repo is not sync with the upstream, the pull request will not have the latest changes
promptUserToSync := func() {
Expand Down
18 changes: 14 additions & 4 deletions src/controller/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,22 @@ func Status(cmd *cobra.Command, args []string) {

checkIfGitRepoInitialized(wd)

/* --------------------------- Get current branch --------------------------- */
branch, err := executor.GetCurrentBranch(wd)
// Check if the head is detached
detached, err := executor.IsDetachedHead(wd)
if err != nil {
exitOnError("Sorry, I can't get the current branch 😢", err)
exitOnError("Sorry, I can't check if the HEAD is detached 😢", err)
}

/* --------------------------- Get current branch --------------------------- */
if detached {
fmt.Println("HEAD is detached (lookout mode)")
} else {
branch, err := executor.GetCurrentBranch(wd)
if err != nil {
exitOnError("Sorry, I can't get the current branch 😢", err)
}
fmt.Printf("On branch %s\n", color.HiGreenString(branch))
}
fmt.Printf("On branch %s\n", color.HiGreenString(branch))

/* --------------------------- Get status of files -------------------------- */
status, err := executor.GetStatus(wd)
Expand Down
10 changes: 10 additions & 0 deletions src/controller/whereami.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ func WhereAmI(cmd *cobra.Command, args []string) {
exitOnError("Sorry, I can't get the current branch 😢", err)
}

// Check if the head is detached
detached, err := executor.IsDetachedHead(wd)
if err != nil {
exitOnError("Sorry, I can't check if the HEAD is detached 😢", err)
}
if detached {
fmt.Printf("HEAD is detached (lookout mode) at %s\n", color.HiGreenString(hash))
return
}

fmt.Printf("HEAD is at %s on branch %s\n", color.HiGreenString(hash), color.HiGreenString(branch))

}

0 comments on commit cdb4b80

Please sign in to comment.