commit b21ebdb07f917bc6e7026654dfbcddc6d3162383 from: Stefan Sperling via: Thomas Adam date: Thu Jun 22 13:10:34 2023 UTC make 'got add' more forgiving about unversioned paths on the command line When users run 'got add *' the shell may pick up already versioned files and trigger errors about paths being in an unexpected status. Expand the check which previously only allowed files in added status to be double-added to cover the following status codes which are all safe to ignore: A M C m This should make bulk additions of files a bit easier in most cases. Problem reported by robert@ ok jamsek commit - e0d77865e2e51f2e3d61d5c36458739101d65005 commit + b21ebdb07f917bc6e7026654dfbcddc6d3162383 blob - ee5ecec15b1c9954ab672ace7b9165717723b7d2 blob + 8122fe9273cc37091dc13c83016ef03a2a436be5 --- got/got.1 +++ got/got.1 @@ -1412,6 +1412,25 @@ By default, files which match a .Cm got status ignore pattern will not be added. .Pp +If a +.Ar path +mentioned in the command line is not an unversioned file then +.Cm got add +may raise an error. +To avoid unnecessary errors from paths picked up by file globbing patterns +in the shell, paths in the argument list will be silently ignored if they +are not reported by +.Cm got status +at all, or if they are reported with one of the following status codes +and do not have changes staged via +.Cm got stage : +.Bl -column YXZ description +.It M Ta modified file +.It A Ta file scheduled for addition in next commit +.It C Ta modified or added file which contains merge conflicts +.It m Ta modified file modes (executable bit only) +.El +.Pp The options for .Cm got add are as follows: blob - e4ced5bd20cd7472a7ab42e03feafc80ec8dd6ac blob + 8ef0f4b40ba4b3c694de8a7b76cbbfb7abdf572e --- lib/worktree.c +++ lib/worktree.c @@ -4194,6 +4194,16 @@ struct schedule_addition_args { struct got_repository *repo; }; +static int +add_noop_status(unsigned char status) +{ + return (status == GOT_STATUS_ADD || + status == GOT_STATUS_MODIFY || + status == GOT_STATUS_CONFLICT || + status == GOT_STATUS_MODE_CHANGE || + status == GOT_STATUS_NO_CHANGE); +} + static const struct got_error * schedule_addition(void *arg, unsigned char status, unsigned char staged_status, const char *relpath, struct got_object_id *blob_id, @@ -4217,7 +4227,8 @@ schedule_addition(void *arg, unsigned char status, uns if (err) goto done; /* Re-adding an existing entry is a no-op. */ - if (status == GOT_STATUS_ADD) + if (staged_status == GOT_STATUS_NO_CHANGE && + add_noop_status(status)) goto done; err = got_error_path(relpath, GOT_ERR_FILE_STATUS); if (err) @@ -4250,7 +4261,7 @@ done: free(ondisk_path); if (err) return err; - if (status == GOT_STATUS_ADD) + if (staged_status == GOT_STATUS_NO_CHANGE && add_noop_status(status)) return NULL; return (*a->progress_cb)(a->progress_arg, GOT_STATUS_ADD, relpath); } blob - eabde9c24df6b9d72582040315ce0f913a98716c blob + 230e87510d8cfc3bfd45d3bbfc058b91d0a05e6e --- regress/cmdline/add.sh +++ regress/cmdline/add.sh @@ -120,6 +120,7 @@ test_add_multiple() { return 1 fi + echo "changed file" > $testroot/wt/alpha echo "new file" > $testroot/wt/bax (cd $testroot/wt && got add -R * > $testroot/stdout) ret=$?