diff mbox

[5/6] dim: Add helper for checking for a branch

Message ID 20170126091049.9122-5-daniel.vetter@ffwll.ch (mailing list archive)
State New, archived
Headers show

Commit Message

Daniel Vetter Jan. 26, 2017, 9:10 a.m. UTC
And roll it out.

Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
---
 dim | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

Comments

Jani Nikula Jan. 26, 2017, 10:46 a.m. UTC | #1
On Thu, 26 Jan 2017, Daniel Vetter <daniel.vetter@ffwll.ch> wrote:
> And roll it out.
>
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>

Could probably look at the quoting a bit, but this is an
improvement. LGTM.

I've done some shellcheck(1) fixes in a dull moment in the past, I
should revive the series and post.

BR,
Jani.

> ---
>  dim | 17 +++++++++++++----
>  1 file changed, 13 insertions(+), 4 deletions(-)
>
> diff --git a/dim b/dim
> index 73fb32c4d5ab..c5c46e9c767a 100755
> --- a/dim
> +++ b/dim
> @@ -307,6 +307,15 @@ function git_is_current_branch # branch
>  	git branch --list $1 | grep -q '\*'
>  }
>  
> +function git_branch_exists # branch
> +{
> +	if [[ `git branch --list $1` == "" ]] ; then
> +		false
> +	else
> +		true
> +	fi
> +}
> +
>  if [[ "$((`date +%s` % 100))" -eq "0" ]] ; then
>          dim_uptodate
>  fi
> @@ -825,7 +834,7 @@ function dim_remove_branch
>  		git worktree prune &> /dev/null || true
>  	fi
>  
> -	if [[ `git branch --list $branch`  != "" ]] &&
> +	if git_branch_exists $branch &&
>  	   ! $DRY git branch -d $branch  ; then
>  			warn_or_fail "Can't remove $branch in working repo"
>  	fi
> @@ -876,7 +885,7 @@ function dim_checkout
>  	branch=$1
>  
>  	dim_cd $branch
> -	if [[ `git branch --list $branch` ==  "" ]] ; then
> +	if ! git_branch_exists $branch ; then
>  		repo=`branch_to_repo $branch`
>  
>  		if [[ $branch == "drm-intel-next" ]] ; then
> @@ -1359,7 +1368,7 @@ function setup_aux_checkout # name url directory
>  		if git help worktree &> /dev/null ; then
>  			cd $DIM_PREFIX/$DIM_DRM_INTEL
>  			remote=`url_to_remote $url`
> -			if [[ `git branch --list $name` == "" ]] ; then
> +			if ! git_branch_exists $name ; then
>  				git_fetch_helper $remote
>  				git branch --track $name $remote/$name
>  			fi
> @@ -1376,7 +1385,7 @@ function setup_aux_checkout # name url directory
>  		cd $dir
>  		remote=`url_to_remote $url`
>  	fi
> -	if [[ `git branch --list $name` == "" ]] ; then
> +	if ! git_branch_exists $name ; then
>  		git checkout -t $remote/$name
>  	fi
>  	cd - > /dev/null
diff mbox

Patch

diff --git a/dim b/dim
index 73fb32c4d5ab..c5c46e9c767a 100755
--- a/dim
+++ b/dim
@@ -307,6 +307,15 @@  function git_is_current_branch # branch
 	git branch --list $1 | grep -q '\*'
 }
 
+function git_branch_exists # branch
+{
+	if [[ `git branch --list $1` == "" ]] ; then
+		false
+	else
+		true
+	fi
+}
+
 if [[ "$((`date +%s` % 100))" -eq "0" ]] ; then
         dim_uptodate
 fi
@@ -825,7 +834,7 @@  function dim_remove_branch
 		git worktree prune &> /dev/null || true
 	fi
 
-	if [[ `git branch --list $branch`  != "" ]] &&
+	if git_branch_exists $branch &&
 	   ! $DRY git branch -d $branch  ; then
 			warn_or_fail "Can't remove $branch in working repo"
 	fi
@@ -876,7 +885,7 @@  function dim_checkout
 	branch=$1
 
 	dim_cd $branch
-	if [[ `git branch --list $branch` ==  "" ]] ; then
+	if ! git_branch_exists $branch ; then
 		repo=`branch_to_repo $branch`
 
 		if [[ $branch == "drm-intel-next" ]] ; then
@@ -1359,7 +1368,7 @@  function setup_aux_checkout # name url directory
 		if git help worktree &> /dev/null ; then
 			cd $DIM_PREFIX/$DIM_DRM_INTEL
 			remote=`url_to_remote $url`
-			if [[ `git branch --list $name` == "" ]] ; then
+			if ! git_branch_exists $name ; then
 				git_fetch_helper $remote
 				git branch --track $name $remote/$name
 			fi
@@ -1376,7 +1385,7 @@  function setup_aux_checkout # name url directory
 		cd $dir
 		remote=`url_to_remote $url`
 	fi
-	if [[ `git branch --list $name` == "" ]] ; then
+	if ! git_branch_exists $name ; then
 		git checkout -t $remote/$name
 	fi
 	cd - > /dev/null