git: allow pushing without updating the repository announcement.

This commit is contained in:
fiatjaf
2026-07-17 22:51:21 -03:00
parent 5b7f3eb4db
commit 57be7627d4

29
git.go
View File

@@ -317,7 +317,7 @@ aside from those, there is also:
Usage: "sync repository with relays",
Action: func(ctx context.Context, c *cli.Command) error {
kr, _, _ := gatherKeyerFromArguments(ctx, c)
_, _, err := gitSync(ctx, kr)
_, _, err := gitSync(ctx, kr, false)
return err
},
},
@@ -621,6 +621,10 @@ aside from those, there is also:
Name: "tags",
Usage: "push all refs under refs/tags",
},
&cli.BoolFlag{
Name: "no-announcement",
Usage: "skip publishing updated repository announcement event",
},
},
Action: func(ctx context.Context, c *cli.Command) error {
// setup signer
@@ -635,7 +639,7 @@ aside from those, there is also:
log("publishing as %s\n", color.CyanString(currentNpub))
// sync to ensure everything is up to date
repo, state, err := gitSync(ctx, kr)
repo, state, err := gitSync(ctx, kr, c.Bool("no-announcement"))
if err != nil {
return fmt.Errorf("failed to sync: %w", err)
}
@@ -795,7 +799,7 @@ aside from those, there is also:
},
Action: func(ctx context.Context, c *cli.Command) error {
// sync to fetch latest state and metadata
_, state, err := gitSync(ctx, nil)
_, state, err := gitSync(ctx, nil, false)
if err != nil {
return fmt.Errorf("failed to sync: %w", err)
}
@@ -930,7 +934,7 @@ aside from those, there is also:
Name: "fetch",
Usage: "fetch git data",
Action: func(ctx context.Context, c *cli.Command) error {
_, _, err := gitSync(ctx, nil)
_, _, err := gitSync(ctx, nil, false)
return err
},
},
@@ -1451,7 +1455,7 @@ aside from those, there is also:
}
// sync to set up remotes and fetch the latest metadata/state
repo, state, err := gitSync(ctx, kr)
repo, state, err := gitSync(ctx, kr, false)
if err != nil {
return fmt.Errorf("failed to sync: %w", err)
}
@@ -1557,7 +1561,7 @@ please merge
return fmt.Errorf("failed to gather keyer: %w", err)
}
repo, state, err := gitSync(ctx, kr)
repo, state, err := gitSync(ctx, kr, false)
if err != nil {
return fmt.Errorf("failed to sync: %w", err)
}
@@ -2824,7 +2828,7 @@ func colorizeGitStatus(status string) string {
}
}
func gitSync(ctx context.Context, signer nostr.Keyer) (nip34.Repository, *nip34.RepositoryState, error) {
func gitSync(ctx context.Context, signer nostr.Keyer, skipAnnouncement bool) (nip34.Repository, *nip34.RepositoryState, error) {
// read current nip34.json
localConfig, err := readNip34ConfigFile("")
if err != nil {
@@ -2839,6 +2843,7 @@ func gitSync(ctx context.Context, signer nostr.Keyer) (nip34.Repository, *nip34.
// fetch repository announcement and state from relays
repo, upToDateAnnouncementEvent, upToDateRelays, state, err := fetchRepositoryAndState(ctx, owner, localConfig.Identifier, localConfig.GraspServers)
if !skipAnnouncement {
notUpToDate := func(graspServer string) bool {
return !slices.Contains(upToDateRelays, nostr.NormalizeURL(graspServer))
}
@@ -2958,6 +2963,16 @@ func gitSync(ctx context.Context, signer nostr.Keyer) (nip34.Repository, *nip34.
}
}
}
} else {
if err != nil {
if _, ok := err.(StateErr); ok {
// some error with the state, just do nothing and proceed
} else {
// actually fail with this error we don't know about
return repo, nil, err
}
}
}
// setup remotes
gitSetupRemotes(ctx, "", repo)