# [PATCH] gitk: properly deal with tag names containing / (slash)

5 messages from 2008-02-06 to 2008-02-12. Participants: Gerrit Pape, Junio C Hamano, Paul Mackerras.
Thread: https://gitlist.dev/t/11910

## Gerrit Pape, 2008-02-06 07:06

Subject: [PATCH] gitk: properly deal with tag names containing / (slash)
Message-ID: <20080206070608.6881.qmail@096465580ae94c.315fe32.mid.smarden.org>
URL: https://gitlist.dev/e/20080206070608.6881.qmail%40096465580ae94c.315fe32.mid.smarden.org

```
When creating a tag through gitk, and the tag name includes a slash (or
slashes), gitk errors out in a popup window.  This patch makes gitk create
the necessary subdirectory(s) to successfully create the tag, and also
catches an error if a directory with the tag name to be created already
exists.

The problem was reported by Fr�d�ric Bri�re through
 http://bugs.debian.org/464104

Signed-off-by: Gerrit Pape <pape@smarden.org>
---
 gitk-git/gitk |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/gitk-git/gitk b/gitk-git/gitk
index 5560e4d..56a8792 100644
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -6136,9 +6136,16 @@ proc domktag {} {
 	error_popup [mc "Tag \"%s\" already exists" $tag]
 	return
     }
+    set dir [gitdir]
+    set fname [file join $dir "refs/tags" $tag]
+    if {[file isdirectory $fname]} {
+	error_popup [mc "A directory with the name \"%s\" exists in \"refs/tags\"" $tag]
+	return
+    }
     if {[catch {
-	set dir [gitdir]
-	set fname [file join $dir "refs/tags" $tag]
+	if {[file dirname $tag] != "."} {
+	    file mkdir [file dirname $fname]
+	}
 	set f [open $fname w]
 	puts $f $id
 	close $f
-- 
1.5.4

```

## Junio C Hamano, 2008-02-06 07:34

Subject: Re: [PATCH] gitk: properly deal with tag names containing / (slash)
Message-ID: <7vtzkm35d1.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vtzkm35d1.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <20080206070608.6881.qmail@096465580ae94c.315fe32.mid.smarden.org>

```
Gerrit Pape <pape@smarden.org> writes:

> When creating a tag through gitk, and the tag name includes a slash (or
> slashes), gitk errors out in a popup window.  This patch makes gitk create
> the necessary subdirectory(s) to successfully create the tag, and also
> catches an error if a directory with the tag name to be created already
> exists.
> ...
> diff --git a/gitk-git/gitk b/gitk-git/gitk
> index 5560e4d..56a8792 100644
> --- a/gitk-git/gitk
> +++ b/gitk-git/gitk
> @@ -6136,9 +6136,16 @@ proc domktag {} {
>  	error_popup [mc "Tag \"%s\" already exists" $tag]
>  	return
>      }
> +    set dir [gitdir]
> +    set fname [file join $dir "refs/tags" $tag]
> +    if {[file isdirectory $fname]} {
> +	error_popup [mc "A directory with the name \"%s\" exists in \"refs/tags\"" $tag]
> +	return
> +    }
>      if {[catch {
> -	set dir [gitdir]
> -	set fname [file join $dir "refs/tags" $tag]
> +	if {[file dirname $tag] != "."} {
> +	    file mkdir [file dirname $fname]
> +	}

That's wrong.  If your refs are packed and you have an existing
tag 'foo', you should error out on a request to create 'foo/bar'
(and vice versa --- existing foo/bar should prevent foo from
being created).

You should be calling out "git tag" instead of futzing with
files under gitdir by hand.

```

## Gerrit Pape, 2008-02-07 09:34

Subject: [PATCH] gitk: properly deal with tag names containing / (slash)
Message-ID: <20080207093415.13241.qmail@945a2ee23beef0.315fe32.mid.smarden.org>
URL: https://gitlist.dev/e/20080207093415.13241.qmail%40945a2ee23beef0.315fe32.mid.smarden.org
In-Reply-To: <7vtzkm35d1.fsf@gitster.siamese.dyndns.org>

```
When creating a tag through gitk, and the tag name includes a slash (or
slashes), gitk errors out in a popup window.  This patch makes gitk use
'git tag' to create the tag instead of modifying files in refs/tags/,
which fixes the issue; if 'git tag' throws an error, gitk pops up with
the error message.

The problem was reported by Fr�d�ric Bri�re through
 http://bugs.debian.org/464104

Signed-off-by: Gerrit Pape <pape@smarden.org>
---

On Tue, Feb 05, 2008 at 11:34:50PM -0800, Junio C Hamano wrote:
> That's wrong.  If your refs are packed and you have an existing
> tag 'foo', you should error out on a request to create 'foo/bar'
> (and vice versa --- existing foo/bar should prevent foo from
> being created).
>
> You should be calling out "git tag" instead of futzing with
> files under gitdir by hand.
Done so.

 gitk-git/gitk |    6 +-----
 1 files changed, 1 insertions(+), 5 deletions(-)

diff --git a/gitk-git/gitk b/gitk-git/gitk
index 5560e4d..00d791f 100644
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -6137,11 +6137,7 @@ proc domktag {} {
 	return
     }
     if {[catch {
-	set dir [gitdir]
-	set fname [file join $dir "refs/tags" $tag]
-	set f [open $fname w]
-	puts $f $id
-	close $f
+	exec git tag $tag $id
     } err]} {
 	error_popup "[mc "Error creating tag:"] $err"
 	return
-- 
1.5.4

```

## Gerrit Pape, 2008-02-11 10:57

Subject: [PATCH/UTF-8] gitk: properly deal with tag names containing / (slash)
Message-ID: <20080211105741.16353.qmail@d33cfe7d8389ec.315fe32.mid.smarden.org>
URL: https://gitlist.dev/e/20080211105741.16353.qmail%40d33cfe7d8389ec.315fe32.mid.smarden.org
In-Reply-To: <20080207093415.13241.qmail@945a2ee23beef0.315fe32.mid.smarden.org>

```
When creating a tag through gitk, and the tag name includes a slash (or
slashes), gitk errors out in a popup window.  This patch makes gitk use
'git tag' to create the tag instead of modifying files in refs/tags/,
which fixes the issue; if 'git tag' throws an error, gitk pops up with
the error message.

The problem was reported by Fr�d�ric Bri�re through
 http://bugs.debian.org/464104

Signed-off-by: Gerrit Pape <pape@smarden.org>
---
 gitk-git/gitk |    6 +-----
 1 files changed, 1 insertions(+), 5 deletions(-)

diff --git a/gitk-git/gitk b/gitk-git/gitk
index 5560e4d..00d791f 100644
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -6137,11 +6137,7 @@ proc domktag {} {
 	return
     }
     if {[catch {
-	set dir [gitdir]
-	set fname [file join $dir "refs/tags" $tag]
-	set f [open $fname w]
-	puts $f $id
-	close $f
+	exec git tag $tag $id
     } err]} {
 	error_popup "[mc "Error creating tag:"] $err"
 	return
-- 
1.5.4

```

## Paul Mackerras, 2008-02-12 02:21

Subject: Re: [PATCH/UTF-8] gitk: properly deal with tag names containing / (slash)
Message-ID: <18353.664.502848.772753@cargo.ozlabs.ibm.com>
URL: https://gitlist.dev/e/18353.664.502848.772753%40cargo.ozlabs.ibm.com
In-Reply-To: <20080211105741.16353.qmail@d33cfe7d8389ec.315fe32.mid.smarden.org>

```
Gerrit Pape writes:

> When creating a tag through gitk, and the tag name includes a slash (or
> slashes), gitk errors out in a popup window.  This patch makes gitk use
> 'git tag' to create the tag instead of modifying files in refs/tags/,
> which fixes the issue; if 'git tag' throws an error, gitk pops up with
> the error message.

Thanks, applied.

Paul.

```
