@@ -312,12 +312,35 @@ public struct Branch { // swiftlint:disable:this type_body_length
312312
313313 /// Creates a new branch in the specified directory.
314314 ///
315+ /// This function creates a new branch in the specified Git repository directory. It allows
316+ /// for an optional starting point for the new branch and an option to prevent tracking the
317+ /// new branch.
318+ ///
315319 /// - Parameters:
316320 /// - directoryURL: The URL of the directory where the Git repository is located.
317321 /// - name: A string representing the name of the new branch.
318322 /// - startPoint: An optional string representing the starting point for the new branch.
319323 /// - noTrack: A boolean indicating whether to track the branch. Defaults to false.
320324 /// - Throws: An error if the shell command fails.
325+ ///
326+ /// - Example:
327+ /// ```swift
328+ /// do {
329+ /// let directoryURL = URL(fileURLWithPath: "/path/to/repository")
330+ /// let branchName = "new-feature-branch"
331+ /// let startPoint = "main"
332+ /// let noTrack = true
333+ /// try createBranch(directoryURL: directoryURL, name: branchName, startPoint: startPoint, noTrack: noTrack)
334+ /// print("Branch created successfully.")
335+ /// } catch {
336+ /// print("Failed to create branch: \(error)")
337+ /// }
338+ /// ```
339+ ///
340+ /// - Note:
341+ /// If `noTrack` is set to `true`, the new branch will not track the remote branch from
342+ /// which it was created. This can be useful when branching directly from a remote branch
343+ /// to avoid automatically pushing to the remote branch's upstream.
321344 public func createBranch( directoryURL: URL ,
322345 name: String ,
323346 startPoint: String ? ,
@@ -382,23 +405,48 @@ public struct Branch { // swiftlint:disable:this type_body_length
382405 /// Prepare and execute the Git command to delete the local branch using a ShellClient.
383406 try GitShell ( ) . git ( args: args,
384407 path: directoryURL,
385- name: " deleteLocalBranch " )
408+ name: #function )
386409
387410 // Return true to indicate that the branch deletion was attempted.
388411 return true
389412 }
390413
391414 /// Deletes a remote branch in the specified directory.
392415 ///
416+ /// This function deletes a remote branch in the specified Git repository directory. It uses the `git push`
417+ /// command with a colon (`:`) in front of the branch name to delete the branch on the remote repository.
418+ ///
419+ /// If the deletion fails due to an authentication error or if the branch has already been deleted on the
420+ /// remote, the function attempts to delete the local reference to the remote branch.
421+ ///
393422 /// - Parameters:
394423 /// - directoryURL: The URL of the directory where the Git repository is located.
395424 /// - remoteName: A string representing the name of the remote repository.
396425 /// - remoteBranchName: A string representing the name of the branch to delete.
397426 /// - Throws: An error if the shell command fails.
427+ ///
428+ /// - Example:
429+ /// ```swift
430+ /// do {
431+ /// let directoryURL = URL(fileURLWithPath: "/path/to/repository")
432+ /// let remoteName = "origin"
433+ /// let remoteBranchName = "feature-branch"
434+ /// try deleteRemoteBranch(directoryURL: directoryURL, remoteName: remoteName, remoteBranchName: remoteBranchName)
435+ /// print("Remote branch deleted successfully.")
436+ /// } catch {
437+ /// print("Failed to delete remote branch: \(error)")
438+ /// }
439+ /// ```
440+ ///
441+ /// - Note:
442+ /// Ensure that you have the necessary permissions to delete branches on the remote repository. If the
443+ /// user is not authenticated or lacks the required permissions, the push operation will fail, and the
444+ /// caller must handle this error appropriately.
398445 public func deleteRemoteBranch( directoryURL: URL ,
399446 remoteName: String ,
400- remoteBranchName: String ) throws {
447+ remoteBranchName: String ) throws -> Bool {
401448 let args = [
449+ gitNetworkArguments. joined ( ) ,
402450 " push " ,
403451 remoteName,
404452 " : \( remoteBranchName) "
@@ -408,7 +456,7 @@ public struct Branch { // swiftlint:disable:this type_body_length
408456 // Let this propagate and leave it to the caller to handle
409457 let result = try GitShell ( ) . git ( args: args,
410458 path: directoryURL,
411- name: " deleteRemoteBranch " ,
459+ name: #function ,
412460 options: IGitExecutionOptions (
413461 expectedErrors: Set ( [ GitError . BranchDeletionFailed] )
414462 ) )
@@ -421,6 +469,8 @@ public struct Branch { // swiftlint:disable:this type_body_length
421469 let ref = " refs/remotes/ \( remoteName) / \( remoteBranchName) "
422470 try UpdateRef ( ) . deleteRef ( directoryURL: directoryURL, ref: ref, reason: nil )
423471 }
472+
473+ return true
424474 }
425475
426476 /// Finds all branches that point at a specific commitish in the given directory.
0 commit comments