mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 12:18:26 +00:00 
			
		
		
		
	use quoted regexp instead of git fixed-value (#20029)
This commit is contained in:
		| @@ -11,6 +11,7 @@ import ( | |||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"os" | 	"os" | ||||||
| 	"os/exec" | 	"os/exec" | ||||||
|  | 	"regexp" | ||||||
| 	"runtime" | 	"runtime" | ||||||
| 	"strings" | 	"strings" | ||||||
| 	"sync" | 	"sync" | ||||||
| @@ -337,7 +338,7 @@ func configSetNonExist(key, value string) error { | |||||||
| } | } | ||||||
|  |  | ||||||
| func configAddNonExist(key, value string) error { | func configAddNonExist(key, value string) error { | ||||||
| 	_, _, err := NewCommand(DefaultContext, "config", "--fixed-value", "--get", key, value).RunStdString(nil) | 	_, _, err := NewCommand(DefaultContext, "config", "--get", key, regexp.QuoteMeta(value)).RunStdString(nil) | ||||||
| 	if err == nil { | 	if err == nil { | ||||||
| 		// already exist | 		// already exist | ||||||
| 		return nil | 		return nil | ||||||
| @@ -357,7 +358,7 @@ func configUnsetAll(key, value string) error { | |||||||
| 	_, _, err := NewCommand(DefaultContext, "config", "--get", key).RunStdString(nil) | 	_, _, err := NewCommand(DefaultContext, "config", "--get", key).RunStdString(nil) | ||||||
| 	if err == nil { | 	if err == nil { | ||||||
| 		// exist, need to remove | 		// exist, need to remove | ||||||
| 		_, _, err = NewCommand(DefaultContext, "config", "--global", "--fixed-value", "--unset-all", key, value).RunStdString(nil) | 		_, _, err = NewCommand(DefaultContext, "config", "--global", "--unset-all", key, regexp.QuoteMeta(value)).RunStdString(nil) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return fmt.Errorf("failed to unset git global config %s, err: %w", key, err) | 			return fmt.Errorf("failed to unset git global config %s, err: %w", key, err) | ||||||
| 		} | 		} | ||||||
|   | |||||||
| @@ -78,4 +78,10 @@ func TestGitConfig(t *testing.T) { | |||||||
|  |  | ||||||
| 	assert.NoError(t, configUnsetAll("test.key-b", "val-2b")) | 	assert.NoError(t, configUnsetAll("test.key-b", "val-2b")) | ||||||
| 	assert.False(t, gitConfigContains("key-b = val-2b")) | 	assert.False(t, gitConfigContains("key-b = val-2b")) | ||||||
|  |  | ||||||
|  | 	assert.NoError(t, configSet("test.key-x", "*")) | ||||||
|  | 	assert.True(t, gitConfigContains("key-x = *")) | ||||||
|  | 	assert.NoError(t, configSetNonExist("test.key-x", "*")) | ||||||
|  | 	assert.NoError(t, configUnsetAll("test.key-x", "*")) | ||||||
|  | 	assert.False(t, gitConfigContains("key-x = *")) | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user