@@ -106,7 +106,6 @@ const (
106
106
107
107
const defaultDirMode = os .FileMode (0775 ) // subject to umask
108
108
109
- // FIXME: should this carry SSH keys? if so, sub-structs?
110
109
type credential struct {
111
110
URL string `json:"url"`
112
111
Username string `json:"username"`
@@ -832,21 +831,27 @@ func main() {
832
831
}
833
832
}
834
833
835
- if * flPassword != "" && * flPasswordFile != "" {
836
- handleConfigError (log , true , "ERROR: only one of --password and --password-file may be specified" )
837
- }
838
834
if * flUsername != "" {
839
835
if * flPassword == "" && * flPasswordFile == "" {
840
- handleConfigError (log , true , "ERROR: --password or --password-file must be set when --username is specified" )
836
+ handleConfigError (log , true , "ERROR: --password or --password-file must be specified when --username is specified" )
837
+ }
838
+ if * flPassword != "" && * flPasswordFile != "" {
839
+ handleConfigError (log , true , "ERROR: only one of --password and --password-file may be specified" )
840
+ }
841
+ } else {
842
+ if * flPassword != "" {
843
+ handleConfigError (log , true , "ERROR: --password may only be specified when --username is specified" )
844
+ }
845
+ if * flPasswordFile != "" {
846
+ handleConfigError (log , true , "ERROR: --password-file may only be specified when --username is specified" )
841
847
}
842
848
}
843
849
//FIXME: mutex wih flCredentials?
844
850
845
- credentials := []credential {}
846
851
if len (* flCredentials ) > 0 {
847
852
for _ , cred := range * flCredentials {
848
853
if cred .URL == "" {
849
- //FIXME: can it default to --repo?
854
+ //FIXME: can it default to --repo? Then --username can be deprecated
850
855
handleConfigError (log , true , "ERROR: --credential URL must be specified" )
851
856
}
852
857
if cred .Username == "" {
@@ -858,11 +863,10 @@ func main() {
858
863
if cred .Password != "" && cred .PasswordFile != "" {
859
864
handleConfigError (log , true , "ERROR: only one of --credential password and password-file may be specified" )
860
865
}
861
- //FIXME: askpass for this purpose, too?
862
- credentials = append (credentials , cred )
863
866
}
864
867
}
865
868
869
+ //FIXME: do I need --ssh at all? With submodules, all sorts of variations can be in flight
866
870
if * flSSH {
867
871
if * flUsername != "" {
868
872
handleConfigError (log , true , "ERROR: only one of --ssh and --username may be specified" )
@@ -873,7 +877,7 @@ func main() {
873
877
if * flPasswordFile != "" {
874
878
handleConfigError (log , true , "ERROR: only one of --ssh and --password-file may be specified" )
875
879
}
876
- //FIXME: mutex wih flCredentials ?
880
+ //FIXME: can I use askpass and --credential together ?
877
881
if * flAskPassURL != "" {
878
882
handleConfigError (log , true , "ERROR: only one of --ssh and --askpass-url may be specified" )
879
883
}
@@ -946,6 +950,17 @@ func main() {
946
950
absLink := makeAbsPath (* flLink , absRoot )
947
951
absTouchFile := makeAbsPath (* flTouchFile , absRoot )
948
952
953
+ // Merge credential sources.
954
+ if * flUsername != "" {
955
+ cred := credential {
956
+ URL : * flRepo ,
957
+ Username : * flUsername ,
958
+ Password : * flPassword ,
959
+ PasswordFile : * flPasswordFile ,
960
+ }
961
+ * flCredentials = append ([]credential {cred }, (* flCredentials )... )
962
+ }
963
+
949
964
if * flAddUser {
950
965
if err := addUser (); err != nil {
951
966
log .Error (err , "ERROR: can't add user" )
@@ -992,19 +1007,9 @@ func main() {
992
1007
os .Exit (1 )
993
1008
}
994
1009
995
- // FIXME: merge into flCredentials
996
- if * flUsername != "" {
997
- if * flPasswordFile != "" {
998
- passwordFileBytes , err := os .ReadFile (* flPasswordFile )
999
- if err != nil {
1000
- log .Error (err , "can't read password file" , "file" , * flPasswordFile )
1001
- os .Exit (1 )
1002
- }
1003
- * flPassword = string (passwordFileBytes )
1004
- }
1005
- }
1006
- //FIXME: merge
1007
- for _ , cred := range credentials {
1010
+ // Finish populating credentials.
1011
+ for i := range * flCredentials {
1012
+ cred := & (* flCredentials )[i ]
1008
1013
if cred .PasswordFile != "" {
1009
1014
passwordFileBytes , err := os .ReadFile (cred .PasswordFile )
1010
1015
if err != nil {
@@ -1135,14 +1140,8 @@ func main() {
1135
1140
1136
1141
// Craft a function that can be called to refresh credentials when needed.
1137
1142
refreshCreds := func (ctx context.Context ) error {
1138
- //FIXME: still mutually exclusive?
1139
1143
// These should all be mutually-exclusive configs.
1140
- if * flUsername != "" {
1141
- if err := git .StoreCredentials (ctx , git .repo , * flUsername , * flPassword ); err != nil {
1142
- return err
1143
- }
1144
- }
1145
- for _ , cred := range credentials {
1144
+ for _ , cred := range * flCredentials {
1146
1145
if err := git .StoreCredentials (ctx , cred .URL , cred .Username , cred .Password ); err != nil {
1147
1146
return err
1148
1147
}
0 commit comments